valueobject

package
v0.0.0-...-f0d32e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AutoHeadingIDTypeGitHub      = "github"
	AutoHeadingIDTypeGitHubAscii = "github-ascii"
	AutoHeadingIDTypeBlackfriday = "blackfriday"
)
View Source
const (
	ImageAttrIsBlock = "_h__isBlock"
	ImageAttrOrdinal = "_h__ordinal"
)

Variables

View Source
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.

View Source
var DefaultHighlightConfig = HighlightConfig{

	Style:              "monokai",
	LineNoStart:        1,
	CodeFences:         true,
	NoClasses:          true,
	LineNumbersInTable: true,
	TabWidth:           4,
}
View Source
var DefaultTocConfig = TocConfig{
	StartLevel: 2,
	EndLevel:   3,
	Ordered:    false,
}

DefaultTocConfig is the default ToC configuration.

View Source
var Empty = &Fragments{
	Headings:    Headings{},
	HeadingsMap: map[string]*TocHeading{},
}

Empty is an empty ToC.

View Source
var EmptyAttr = &AttributesHolder{}

EmptyAttr holds no attributes.

View Source
var KindCodeBlock = ast.NewNodeKind("HugoCodeBlock")

KindCodeBlock is the kind of an Hugo code block.

View Source
var KindPassthroughBlock = ast.NewNodeKind("PassthroughBlock")

KindPassthroughBlock is a NodeKind of the PassthroughBlock node.

View Source
var KindPassthroughInline = ast.NewNodeKind("PassthroughInline")

KindPassthroughInline is a NodeKind of the PassthroughInline node.

View Source
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 NewAttrExt() goldmark.Extender

func NewCodeBlocksExt

func NewCodeBlocksExt() goldmark.Extender

func NewHighlighter

func NewHighlighter(cfg HighlightConfig) markdown.Highlighter

func NewImagesExt

func NewImagesExt(wrapStandAloneImageWithinParagraph bool) goldmark.Extender

func NewLinkHooks

func NewLinkHooks(protocol string) goldmark.Extender

func NewPassThroughExt

func NewPassThroughExt(c PassThroughConfig) goldmark.Extender

func NewTocExtension

func NewTocExtension(options []renderer.Option) 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

func WritePreStart(w io.Writer, language, styleAttr string)

Types

type Attribute

type Attribute struct {
	Name  string
	Value any
}

func (Attribute) ValueString

func (a Attribute) ValueString() string

type Attributes

type Attributes map[string]any

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 BufWriter

type BufWriter struct {
	*bytes.Buffer
}

func (*BufWriter) Available

func (b *BufWriter) Available() int

func (*BufWriter) Buffered

func (b *BufWriter) Buffered() int

func (*BufWriter) Flush

func (b *BufWriter) Flush() error

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{}

func (*CodeBlockTransformer) Transform

func (*CodeBlockTransformer) Transform(doc *ast.Document, reader text.Reader, pctx parser.Context)

Transform transforms the provided Markdown AST.

type Context

type Context struct {
	*BufWriter

	markdown.ContextData
	// contains filtered or unexported fields
}

func (*Context) PopPos

func (ctx *Context) PopPos() int

func (*Context) PushPos

func (ctx *Context) PushPos(n int)

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.

func (*Fragments) ToHTML

func (toc *Fragments) ToHTML(startLevel, stopLevel int, ordered bool) template.HTML

ToHTML renders the ToC as HTML.

type GoldMarkConfig

type GoldMarkConfig struct {
	Renderer               Renderer
	Parser                 Parser
	Extensions             Extensions
	DuplicateResourceFiles bool
	RenderHooks            RenderHooks
}

GoldMarkConfig configures Goldmark.

type Headings

type Headings []*TocHeading

Headings holds the top level headings.

func (Headings) FilterBy

func (h Headings) FilterBy(fn func(*TocHeading) bool) Headings

FilterBy returns a new Headings slice with all headings that matches the given predicate. For internal use only.

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

func NewIDFactory(idType string) *IdFactory

func (*IdFactory) Generate

func (ids *IdFactory) Generate(value []byte, kind ast.NodeKind) []byte

func (*IdFactory) Put

func (ids *IdFactory) Put(value []byte)

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
}

func (*ImagesTransformer) Transform

func (t *ImagesTransformer) Transform(doc *ast.Document, reader text.Reader, pctx parser.Context)

Transform transforms the provided Markdown AST.

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 ParserAttribute struct {
	// Enables custom attributes for titles.
	Title bool
	// Enables custom attributeds for blocks.
	Block bool
}

type ParserContext

type ParserContext struct {
	parser.Context
}

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 PassThroughDelimiters struct {
	Open  string
	Close string
}

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

type PassthroughBlock struct {
	ast.BaseBlock
}

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.Result
}

type Renderer

type Renderer struct {
	// Whether softline breaks should be rendered as '<br>'
	HardWraps bool

	// XHTML instead of HTML5.
	XHTML bool

	// Allow raw HTML etc.
	Unsafe bool
}

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.

func (TocBuilder) Build

func (b TocBuilder) Build() *Fragments

Build returns 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

type TocHeading struct {
	ID    string
	Level int
	Title string

	Headings Headings
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL