Documentation
¶
Overview ¶
Package printer renders a (normalized) gsx AST back to canonical gsx source.
Fprint assumes the AST has already been whitespace-normalized (via internal/wsnorm); gsx fmt does that first. The printer builds a width-aware pretty.Doc describing the layout, then renders it: cosmetic newlines and tab indentation are added only at whitespace-safe boundaries (which wsnorm drops on a re-parse), so the output is render-faithful and idempotent.
It depends on github.com/gsxhq/gsx/ast, internal/pretty, plus go/format, go/parser, go/token and the standard library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
Fprint writes the canonical gsx rendering of f to w, wrapping lists that exceed width columns. width <= 0 uses pretty.DefaultPrintWidth; tabWidth <= 0 uses pretty.DefaultTabWidth.
func FprintWith ¶
func FprintWith(w io.Writer, f *ast.File, width, tabWidth int, cssFmt, jsFmt rawfmt.Formatter) error
FprintWith is Fprint with explicit external CSS and JS formatters for <style>/<script> bodies. A nil formatter leaves that body verbatim. External flat formatters carry no token structure, so a multi-line-token interior in their output is re-indented (the same limitation as before line formatters).
func StripSyntheticPackage ¶
StripSyntheticPackage removes the synthetic package clause from formatted — the output of a Go formatter that was fed a synthetic clause + a GoChunk's text. It locates the clause by PARSING, never by assuming it is the first line: go/printer relocates build-constraint comments (//go:build) above the package clause, so a line- or byte-index strip would shear the constraint and leave the synthetic `package` declaration spliced into the user's source.
The single blank line the formatter always places between the package clause and the following declaration is removed too — it is separation we introduced by adding the clause, not layout the author wrote.
ok is false when formatted does not parse; the caller then leaves the text untouched.
Types ¶
This section is empty.