Documentation ¶
Overview ¶
Package render contains conversions from a processed Booklit section into a rendered format such as plaintext or HTML, either for serving in a browser or for writing to files on disk.
Index ¶
- Variables
- type Engine
- type HTMLEngine
- func (engine *HTMLEngine) FileExtension() string
- func (engine *HTMLEngine) LoadTemplates(templatesDir string) error
- func (engine *HTMLEngine) RenderSection(out io.Writer, con *booklit.Section) error
- func (engine *HTMLEngine) URL(tag booklit.Tag) string
- func (engine *HTMLEngine) VisitDefinitions(con booklit.Definitions) error
- func (engine *HTMLEngine) VisitImage(con booklit.Image) error
- func (engine *HTMLEngine) VisitLink(con booklit.Link) error
- func (engine *HTMLEngine) VisitList(con booklit.List) error
- func (engine *HTMLEngine) VisitParagraph(con booklit.Paragraph) error
- func (engine *HTMLEngine) VisitPreformatted(con booklit.Preformatted) error
- func (engine *HTMLEngine) VisitReference(con *booklit.Reference) error
- func (engine *HTMLEngine) VisitSection(con *booklit.Section) error
- func (engine *HTMLEngine) VisitSequence(con booklit.Sequence) error
- func (engine *HTMLEngine) VisitString(con booklit.String) error
- func (engine *HTMLEngine) VisitStyled(con booklit.Styled) error
- func (engine *HTMLEngine) VisitTable(con booklit.Table) error
- func (engine *HTMLEngine) VisitTableOfContents(con booklit.TableOfContents) error
- func (engine *HTMLEngine) VisitTarget(con booklit.Target) error
- type SearchDocument
- type SearchIndex
- type TextEngine
- func (engine *TextEngine) FileExtension() string
- func (engine *TextEngine) LoadTemplates(templatesDir string) error
- func (engine *TextEngine) RenderSection(out io.Writer, con *booklit.Section) error
- func (engine *TextEngine) URL(tag booklit.Tag) string
- func (engine *TextEngine) VisitDefinitions(con booklit.Definitions) error
- func (engine *TextEngine) VisitImage(con booklit.Image) error
- func (engine *TextEngine) VisitLink(con booklit.Link) error
- func (engine *TextEngine) VisitList(con booklit.List) error
- func (engine *TextEngine) VisitParagraph(con booklit.Paragraph) error
- func (engine *TextEngine) VisitPreformatted(con booklit.Preformatted) error
- func (engine *TextEngine) VisitReference(con *booklit.Reference) error
- func (engine *TextEngine) VisitSection(con *booklit.Section) error
- func (engine *TextEngine) VisitSequence(con booklit.Sequence) error
- func (engine *TextEngine) VisitString(con booklit.String) error
- func (engine *TextEngine) VisitStyled(con booklit.Styled) error
- func (engine *TextEngine) VisitTable(con booklit.Table) error
- func (engine *TextEngine) VisitTableOfContents(con booklit.TableOfContents) error
- func (engine *TextEngine) VisitTarget(con booklit.Target) error
- type WalkContext
- type Writer
Constants ¶
This section is empty.
Variables ¶
var HTMLFuncs = template.FuncMap{ "render": func(booklit.Content) (template.HTML, error) { return "", errors.New("render stubbed out") }, "url": func(tag booklit.Tag) string { return sectionURL("html", tag.Section, tag.Anchor) }, "stripAux": booklit.StripAux, "rawHTML": func(con booklit.Content) template.HTML { return template.HTML(con.String()) }, "walkContext": func(current *booklit.Section, section *booklit.Section) WalkContext { return WalkContext{ Current: current, Section: section, } }, "headerDepth": func(con *booklit.Section) int { depth := con.PageDepth() + 1 if depth > 6 { depth = 6 } return depth }, }
HTMLFuncs is the set of functions available to all templates.
See https://booklit.page/html-renderer.html#template-functions for more information.
var TextFuncs = template.FuncMap{ "render": func(booklit.Content) (string, error) { return "", errors.New("render stubbed out") }, "url": func(ext string, tag booklit.Tag) (string, error) { return "", errors.New("url stubbed out") }, "htmlURL": func(tag booklit.Tag) string { return sectionURL("html", tag.Section, tag.Anchor) }, "stripAux": booklit.StripAux, "joinLines": func(prefix string, str string) string { return strings.Join(strings.Split(str, "\n"), "\n"+prefix) }, }
TextFuncs is the set of functions available to all templates.
Functions ¶
This section is empty.
Types ¶
type Engine ¶ added in v0.12.0
type Engine interface { // RenderSection writes the given section to the writer. RenderSection(io.Writer, *booklit.Section) error // The canonical file extension for files written by the engine, // without the leading dot. FileExtension() string // The URL to reference rendered content for a given tag. URL(booklit.Tag) string }
Engine is the primary type for rendering sections.
type HTMLEngine ¶ added in v0.12.0
type HTMLEngine struct {
// contains filtered or unexported fields
}
HTMLEngine renders sections as HTML using Go's html/template system.
func NewHTMLEngine ¶ added in v0.12.0
func NewHTMLEngine() *HTMLEngine
NewHTMLEngine constructs a new HTMLEngine with the basic set of HTML templates bundled with Booklit.
func (*HTMLEngine) FileExtension ¶ added in v0.12.0
func (engine *HTMLEngine) FileExtension() string
FileExtension returns "html".
func (*HTMLEngine) LoadTemplates ¶ added in v0.12.0
func (engine *HTMLEngine) LoadTemplates(templatesDir string) error
LoadTemplates loads all *.tmpl files in the specified directory.
func (*HTMLEngine) RenderSection ¶ added in v0.12.0
RenderSection renders the section to the writer using page.tmpl.
If the section has Style set and a template named (Style)-page.tmpl exists it will be used instead.
func (*HTMLEngine) URL ¶ added in v0.12.0
func (engine *HTMLEngine) URL(tag booklit.Tag) string
URL returns the HTML file name with an anchor if present.
func (*HTMLEngine) VisitDefinitions ¶ added in v0.12.0
func (engine *HTMLEngine) VisitDefinitions(con booklit.Definitions) error
VisitDefinitions renders con using definitions.tmpl.
func (*HTMLEngine) VisitImage ¶ added in v0.12.0
func (engine *HTMLEngine) VisitImage(con booklit.Image) error
VisitImage renders con using image.tmpl.
func (*HTMLEngine) VisitLink ¶ added in v0.12.0
func (engine *HTMLEngine) VisitLink(con booklit.Link) error
VisitLink renders con using link.tmpl.
func (*HTMLEngine) VisitList ¶ added in v0.12.0
func (engine *HTMLEngine) VisitList(con booklit.List) error
VisitList renders con using list.tmpl.
func (*HTMLEngine) VisitParagraph ¶ added in v0.12.0
func (engine *HTMLEngine) VisitParagraph(con booklit.Paragraph) error
VisitParagraph renders con using paragraph.tmpl.
func (*HTMLEngine) VisitPreformatted ¶ added in v0.12.0
func (engine *HTMLEngine) VisitPreformatted(con booklit.Preformatted) error
VisitPreformatted renders con using preformatted.tmpl.
func (*HTMLEngine) VisitReference ¶ added in v0.12.0
func (engine *HTMLEngine) VisitReference(con *booklit.Reference) error
VisitReference renders con using reference.tmpl.
func (*HTMLEngine) VisitSection ¶ added in v0.12.0
func (engine *HTMLEngine) VisitSection(con *booklit.Section) error
VisitSection renders con using section.tmpl.
If the section has Style set and a template named (Style).tmpl exists it will be used instead.
func (*HTMLEngine) VisitSequence ¶ added in v0.12.0
func (engine *HTMLEngine) VisitSequence(con booklit.Sequence) error
VisitSequence renders con using sequence.tmpl.
func (*HTMLEngine) VisitString ¶ added in v0.12.0
func (engine *HTMLEngine) VisitString(con booklit.String) error
VisitString renders con using string.tmpl.
func (*HTMLEngine) VisitStyled ¶ added in v0.12.0
func (engine *HTMLEngine) VisitStyled(con booklit.Styled) error
VisitStyled renders con using (Style).tmpl.
func (*HTMLEngine) VisitTable ¶ added in v0.12.0
func (engine *HTMLEngine) VisitTable(con booklit.Table) error
VisitTable renders con using table.tmpl.
func (*HTMLEngine) VisitTableOfContents ¶ added in v0.12.0
func (engine *HTMLEngine) VisitTableOfContents(con booklit.TableOfContents) error
VisitTableOfContents renders con using toc.tmpl.
func (*HTMLEngine) VisitTarget ¶ added in v0.12.0
func (engine *HTMLEngine) VisitTarget(con booklit.Target) error
VisitTarget renders con using target.tmpl.
type SearchDocument ¶ added in v0.6.0
type SearchDocument struct { // The tag's URL. Location string `json:"location"` // The title of the tag. Title string `json:"title"` // The text content for the tag, or the section's text if the tag // does not have its own content. Text string `json:"text"` // The depth of the tag's section. Depth int `json:"depth"` // The containing section's primary tag. SectionTag string `json:"section_tag"` }
SearchDocument contains data useful for implementing inline search.
type SearchIndex ¶ added in v0.6.0
type SearchIndex map[string]SearchDocument
SearchIndex is a mapping from tag names to a summary useful for inline search.
type TextEngine ¶ added in v0.12.0
type TextEngine struct {
// contains filtered or unexported fields
}
TextEngine renders sections as plaintext using Go's text/template system.
Text templates may be provided to generate e.g. Markdown or other plaintext formats.
func NewTextEngine ¶ added in v0.12.0
func NewTextEngine(fileExtension string) *TextEngine
NewTextEngine constructs a new TextEngine with the basic set of text templates bundled with Booklit.
A file extension must be provided, e.g. "md" for Markdown.
func (*TextEngine) FileExtension ¶ added in v0.12.0
func (engine *TextEngine) FileExtension() string
FileExtension returns the configured file extension.
func (*TextEngine) LoadTemplates ¶ added in v0.12.0
func (engine *TextEngine) LoadTemplates(templatesDir string) error
LoadTemplates loads all *.tmpl files in the specified directory.
func (*TextEngine) RenderSection ¶ added in v0.12.0
RenderSection renders the section to the writer using page.tmpl.
If the section has Style set and a template named (Style)-page.tmpl exists it will be used instead.
func (*TextEngine) URL ¶ added in v0.12.0
func (engine *TextEngine) URL(tag booklit.Tag) string
URL returns the file name using te configured file extension, with an anchor if present.
func (*TextEngine) VisitDefinitions ¶ added in v0.12.0
func (engine *TextEngine) VisitDefinitions(con booklit.Definitions) error
VisitDefinitions renders con using definitions.tmpl.
func (*TextEngine) VisitImage ¶ added in v0.12.0
func (engine *TextEngine) VisitImage(con booklit.Image) error
VisitImage renders con using image.tmpl.
func (*TextEngine) VisitLink ¶ added in v0.12.0
func (engine *TextEngine) VisitLink(con booklit.Link) error
VisitLink renders con using link.tmpl.
func (*TextEngine) VisitList ¶ added in v0.12.0
func (engine *TextEngine) VisitList(con booklit.List) error
VisitList renders con using list.tmpl.
func (*TextEngine) VisitParagraph ¶ added in v0.12.0
func (engine *TextEngine) VisitParagraph(con booklit.Paragraph) error
VisitParagraph renders con using paragraph.tmpl.
func (*TextEngine) VisitPreformatted ¶ added in v0.12.0
func (engine *TextEngine) VisitPreformatted(con booklit.Preformatted) error
VisitPreformatted renders con using preformatted.tmpl.
func (*TextEngine) VisitReference ¶ added in v0.12.0
func (engine *TextEngine) VisitReference(con *booklit.Reference) error
VisitReference renders con using reference.tmpl.
func (*TextEngine) VisitSection ¶ added in v0.12.0
func (engine *TextEngine) VisitSection(con *booklit.Section) error
VisitSection renders con using section.tmpl.
If the section has Style set and a template named (Style).tmpl exists it will be used instead.
func (*TextEngine) VisitSequence ¶ added in v0.12.0
func (engine *TextEngine) VisitSequence(con booklit.Sequence) error
VisitSequence renders con using sequence.tmpl.
func (*TextEngine) VisitString ¶ added in v0.12.0
func (engine *TextEngine) VisitString(con booklit.String) error
VisitString renders con using string.tmpl.
func (*TextEngine) VisitStyled ¶ added in v0.12.0
func (engine *TextEngine) VisitStyled(con booklit.Styled) error
VisitStyled renders con using (Style).tmpl.
func (*TextEngine) VisitTable ¶ added in v0.12.0
func (engine *TextEngine) VisitTable(con booklit.Table) error
VisitTable renders con using table.tmpl.
func (*TextEngine) VisitTableOfContents ¶ added in v0.12.0
func (engine *TextEngine) VisitTableOfContents(con booklit.TableOfContents) error
VisitTableOfContents renders con using toc.tmpl.
func (*TextEngine) VisitTarget ¶ added in v0.12.0
func (engine *TextEngine) VisitTarget(con booklit.Target) error
VisitTarget renders con using target.tmpl.
type WalkContext ¶
WalkContext is a utility type constructed via the walkContext template function.
type Writer ¶
Writer writes rendered content using an Engine to the given destination.
func (Writer) WriteSearchIndex ¶ added in v0.8.0
WriteSearchIndex generates and writes a SearchIndex in JSON format to the given path within the destination.