parse

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MulanPSL-2.0 Imports: 13 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmojiAliasUnicode = map[string]string{}/* 1507 elements not displayed */
View Source
var EmojiLock = sync.Mutex{}
View Source
var EmojiSitePlaceholder = util.StrToBytes("${emojiSite}")
View Source
var EmojiUnicodeAlias map[string]string
View Source
var MathBlockMarker = util.StrToBytes("$$")
View Source
var MathBlockMarkerCaret = util.StrToBytes("$$" + editor.Caret)
View Source
var MathBlockMarkerCaretNewline = util.StrToBytes("$$" + editor.Caret + "\n")
View Source
var MathBlockMarkerNewline = util.StrToBytes("$$\n")
View Source
var YamlFrontMatterMarker = util.StrToBytes("---")
View Source
var YamlFrontMatterMarkerCaret = util.StrToBytes("---" + editor.Caret)
View Source
var YamlFrontMatterMarkerCaretNewline = util.StrToBytes("---" + editor.Caret + "\n")
View Source
var YamlFrontMatterMarkerNewline = util.StrToBytes("---\n")

Functions

func ATXHeadingStart

func ATXHeadingStart(t *Tree, container *ast.Node) int

ATXHeadingStart 判断 ATX 标题(#)是否开始。

func AddAutoLinkDomainSuffix

func AddAutoLinkDomainSuffix(suffix string)

AddAutoLinkDomainSuffix 添加自动链接解析域名后缀 suffix。

func BlockQueryEmbedStart

func BlockQueryEmbedStart(t *Tree, container *ast.Node) int

BlockQueryEmbedStart 判断内容块查询嵌入({{ SELECT * FROM blocks WHERE content LIKE '%待办%' }})是否开始。

func BlockquoteContinue

func BlockquoteContinue(blockquote *ast.Node, context *Context) int

func BlockquoteStart

func BlockquoteStart(t *Tree, container *ast.Node) int

BlockquoteStart 判断块引用(>)是否开始。

func CodeBlockContinue

func CodeBlockContinue(codeBlock *ast.Node, context *Context) int

func ContainTextMark added in v1.7.5

func ContainTextMark(node *ast.Node, dataTypes ...string) bool

func CustomBlockContinue added in v1.7.6

func CustomBlockContinue(customBlock *ast.Node, context *Context) int

func CustomBlockStart added in v1.7.6

func CustomBlockStart(t *Tree, container *ast.Node) int

CustomBlockStart 判断围栏自定义块(;;;info)是否开始。

func FenceCodeBlockStart

func FenceCodeBlockStart(t *Tree, container *ast.Node) int

FenceCodeBlockStart 判断围栏代码块(```)是否开始。

func FootnotesContinue

func FootnotesContinue(footnotesDef *ast.Node, context *Context) int

func FootnotesStart

func FootnotesStart(t *Tree, container *ast.Node) int

FootnotesStart 判断脚注定义([^label])是否开始。

func GitConflictContinue

func GitConflictContinue(gitConflictBlock *ast.Node, context *Context) int

func GitConflictStart

func GitConflictStart(t *Tree, container *ast.Node) int

判断 Git 冲突标记是否开始。

<<<<<<< HEAD
这里是本地原来的内容
=======
这里是拉取下来的内容
>>>>>>> feebfeb6bef44cf1384d51cdd7aef7e4197b8180

func HtmlBlockContinue

func HtmlBlockContinue(html *ast.Node, context *Context) int

func HtmlBlockStart

func HtmlBlockStart(t *Tree, container *ast.Node) int

HtmlBlockStart 判断 HTML 块(<)是否开始。

func IAL2Map

func IAL2Map(ial [][]string) (ret map[string]string)

func IAL2MapUnEsc

func IAL2MapUnEsc(ial [][]string) (ret map[string]string)

func IAL2Tokens

func IAL2Tokens(ial [][]string) []byte

func IALStart

func IALStart(t *Tree, container *ast.Node) int

IALStart 判断 kramdown 块级内联属性列表({: attrs})是否开始。

func IALVal

func IALVal(ial *ast.Node, name string) string

func IALValMap

func IALValMap(ial *ast.Node) (ret map[string]string)

func IndentCodeBlockStart

func IndentCodeBlockStart(t *Tree, container *ast.Node) int

IndentCodeBlockStart 判断缩进代码块( code)是否开始。

func ListItemContinue

func ListItemContinue(listItem *ast.Node, context *Context) int

func ListStart

func ListStart(t *Tree, container *ast.Node) int

ListStart 判断列表、列表项(* - + 1.)或者任务列表项是否开始。

func Map2IAL

func Map2IAL(properties map[string]string) (ret [][]string)

func MathBlockContinue

func MathBlockContinue(mathBlock *ast.Node, context *Context) int

func MathBlockStart

func MathBlockStart(t *Tree, container *ast.Node) int

MathBlockStart 判断数学公式块($$)是否开始。

func NestedInlines2FlattedSpans added in v1.7.5

func NestedInlines2FlattedSpans(tree *Tree, isExportMd bool)

NestedInlines2FlattedSpans 将嵌套的行级节点转换为平铺的文本标记节点。 该函数会移除转义节点。

func NestedInlines2FlattedSpansHybrid added in v1.7.6

func NestedInlines2FlattedSpansHybrid(tree *Tree, isExportMd bool)

NestedInlines2FlattedSpansHybrid 将嵌套的行级节点转换为平铺的文本标记节点。 该函数不会移除转义节点。

func ParagraphContinue

func ParagraphContinue(p *ast.Node, context *Context) int

func SetSpanIAL added in v1.7.5

func SetSpanIAL(node *ast.Node, n *html.Node)

func SetTextMarkNode added in v1.7.5

func SetTextMarkNode(node *ast.Node, n *html.Node, options *Options)

func SetextHeadingStart

func SetextHeadingStart(t *Tree, container *ast.Node) int

SetextHeadingStart 判断 Setext 标题(- =)是否开始。

func StyleValue added in v1.7.5

func StyleValue(style string) (ret string)

func SuperBlockContinue

func SuperBlockContinue(superBlock *ast.Node, context *Context) int

func SuperBlockStart

func SuperBlockStart(t *Tree, container *ast.Node) int

SuperBlockStart 判断超级块({{{ blocks }}})是否开始。

func TagAttr

func TagAttr(tokens []byte) (valid bool, remains, attr, name, val []byte)

func ThematicBreakStart

func ThematicBreakStart(t *Tree, container *ast.Node) int

判断分隔线(--- ***)是否开始。

func Tokens2IAL

func Tokens2IAL(tokens []byte) (ret [][]string)

func YamlFrontMatterContinue

func YamlFrontMatterContinue(node *ast.Node, context *Context) int

func YamlFrontMatterStart

func YamlFrontMatterStart(t *Tree, container *ast.Node) int

判断 YAML Front Matter(---)是否开始。

Types

type Context

type Context struct {
	Tree        *Tree    // 关联的语法树
	ParseOption *Options // 解析选项

	Tip *ast.Node // 末梢节点
	// contains filtered or unexported fields
}

Context 用于维护块级元素解析过程中使用到的公共数据。

func (*Context) ParentTip

func (context *Context) ParentTip()

func (*Context) TipAppendChild

func (context *Context) TipAppendChild(child *ast.Node)

type InlineContext

type InlineContext struct {
	// contains filtered or unexported fields
}

InlineContext 描述了行级元素解析上下文。

type Options

type Options struct {
	// GFMTable 设置是否打开“GFM 表”支持。
	GFMTable bool
	// GFMTaskListItem 设置是否打开“GFM 任务列表项”支持。
	GFMTaskListItem bool
	// GFMStrikethrough 设置是否打开“GFM 删除线”支持。
	GFMStrikethrough bool
	// GFMAutoLink 设置是否打开“GFM 自动链接”支持。
	GFMAutoLink bool
	// Footnotes 设置是否打开“脚注”支持。
	Footnotes bool
	// HeadingID 设置是否打开“自定义标题 ID”支持。
	HeadingID bool
	// ToC 设置是否打开“目录”支持。
	ToC bool
	// Emoji 设置是否对 Emoji 别名替换为原生 Unicode 字符。
	Emoji bool
	// AliasEmoji 存储 ASCII 别名到表情 Unicode 映射。
	AliasEmoji map[string]string
	// EmojiAlias 存储表情 Unicode 到 ASCII 别名映射。
	EmojiAlias map[string]string
	// EmojiSite 设置图片 Emoji URL 的路径前缀。
	EmojiSite string
	// Vditor 所见即所得支持。
	VditorWYSIWYG bool
	// Vditor 即时渲染支持。
	VditorIR bool
	// Vditor 分屏预览支持。
	VditorSV bool
	// Protyle 所见即所得支持。
	ProtyleWYSIWYG bool
	// InlineMathAllowDigitAfterOpenMarker 设置内联数学公式是否允许起始 $ 后紧跟数字 https://github.com/b3log/lute/issues/38
	InlineMathAllowDigitAfterOpenMarker bool
	// Setext 设置是否解析 Setext 标题 https://github.com/88250/lute/issues/50
	Setext bool
	// YamlFrontMatter 设置是否开启 YAML Front Matter 支持。
	YamlFrontMatter bool
	// BlockRef 设置是否开启内容块引用支持。
	BlockRef bool
	// FileAnnotationRef 设置是否开启文件注解引用支持。
	FileAnnotationRef bool
	// Mark 设置是否打开 ==标记== 支持。
	Mark bool
	// KramdownBlockIAL 设置是否打开 kramdown 块级内联属性列表支持。 https://kramdown.gettalong.org/syntax.html#inline-attribute-lists
	KramdownBlockIAL bool
	// KramdownSpanIAL 设置是否打开 kramdown 行级内联属性列表支持。
	KramdownSpanIAL bool
	// Tag 设置是否开启 #标签# 支持。
	Tag bool
	// ImgPathAllowSpace 设置是否支持图片路径带空格。
	ImgPathAllowSpace bool
	// SuperBlock 设置是否支持超级块。 https://github.com/88250/lute/issues/111
	SuperBlock bool
	// Sup 设置是否打开 ^上标^ 支持。
	Sup bool
	// Sub 设置是否打开 ~下标~ 支持。
	Sub bool
	// GitConflict 设置是否打开 Git 冲突标记支持。
	GitConflict bool
	// LinkRef 设置是否打开“链接引用”支持。
	LinkRef bool
	// IndentCodeBlock 设置是否打开“缩进代码块”支持。
	IndentCodeBlock bool
	// ParagraphBeginningSpace 设置是否打开“段首空格”支持。
	ParagraphBeginningSpace bool
	// DataImage 设置是否打开 ![foo](data:image...) 形式的图片支持。
	DataImage bool
	// TextMark 设置是否打开通用行级节点解析支持。
	TextMark bool
	// HTMLTag2TextMark 设置是否打开 HTML 某些标签解析为 TextMark 节点支持。目前仅支持 <u> 和 <kbd> 标签。
	// 这个开关主要用于兼容 Markdown 输入 API 上 https://github.com/siyuan-note/siyuan/issues/6039
	// 不用于 Protyle 自旋过程 https://github.com/siyuan-note/siyuan/issues/5877
	HTMLTag2TextMark bool
	// Spin 设置是否打开自旋解析支持,该选项仅用于 Spin 内部过程,设置时请注意使用场景。
	//
	// 该选项的引入主要为了解决 finalParseBlockIAL 过程中是否需要移动 IAL 节点的问题,只有处于自旋过程中才需要移动 IAL 节点
	// 其他情况,比如标题块软换行分块 https://github.com/siyuan-note/siyuan/issues/5723 以及软换行空行分块 https://ld246.com/article/1703839312585
	// 的场景需要移动 IAL 节点,但是 API 输入 markdown https://github.com/siyuan-note/siyuan/issues/6725)无需移动
	Spin bool
}

Options 描述了解析选项。

func NewOptions

func NewOptions() *Options

type Tree

type Tree struct {
	Root    *ast.Node // 根节点
	Context *Context  // 块级解析上下文

	Name    string   // 名称
	ID      string   // ID
	Box     string   // 容器
	Path    string   // 路径
	HPath   string   // 人类可读的路径
	Marks   []string // 文本标记
	Created int64    // 创建时间
	Updated int64    // 更新时间
	Hash    string   // 内容哈希
	// contains filtered or unexported fields
}

Tree 描述了 Markdown 抽象语法树结构。

func Block

func Block(name string, markdown []byte, options *Options) (tree *Tree)

Block 会将 markdown 原始文本字节数组解析为一棵语法树,该语法树的第一个块级子节点是段落节点。

func Inline

func Inline(name string, markdown []byte, options *Options) (tree *Tree)

Inline 会将 markdown 原始文本字节数组解析为一棵语法树,该语法树的第一个块级子节点是段落节点。

func Parse

func Parse(name string, markdown []byte, options *Options) (tree *Tree)

Parse 会将 markdown 原始文本字节数组解析为一棵语法树。

func (*Tree) BlockCount

func (t *Tree) BlockCount() (ret int)

func (*Tree) DocBlockCount

func (t *Tree) DocBlockCount() (ret int)

func (*Tree) EmojiImgTokens

func (t *Tree) EmojiImgTokens(alias, src string) []byte

func (*Tree) FindFootnotesDef

func (t *Tree) FindFootnotesDef(label []byte) (pos int, def *ast.Node)
func (t *Tree) FindLinkRefDefLink(label []byte) (link *ast.Node)

func (*Tree) MergeText added in v1.7.6

func (t *Tree) MergeText()

Jump to

Keyboard shortcuts

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