1

I need to embed codelabs into an existing web site. So, I need to change the actual HTML output (I need to get rid of etc.) In claat's own help I see:

Note that the built-in templates of the formats are not guaranteed to be stable.
They can be found in https://github.com/googlecodelabs/tools/tree/master/claat/render.
Please avoid using default templates in production. Use your own copies.

To use a custom format, specify a local file path to a Go template file.
More info on Go templates: https://golang.org/pkg/text/template/.

Except that:

  • The link provided is very API-ish
  • The only command line option that mentiones templates is this:
  -extra string
        Additional arguments to pass to format templates. JSON object of string,string key values.

What do I actually need to do to pass claat a different template?

Merc
  • 16,277
  • 18
  • 79
  • 122

1 Answers1

1

As the help message implies, use the format option. html or md are merely shortcuts to use the built-in templates.

claat export -f [template filepath] [source filepath] 

Also was trying to solve this a year after it was first asked. It doesn't say explicitly, but digging into the source we can find where the format option is parsed.

https://github.com/googlecodelabs/tools/blob/main/claat/render/template.go#L166

Following that, we can specify our own html or text template file (relative or absolute path) with the -f option, instead of the default html or md format option (loading built-in templates).

These templates are parsed according to:
https://pkg.go.dev/html/template
https://pkg.go.dev/text/template
as the help message indicates.

  • Thanks, this was super helpful! as I could just grab a copy of the existing builtin template file and then just customise to my needs. – Maks Jun 16 '23 at 02:02