Documentation ¶
Index ¶
- Constants
- Variables
- func GetChromaLexer(name string) chroma.Lexer
- func NewAttrExt() goldmark.Extender
- func NewCodeBlocksExt() goldmark.Extender
- func NewHighlighter(cfg HighlightConfig) markdown.Highlighter
- func NewImagesExt(wrapStandAloneImageWithinParagraph bool) goldmark.Extender
- func NewLinkHooks(protocol string) goldmark.Extender
- func NewPassThroughExt(c PassThroughConfig) goldmark.Extender
- func NewTocExtension(options []renderer.Option) goldmark.Extender
- func RenderASTAttributes(w io.FlexiWriter, attributes ...ast.Attribute)
- func RenderAttributes(w io.FlexiWriter, skipClass bool, attributes ...markdown.Attribute)
- func WritePreStart(w io.Writer, language, styleAttr string)
- type Attribute
- type Attributes
- type AttributesHolder
- type AttributesOwnerType
- type BufWriter
- type CJK
- type CodeBlockTransformer
- type Context
- type DelimitersConfig
- type Extensions
- type Fragments
- type GoldMarkConfig
- type Headings
- type HighlightConfig
- type HighlightResult
- type IdFactory
- type ImageRenderHook
- type ImagesTransformer
- type LinkRenderHook
- type Parser
- type ParserAttribute
- type ParserContext
- type ParserResult
- type PassThroughConfig
- type PassThroughDelimiters
- type Passthrough
- type PassthroughBlock
- type RenderContextDataHolder
- type RenderHooks
- type RenderResult
- type Renderer
- type Result
- type TocBuilder
- type TocConfig
- type TocHeading
- type Typographer
Constants ¶
const ( AutoHeadingIDTypeGitHub = "github" AutoHeadingIDTypeGitHubAscii = "github-ascii" AutoHeadingIDTypeBlackfriday = "blackfriday" )
const ( ImageAttrIsBlock = "_h__isBlock" ImageAttrOrdinal = "_h__ordinal" )
Variables ¶
var DefaultGoldMarkConf = GoldMarkConfig{ Extensions: Extensions{ Typographer: Typographer{ Disable: false, LeftSingleQuote: "‘", RightSingleQuote: "’", LeftDoubleQuote: "“", RightDoubleQuote: "”", EnDash: "–", EmDash: "—", Ellipsis: "…", LeftAngleQuote: "«", RightAngleQuote: "»", Apostrophe: "’", }, Footnote: true, DefinitionList: true, Table: true, Strikethrough: true, Linkify: true, LinkifyProtocol: "https", TaskList: true, CJK: CJK{ Enable: false, EastAsianLineBreaks: false, EastAsianLineBreaksStyle: "simple", EscapedSpace: false, }, Passthrough: Passthrough{ Enable: false, Delimiters: DelimitersConfig{ Inline: [][]string{}, Block: [][]string{}, }, }, Highlight: DefaultHighlightConfig, }, Renderer: Renderer{ Unsafe: false, }, Parser: Parser{ AutoHeadingID: true, AutoHeadingIDType: AutoHeadingIDTypeGitHub, WrapStandAloneImageWithinParagraph: true, Attribute: ParserAttribute{ Title: true, Block: false, }, }, }
DefaultGoldMarkConf holds the default Goldmark configuration.
var DefaultHighlightConfig = HighlightConfig{ Style: "monokai", LineNoStart: 1, CodeFences: true, NoClasses: true, LineNumbersInTable: true, TabWidth: 4, }
var DefaultTocConfig = TocConfig{ StartLevel: 2, EndLevel: 3, Ordered: false, }
DefaultTocConfig is the default ToC configuration.
var Empty = &Fragments{ Headings: Headings{}, HeadingsMap: map[string]*TocHeading{}, }
Empty is an empty ToC.
var EmptyAttr = &AttributesHolder{}
EmptyAttr holds no attributes.
var KindCodeBlock = ast.NewNodeKind("HugoCodeBlock")
KindCodeBlock is the kind of an Hugo code block.
var KindPassthroughBlock = ast.NewNodeKind("PassthroughBlock")
KindPassthroughBlock is a NodeKind of the PassthroughBlock node.
var KindPassthroughInline = ast.NewNodeKind("PassthroughInline")
KindPassthroughInline is a NodeKind of the PassthroughInline node.
var PassthroughInlineTransformer = &passthroughInlineTransformer{}
Functions ¶
func GetChromaLexer ¶
func GetChromaLexer(name string) chroma.Lexer
GetChromaLexer returns a lexer for the given language name, nil if not found. This is just a wrapper around chromalexers.Get that caches the result. Reasoning for this is that chromalexers.Get is slow in the case where the lexer is not found, which is a common case in Hugo.
func NewAttrExt ¶
func NewCodeBlocksExt ¶
func NewHighlighter ¶
func NewHighlighter(cfg HighlightConfig) markdown.Highlighter
func NewImagesExt ¶
func NewLinkHooks ¶
func NewPassThroughExt ¶
func NewPassThroughExt(c PassThroughConfig) goldmark.Extender
func RenderASTAttributes ¶
func RenderASTAttributes(w io.FlexiWriter, attributes ...ast.Attribute)
RenderASTAttributes writes the AST attributes to the given as attributes to an HTML element. This is used by the default HTML renderers, e.g. for headings etc. where no hook template could be found. This performs HTML escaping of string attributes.
func RenderAttributes ¶
func RenderAttributes(w io.FlexiWriter, skipClass bool, attributes ...markdown.Attribute)
RenderAttributes Render writes the attributes to the given as attributes to an HTML element. This is used for the default codeblock rendering. This performs HTML escaping of string attributes.
func WritePreStart ¶
Types ¶
type Attribute ¶
func (Attribute) ValueString ¶
type Attributes ¶
type AttributesHolder ¶
type AttributesHolder struct {
// contains filtered or unexported fields
}
func NewAttr ¶
func NewAttr(astAttributes []ast.Attribute, ownerType AttributesOwnerType) *AttributesHolder
func (*AttributesHolder) Attributes ¶
func (a *AttributesHolder) Attributes() map[string]any
func (*AttributesHolder) AttributesSlice ¶
func (a *AttributesHolder) AttributesSlice() []Attribute
func (*AttributesHolder) Options ¶
func (a *AttributesHolder) Options() map[string]any
func (*AttributesHolder) OptionsSlice ¶
func (a *AttributesHolder) OptionsSlice() []Attribute
type AttributesOwnerType ¶
type AttributesOwnerType int
const ( AttributesOwnerGeneral AttributesOwnerType = iota AttributesOwnerCodeBlockChroma AttributesOwnerCodeBlockCustom )
type CJK ¶
type CJK struct { // Whether to enable CJK support. Enable bool // Whether softline breaks between east asian wide characters should be ignored. EastAsianLineBreaks bool // Styles of Line Breaking of EastAsianLineBreaks: "simple" or "css3draft" EastAsianLineBreaksStyle string // Whether a '\' escaped half-space(0x20) should not be rendered. EscapedSpace bool }
type CodeBlockTransformer ¶
type CodeBlockTransformer struct{}
type Context ¶
type Context struct { *BufWriter markdown.ContextData // contains filtered or unexported fields }
type DelimitersConfig ¶
type DelimitersConfig struct { // The delimiters to use for inline passthroughs. Each entry in the list // is a size-2 list of strings, where the first string is the opening delimiter // and the second string is the closing delimiter, e.g., // // [["$", "$"], ["\\(", "\\)"]] Inline [][]string // The delimiters to use for block passthroughs. Same format as Inline. Block [][]string }
type Extensions ¶
type Extensions struct { Typographer Typographer Footnote bool DefinitionList bool Passthrough Passthrough // GitHub flavored markdown Table bool Strikethrough bool Linkify bool LinkifyProtocol string TaskList bool CJK CJK // The configuration used by code highlighters. Highlight HighlightConfig Emoji bool }
type Fragments ¶
type Fragments struct { // Headings holds the top level headings. Headings Headings // Identifiers holds all the identifiers in the ToC as a sorted slice. // Note that collections.SortedStringSlice has both a Contains and Count method // that can be used to identify missing and duplicate IDs. Identifiers collections.SortedStringSlice // HeadingsMap holds all the headings in the ToC as a map. // Note that with duplicate IDs, the last one will win. HeadingsMap map[string]*TocHeading }
Fragments holds the table of contents for a page.
type GoldMarkConfig ¶
type GoldMarkConfig struct { Renderer Renderer Parser Parser Extensions Extensions DuplicateResourceFiles bool RenderHooks RenderHooks }
GoldMarkConfig configures Goldmark.
type HighlightConfig ¶
type HighlightConfig struct { Style string CodeFences bool // Use inline CSS styles. NoClasses bool // No highlighting. NoHl bool // When set, line numbers will be printed. LineNos bool LineNumbersInTable bool // When set, add links to line numbers AnchorLineNos bool LineAnchors string // Start the line numbers from this value (default is 1). LineNoStart int // A space separated list of line numbers, e.g. “3-8 10-20”. Hl_Lines string // If set, the markup will not be wrapped in any container. Hl_inline bool // A parsed and ready to use list of line ranges. HL_lines_parsed [][2]int `json:"-"` // TabWidth sets the number of characters for a tab. Defaults to 4. TabWidth int GuessSyntax bool }
type HighlightResult ¶
type HighlightResult struct {
// contains filtered or unexported fields
}
HighlightResult holds the result of an highlighting operation.
func (HighlightResult) Inner ¶
func (h HighlightResult) Inner() template.HTML
Inner returns the highlighted code without the wrapping <div>, <pre> and <code> tag, suitable for inline use.
func (HighlightResult) Wrapped ¶
func (h HighlightResult) Wrapped() template.HTML
Wrapped returns the highlighted code wrapped in a <div>, <pre> and <code> tag.
type IdFactory ¶
type IdFactory struct {
// contains filtered or unexported fields
}
func NewIDFactory ¶
type ImageRenderHook ¶
type ImageRenderHook struct { // Enable the default images render hook. // We need to know if it is set or not, hence the pointer. EnableDefault *bool }
ImageRenderHook contains configuration for the images render hook.
func (ImageRenderHook) IsEnableDefault ¶
func (h ImageRenderHook) IsEnableDefault() bool
type ImagesTransformer ¶
type ImagesTransformer struct {
// contains filtered or unexported fields
}
type LinkRenderHook ¶
type LinkRenderHook struct { // Disable the default images render hook. // We need to know if it is set or not, hence the pointer. EnableDefault *bool }
LinkRenderHook contains configuration for the link render hook.
func (LinkRenderHook) IsEnableDefault ¶
func (h LinkRenderHook) IsEnableDefault() bool
type Parser ¶
type Parser struct { // Enables custom heading ids and // auto generated heading ids. AutoHeadingID bool // The strategy to use when generating heading IDs. // Available options are "github", "github-ascii". // Default is "github", which will create GitHub-compatible anchor names. AutoHeadingIDType string // Enables custom attributes. Attribute ParserAttribute // Whether to wrap stand-alone images within a paragraph or not. WrapStandAloneImageWithinParagraph bool }
type ParserAttribute ¶
type ParserContext ¶
func NewParserContext ¶
func NewParserContext(rctx markdown.RenderContext) *ParserContext
func (*ParserContext) TableOfContents ¶
func (p *ParserContext) TableOfContents() *Fragments
type ParserResult ¶
type ParserResult struct {
// contains filtered or unexported fields
}
func NewParserResult ¶
func NewParserResult(doc any, toc markdown.TocFragments) *ParserResult
func (ParserResult) Doc ¶
func (p ParserResult) Doc() any
func (ParserResult) TableOfContents ¶
func (p ParserResult) TableOfContents() markdown.TocFragments
type PassThroughConfig ¶
type PassThroughConfig struct { InlineDelimiters []PassThroughDelimiters BlockDelimiters []PassThroughDelimiters }
PassThroughConfig configures this extension.
type PassThroughDelimiters ¶
type Passthrough ¶
type Passthrough struct { // Whether to enable the extension Enable bool // The delimiters to use for inline and block passthroughs. Delimiters DelimitersConfig }
Passthrough hold passthrough configuration. github.com/hugoio/hugo-goldmark-extensions/passthrough
type PassthroughBlock ¶
A PassthroughBlock struct represents a fenced block of raw text to pass through unchanged. This is not parsed directly, but emitted by an ASTTransformer that splits a paragraph at the point of an inline passthrough with the matching block delimiters.
func (*PassthroughBlock) Dump ¶
func (n *PassthroughBlock) Dump(source []byte, level int)
Dump implements Node.Dump.
func (*PassthroughBlock) Kind ¶
func (n *PassthroughBlock) Kind() ast.NodeKind
Kind implements Node.Kind.
type RenderContextDataHolder ¶
type RenderContextDataHolder struct { Rctx markdown.RenderContext Dctx markdown.DocumentContext }
func (*RenderContextDataHolder) DocumentContext ¶
func (ctx *RenderContextDataHolder) DocumentContext() markdown.DocumentContext
func (*RenderContextDataHolder) RenderContext ¶
func (ctx *RenderContextDataHolder) RenderContext() markdown.RenderContext
type RenderHooks ¶
type RenderHooks struct { Image ImageRenderHook Link LinkRenderHook }
RenderHooks contains configuration for Goldmark render hooks.
type RenderResult ¶
type RenderResult struct {
markdown.RenderResult
}
type Result ¶
type Result struct { markdown.RenderResult markdown.TableOfContentsProvider }
type TocBuilder ¶
type TocBuilder struct {
// contains filtered or unexported fields
}
TocBuilder is used to build the ToC data structure.
func (*TocBuilder) AddAt ¶
func (b *TocBuilder) AddAt(h *TocHeading, row, level int)
AddAt adds the heading to the ToC.
type TocConfig ¶
type TocConfig struct { // Heading start level to include in the table of contents, starting // at h1 (inclusive). // <docsmeta>{ "identifiers": ["h1"] }</docsmeta> StartLevel int // Heading end level, inclusive, to include in the table of contents. // Default is 3, a value of -1 will include everything. EndLevel int // Whether to produce a ordered list or not. Ordered bool }
type TocHeading ¶
TocHeading holds the data about a heading and its children.
func (TocHeading) IsZero ¶
func (h TocHeading) IsZero() bool
IsZero is true when no ID or Text is set.
type Typographer ¶
type Typographer struct { // Whether to disable typographer. Disable bool // Value used for left single quote. LeftSingleQuote string // Value used for right single quote. RightSingleQuote string // Value used for left double quote. LeftDoubleQuote string // Value used for right double quote. RightDoubleQuote string // Value used for en dash. EnDash string // Value used for em dash. EmDash string // Value used for ellipsis. Ellipsis string // Value used for left angle quote. LeftAngleQuote string // Value used for right angle quote. RightAngleQuote string // Value used for apostrophe. Apostrophe string }
Typographer holds typographer configuration.
Source Files ¶
- attributes.go
- autoid.go
- bufwriter.go
- chromalexers.go
- config.go
- context.go
- extattributes.go
- extcodeblock.go
- extimages.go
- extlinkhooks.go
- extpassthrough.go
- exttoc.go
- highlight.go
- highlightconfig.go
- hookedrenderer.go
- linkheading.go
- linkimg.go
- parsercontext.go
- parserresult.go
- rendercontext.go
- renderresult.go
- result.go
- tableofcontents.go