djot_parser

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	RawInlineFormatKey    = "$RawInlineFormatKey"
	RawBlockFormatKey     = "$RawBlockLevelKey"
	HeadingLevelKey       = "$HeadingLevelKey"
	SparseListNodeKey     = "$SparseListNodeKey"
	DefinitionListItemKey = "$DefinitionListItemKey"

	IdKey                  = "id"
	RoleKey                = "role"
	LinkHrefKey            = "href"
	ImgAltKey              = "alt"
	ImgSrcKey              = "src"
	TaskListClass          = "task-list"
	CheckedTaskItemClass   = "checked"
	UncheckedTaskItemClass = "unchecked"
	LeftAlignment          = "left"
	CenterAlignment        = "center"
	RightAlignment         = "right"
	DefaultAlignment       = ""
)

Variables

View Source
var (
	UnorderedListByteMask = tokenizer.NewByteMask([]byte("-+*"))
	DigitByteMask         = tokenizer.NewByteMask([]byte("0123456789"))
	LowerAlphaByteMask    = tokenizer.NewByteMask([]byte("abcdefghijklmnopqrstuvwxyz"))
	UpperAlphaByteMask    = tokenizer.NewByteMask([]byte("ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
)

Functions

func CreateSectionId

func CreateSectionId(s string) string

Types

type Children

type Children []TreeNode[DjotNode]

type Conversion

type Conversion[T any] func(state ConversionState[T], next func(Children))

type ConversionContext

type ConversionContext[T any] struct {
	Format   string
	Registry ConversionRegistry[T]
}

ConversionContext holds registry of conversion functions for all AST nodes Note, that it has generic parameter T which is opaque for the library and caller can use it however he wants (for example, render data somewhere or just analyze AST and accumulate some knowledge in the internal fields of T)

Also, third-party libraries can implement custom factories for ConversionContext for targets different from HTML (see https://git.sr.ht/~ser/godjot/issues/14 for more details)

func NewConversionContext

func NewConversionContext(_ backCompatGuard) ConversionContext[backCompatGuard]

NewConversionContext kept to simplify migration from old API to the new approach Deprecated: use djot_html.New(converters...) instead See https://git.sr.ht/~ser/godjot/releases/tag/v2.0.0

func (ConversionContext[T]) ConvertDjot

func (context ConversionContext[T]) ConvertDjot(
	builder T,
	nodes ...TreeNode[DjotNode],
) T

type ConversionRegistry

type ConversionRegistry[T any] map[DjotNode]Conversion[T]

type ConversionState

type ConversionState[T any] struct {
	Format string
	Writer T
	Node   TreeNode[DjotNode]
	Parent *TreeNode[DjotNode]
}

type DjotContext

type DjotContext struct {
	References          map[string][]byte
	ReferenceAttributes map[string]tokenizer.Attributes
	FootnoteId          map[string]int
}

func BuildDjotContext

func BuildDjotContext(document []byte, list tokenizer.TokenList[djot_tokenizer.DjotToken]) DjotContext

type DjotLocalContext

type DjotLocalContext struct {
	TextNode   bool
	TableNode  bool
	TableProps TableProps
}

type DjotNode

type DjotNode int
const (
	DocumentNode DjotNode = iota
	SectionNode
	ParagraphNode
	HeadingNode
	QuoteNode
	UnorderedListNode
	OrderedListNode
	DefinitionListNode
	TaskListNode
	ListItemNode
	DefinitionTermNode
	DefinitionItemNode
	CodeNode
	RawNode
	ThematicBreakNode
	DivNode
	TableNode
	TableCaptionNode
	TableRowNode
	TableHeaderNode
	TableCellNode
	ReferenceDefNode
	FootnoteDefNode
	TextNode
	EmphasisNode
	StrongNode
	HighlightedNode
	SubscriptNode
	SuperscriptNode
	InsertNode
	DeleteNode
	SymbolsNode
	VerbatimNode
	LineBreakNode
	LinkNode
	ImageNode
	SpanNode
)

func (DjotNode) IsList

func (n DjotNode) IsList() bool

func (DjotNode) String

func (n DjotNode) String() string

type ListProps

type ListProps struct {
	Type   DjotNode
	Style  string
	Marker string
}

type QuoteDirection

type QuoteDirection int
const (
	OpenQuote  QuoteDirection = +1
	CloseQuote QuoteDirection = -1
)

type TableProps

type TableProps struct {
	TableIndex int
	Ignore     bool
	IsHeader   bool
	Alignments []string
}

type TreeNode

type TreeNode[T ~int] struct {
	Type       T
	Attributes tokenizer.Attributes
	Children   []TreeNode[T]
	Text       []byte
	Index      int
}

func BuildDjotAst

func BuildDjotAst(document []byte) []TreeNode[DjotNode]

func (TreeNode[T]) FullText

func (n TreeNode[T]) FullText() []byte

func (TreeNode[T]) Traverse

func (n TreeNode[T]) Traverse(f func(node TreeNode[T]))

Jump to

Keyboard shortcuts

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