Documentation
¶
Overview ¶
Package lute 提供了一款结构化的 Markdown 引擎,支持 Go 和 JavaScript。
Index ¶
- Constants
- func FormatNodeSync(node *ast.Node, parseOptions *parse.Options, renderOptions *render.Options) (ret string, err error)
- func ProtyleExportMdNodeSync(node *ast.Node, parseOptions *parse.Options, renderOptions *render.Options) (ret string, err error)
- type Lute
- func (lute *Lute) BlockDOM2Content(htmlStr string) (text string)
- func (lute *Lute) BlockDOM2EscapeMarkerContent(htmlStr string) (text string)
- func (lute *Lute) BlockDOM2HTML(vHTML string) (sHTML string)
- func (lute *Lute) BlockDOM2InlineBlockDOM(vHTML string) (vIHTML string)
- func (lute *Lute) BlockDOM2Md(htmlStr string) (kramdown string)
- func (lute *Lute) BlockDOM2StdMd(htmlStr string) (markdown string)
- func (lute *Lute) BlockDOM2Text(htmlStr string) (text string)
- func (lute *Lute) BlockDOM2TextLen(htmlStr string) int
- func (lute *Lute) BlockDOM2Tree(htmlStr string) (ret *parse.Tree)
- func (lute *Lute) Blocks2Hs(ivHTML, level string) (ovHTML string)
- func (lute *Lute) Blocks2Ps(ivHTML string) (ovHTML string)
- func (lute *Lute) CancelBlockquote(ivHTML string) (ovHTML string)
- func (lute *Lute) CancelList(ivHTML string) (ovHTML string)
- func (lute *Lute) CancelSuperBlock(ivHTML string) (ovHTML string)
- func (lute *Lute) Format(name string, markdown []byte) (formatted []byte)
- func (lute *Lute) FormatStr(name, markdown string) (formatted string)
- func (lute *Lute) GetEmojis() (ret map[string]string)
- func (lute *Lute) GetLinkBase() string
- func (lute *Lute) GetTerms() map[string]string
- func (lute *Lute) HTML2BlockDOM(sHTML string) (vHTML string)
- func (lute *Lute) HTML2Markdown(htmlStr string) (markdown string, err error)
- func (lute *Lute) HTML2Md(html string) (markdown string)
- func (lute *Lute) HTML2Text(dom string) string
- func (lute *Lute) HTML2Tree(dom string) (ret *parse.Tree)
- func (lute *Lute) HTML2VditorDOM(sHTML string) (vHTML string)
- func (lute *Lute) HTML2VditorIRDOM(sHTML string) (vHTML string)
- func (lute *Lute) HTML2VditorSVDOM(sHTML string) (vHTML string)
- func (lute *Lute) InlineMd2BlockDOM(markdown string) (vHTML string)
- func (lute *Lute) IsValidLinkDest(str string) bool
- func (lute *Lute) Markdown(name string, markdown []byte) (html []byte)
- func (lute *Lute) MarkdownStr(name, markdown string) (html string)
- func (lute *Lute) Md2BlockDOM(markdown string, reserveEmptyParagraph bool) (vHTML string)
- func (lute *Lute) Md2BlockDOMTree(markdown string, reserveEmptyParagraph bool) (vHTML string, tree *parse.Tree)
- func (lute *Lute) Md2HTML(markdown string) (sHTML string)
- func (lute *Lute) Md2VditorDOM(markdown string) (vHTML string)
- func (lute *Lute) Md2VditorIRDOM(markdown string) (vHTML string)
- func (lute *Lute) Md2VditorSVDOM(markdown string) (vHTML string)
- func (lute *Lute) MergeSameSpan(n *ast.Node)
- func (lute *Lute) MergeSameTextMark(n *ast.Node)
- func (lute *Lute) OL2TL(ivHTML string) (ovHTML string)
- func (lute *Lute) OL2UL(ivHTML string) (ovHTML string)
- func (lute *Lute) ProtylePreview(tree *parse.Tree, options *render.Options) string
- func (lute *Lute) PutEmojis(emojiMap map[string]string)
- func (lute *Lute) PutTerms(termMap map[string]string)
- func (lute *Lute) RemoveEmoji(str string) string
- func (lute *Lute) RenderEChartsJSON(markdown string) (json string)
- func (lute *Lute) RenderJSON(markdown string) (json string)
- func (lute *Lute) RenderKityMinderJSON(markdown string) (json string)
- func (lute *Lute) RenderNodeBlockDOM(node *ast.Node) string
- func (lute *Lute) SetAutoSpace(b bool)
- func (lute *Lute) SetBlockRef(b bool)
- func (lute *Lute) SetChineseParagraphBeginningSpace(b bool)
- func (lute *Lute) SetCodeSyntaxHighlight(b bool)
- func (lute *Lute) SetCodeSyntaxHighlightDetectLang(b bool)
- func (lute *Lute) SetCodeSyntaxHighlightInlineStyle(b bool)
- func (lute *Lute) SetCodeSyntaxHighlightLineNum(b bool)
- func (lute *Lute) SetCodeSyntaxHighlightStyleName(name string)
- func (lute *Lute) SetDataImage(b bool)
- func (lute *Lute) SetEmoji(b bool)
- func (lute *Lute) SetEmojiSite(emojiSite string)
- func (lute *Lute) SetEmojis(emojis map[string]string)
- func (lute *Lute) SetFileAnnotationRef(b bool)
- func (lute *Lute) SetFixTermTypo(b bool)
- func (lute *Lute) SetFootnotes(b bool)
- func (lute *Lute) SetGFMAutoLink(b bool)
- func (lute *Lute) SetGFMStrikethrough(b bool)
- func (lute *Lute) SetGFMTable(b bool)
- func (lute *Lute) SetGFMTaskListItem(b bool)
- func (lute *Lute) SetGFMTaskListItemClass(class string)
- func (lute *Lute) SetGitConflict(b bool)
- func (lute *Lute) SetHTMLTag2TextMark(b bool)
- func (lute *Lute) SetHeadingAnchor(b bool)
- func (lute *Lute) SetHeadingID(b bool)
- func (lute *Lute) SetImageLazyLoading(dataSrc string)
- func (lute *Lute) SetImgPathAllowSpace(b bool)
- func (lute *Lute) SetIndentCodeBlock(b bool)
- func (lute *Lute) SetInlineMathAllowDigitAfterOpenMarker(b bool)
- func (lute *Lute) SetJSRenderers(options map[string]map[string]*js.Object)
- func (lute *Lute) SetKramdownBlockIAL(b bool)
- func (lute *Lute) SetKramdownIAL(b bool)
- func (lute *Lute) SetKramdownIALIDRenderName(name string)
- func (lute *Lute) SetKramdownSpanIAL(b bool)
- func (lute *Lute) SetLinkBase(linkBase string)
- func (lute *Lute) SetLinkPrefix(linkPrefix string)
- func (lute *Lute) SetLinkRef(b bool)
- func (lute *Lute) SetMark(b bool)
- func (lute *Lute) SetParagraphBeginningSpace(b bool)
- func (lute *Lute) SetProtyleMarkNetImg(b bool)
- func (lute *Lute) SetProtyleWYSIWYG(b bool)
- func (lute *Lute) SetRenderListStyle(b bool)
- func (lute *Lute) SetSanitize(b bool)
- func (lute *Lute) SetSetext(b bool)
- func (lute *Lute) SetSoftBreak2HardBreak(b bool)
- func (lute *Lute) SetSpellcheck(b bool)
- func (lute *Lute) SetSpin(b bool)
- func (lute *Lute) SetSub(b bool)
- func (lute *Lute) SetSup(b bool)
- func (lute *Lute) SetSuperBlock(b bool)
- func (lute *Lute) SetTag(b bool)
- func (lute *Lute) SetTerms(terms map[string]string)
- func (lute *Lute) SetTextMark(b bool)
- func (lute *Lute) SetToC(b bool)
- func (lute *Lute) SetVditorCodeBlockPreview(b bool)
- func (lute *Lute) SetVditorHTMLBlockPreview(b bool)
- func (lute *Lute) SetVditorIR(b bool)
- func (lute *Lute) SetVditorMathBlockPreview(b bool)
- func (lute *Lute) SetVditorSV(b bool)
- func (lute *Lute) SetVditorWYSIWYG(b bool)
- func (lute *Lute) SetYamlFrontMatter(b bool)
- func (lute *Lute) Space(text string) string
- func (lute *Lute) SpinBlockDOM(ivHTML string) (ovHTML string)
- func (lute *Lute) SpinVditorDOM(ivHTML string) (ovHTML string)
- func (lute *Lute) SpinVditorIRDOM(ivHTML string) (ovHTML string)
- func (lute *Lute) SpinVditorSVDOM(markdown string) (ovHTML string)
- func (lute *Lute) TL2OL(ivHTML string) (ovHTML string)
- func (lute *Lute) TL2UL(ivHTML string) (ovHTML string)
- func (lute *Lute) TextBundle(name string, markdown []byte, linkPrefixes []string) (textbundle []byte, originalLinks []string)
- func (lute *Lute) TextBundleStr(name, markdown string, linkPrefixes []string) (textbundle string, originalLinks []string)
- func (lute *Lute) Tree2BlockDOM(tree *parse.Tree, options *render.Options) (vHTML string)
- func (lute *Lute) Tree2HTML(tree *parse.Tree, options *render.Options) string
- func (lute *Lute) UL2OL(ivHTML string) (ovHTML string)
- func (lute *Lute) UL2TL(ivHTML string) (ovHTML string)
- func (lute *Lute) VditorDOM2HTML(vhtml string) (sHTML string)
- func (lute *Lute) VditorDOM2Md(htmlStr string) (markdown string)
- func (lute *Lute) VditorIRDOM2HTML(vhtml string) (sHTML string)
- func (lute *Lute) VditorIRDOM2Md(htmlStr string) (markdown string)
- type ParseOption
Constants ¶
const Version = "1.7.6"
Variables ¶
This section is empty.
Functions ¶
func FormatNodeSync ¶
Types ¶
type Lute ¶
type Lute struct { ParseOptions *parse.Options // 解析选项 RenderOptions *render.Options // 渲染选项 HTML2MdRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 HTML2Md 渲染器函数 HTML2VditorDOMRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 HTML2VditorDOM 渲染器函数 HTML2VditorIRDOMRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 HTML2VditorIRDOM 渲染器函数 HTML2BlockDOMRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 HTML2BlockDOM 渲染器函数 HTML2VditorSVDOMRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 HTML2VditorSVDOM 渲染器函数 Md2HTMLRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 Md2HTML 渲染器函数 Md2VditorDOMRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 Md2VditorDOM 渲染器函数 Md2VditorIRDOMRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 Md2VditorIRDOM 渲染器函数 Md2BlockDOMRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 Md2BlockDOM 渲染器函数 Md2VditorSVDOMRendererFuncs map[ast.NodeType]render.ExtRendererFunc // 用户自定义的 Md2VditorSVDOM 渲染器函数 }
Lute 描述了 Lute 引擎的顶层使用入口。
func New ¶
func New(opts ...ParseOption) (ret *Lute)
New 创建一个新的 Lute 引擎。
默认启用的解析选项:
- GFM 支持
- 脚注
- 标题自定义 ID
- Emoji 别名替换,比如 :heart: 替换为 ❤️
- YAML Front Matter
默认启用的渲染选项:
- 软换行转硬换行
- 代码块语法高亮
- 中西文间插入空格
- 修正术语拼写
- 标题自定义 ID
func (*Lute) BlockDOM2Content ¶
func (*Lute) BlockDOM2EscapeMarkerContent ¶ added in v1.7.6
func (*Lute) BlockDOM2HTML ¶
func (*Lute) BlockDOM2InlineBlockDOM ¶
func (*Lute) BlockDOM2Md ¶
func (*Lute) BlockDOM2StdMd ¶
func (*Lute) BlockDOM2Text ¶
func (*Lute) BlockDOM2TextLen ¶
func (*Lute) CancelBlockquote ¶
func (*Lute) CancelList ¶
func (*Lute) CancelSuperBlock ¶
func (*Lute) GetLinkBase ¶
func (*Lute) HTML2BlockDOM ¶
func (*Lute) HTML2Markdown ¶
HTML2Markdown 将 HTML 转换为 Markdown。
func (*Lute) HTML2VditorDOM ¶
HTML2VditorDOM 将 HTML 转换为 Vditor DOM,用于所见即所得模式下粘贴。
func (*Lute) HTML2VditorIRDOM ¶
HTML2VditorIRDOM 将 HTML 转换为 Vditor Instant-Rendering DOM,用于即时渲染模式下粘贴。
func (*Lute) HTML2VditorSVDOM ¶
HTML2VditorSVDOM 将 HTML 转换为 Vditor Split-View DOM,用于分屏预览模式下粘贴。
func (*Lute) InlineMd2BlockDOM ¶
func (*Lute) IsValidLinkDest ¶
IsValidLinkDest 判断 str 是否为合法的链接地址。
func (*Lute) Markdown ¶
Markdown 将 markdown 文本字节数组处理为相应的 html 字节数组。name 参数仅用于标识文本,比如可传入 id 或者标题,也可以传入 ""。
func (*Lute) MarkdownStr ¶
MarkdownStr 接受 string 类型的 markdown 后直接调用 Markdown 进行处理。
func (*Lute) Md2BlockDOM ¶
func (*Lute) Md2BlockDOMTree ¶ added in v1.7.6
func (*Lute) Md2VditorDOM ¶
Md2VditorDOM 将 markdown 转换为 Vditor DOM,用于从源码模式切换至所见即所得模式。
func (*Lute) Md2VditorIRDOM ¶
Md2VditorIRDOM 将 markdown 转换为 Vditor Instant-Rendering DOM,用于从源码模式切换至即时渲染模式。
func (*Lute) Md2VditorSVDOM ¶
Md2VditorSVDOM 将 markdown 转换为 Vditor Split-View DOM,用于从源码模式切换至分屏预览模式。
func (*Lute) MergeSameSpan ¶
func (*Lute) MergeSameTextMark ¶ added in v1.7.5
func (*Lute) ProtylePreview ¶
ProtylePreview 使用指定的 options 渲染 tree 为 Protyle 预览 HTML。
func (*Lute) RemoveEmoji ¶
RemoveEmoji 用于删除 str 中的 Emoji Unicode。
func (*Lute) RenderEChartsJSON ¶
RenderEChartsJSON 用于渲染 ECharts JSON 格式数据。
func (*Lute) RenderJSON ¶
RenderJSON 用于渲染 JSON 格式数据。
func (*Lute) RenderKityMinderJSON ¶
RenderKityMinderJSON 用于渲染 KityMinder JSON 格式数据。
func (*Lute) RenderNodeBlockDOM ¶ added in v1.7.6
func (*Lute) SetAutoSpace ¶
func (*Lute) SetBlockRef ¶
func (*Lute) SetChineseParagraphBeginningSpace ¶
func (*Lute) SetCodeSyntaxHighlight ¶
func (*Lute) SetCodeSyntaxHighlightDetectLang ¶
func (*Lute) SetCodeSyntaxHighlightInlineStyle ¶
func (*Lute) SetCodeSyntaxHighlightLineNum ¶
func (*Lute) SetCodeSyntaxHighlightStyleName ¶
func (*Lute) SetDataImage ¶ added in v1.7.5
func (*Lute) SetEmojiSite ¶
func (*Lute) SetFileAnnotationRef ¶
func (*Lute) SetFixTermTypo ¶
func (*Lute) SetFootnotes ¶
func (*Lute) SetGFMAutoLink ¶
func (*Lute) SetGFMStrikethrough ¶
func (*Lute) SetGFMTable ¶
func (*Lute) SetGFMTaskListItem ¶
func (*Lute) SetGFMTaskListItemClass ¶
func (*Lute) SetGitConflict ¶
func (*Lute) SetHTMLTag2TextMark ¶ added in v1.7.5
func (*Lute) SetHeadingAnchor ¶
func (*Lute) SetHeadingID ¶
func (*Lute) SetImageLazyLoading ¶
func (*Lute) SetImgPathAllowSpace ¶
func (*Lute) SetIndentCodeBlock ¶
func (*Lute) SetInlineMathAllowDigitAfterOpenMarker ¶
func (*Lute) SetJSRenderers ¶
func (*Lute) SetKramdownBlockIAL ¶
func (*Lute) SetKramdownIAL ¶
func (*Lute) SetKramdownIALIDRenderName ¶
func (*Lute) SetKramdownSpanIAL ¶
func (*Lute) SetLinkBase ¶
func (*Lute) SetLinkPrefix ¶
func (*Lute) SetLinkRef ¶
func (*Lute) SetParagraphBeginningSpace ¶
func (*Lute) SetProtyleMarkNetImg ¶
func (*Lute) SetProtyleWYSIWYG ¶
func (*Lute) SetRenderListStyle ¶
func (*Lute) SetSanitize ¶
SetSanitize 设置为 true 时表示对输出进行 XSS 过滤。 注意:Lute 目前的实现存在一些漏洞,请不要依赖它来防御 XSS 攻击。
func (*Lute) SetSoftBreak2HardBreak ¶
func (*Lute) SetSpellcheck ¶ added in v1.7.5
func (*Lute) SetSuperBlock ¶
func (*Lute) SetTextMark ¶ added in v1.7.5
func (*Lute) SetVditorCodeBlockPreview ¶
func (*Lute) SetVditorHTMLBlockPreview ¶
func (*Lute) SetVditorIR ¶
func (*Lute) SetVditorMathBlockPreview ¶
func (*Lute) SetVditorSV ¶
func (*Lute) SetVditorWYSIWYG ¶
func (*Lute) SetYamlFrontMatter ¶
func (*Lute) SpinBlockDOM ¶
func (*Lute) SpinVditorDOM ¶
SpinVditorDOM 自旋 Vditor DOM,用于所见即所得模式下的编辑。
func (*Lute) SpinVditorIRDOM ¶
SpinVditorIRDOM 自旋 Vditor Instant-Rendering DOM,用于即时渲染模式下的编辑。
func (*Lute) SpinVditorSVDOM ¶
SpinVditorSVDOM 自旋 Vditor Split-View DOM,用于分屏预览模式下的编辑。
func (*Lute) TextBundle ¶
func (lute *Lute) TextBundle(name string, markdown []byte, linkPrefixes []string) (textbundle []byte, originalLinks []string)
TextBundle 将 markdown 文本字节数组进行 TextBundle 处理。
func (*Lute) TextBundleStr ¶
func (lute *Lute) TextBundleStr(name, markdown string, linkPrefixes []string) (textbundle string, originalLinks []string)
TextBundleStr 接受 string 类型的 markdown 后直接调用 TextBundle 进行处理。
func (*Lute) Tree2BlockDOM ¶
func (*Lute) VditorDOM2HTML ¶
VditorDOM2HTML 将 Vditor DOM 转换为 HTML,用于 Vditor.getHTML() 接口。
func (*Lute) VditorDOM2Md ¶
VditorDOM2Md 将 Vditor DOM 转换为 markdown,用于从所见即所得模式切换至源码模式。
func (*Lute) VditorIRDOM2HTML ¶
VditorIRDOM2HTML 将 Vditor Instant-Rendering DOM 转换为 HTML,用于 Vditor.getHTML() 接口。
func (*Lute) VditorIRDOM2Md ¶
VditorIRDOM2Md 将 Vditor Instant-Rendering DOM 转换为 markdown,用于从即时渲染模式切换至源码模式。
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package html implements an HTML5-compliant tokenizer and parser.
|
Package html implements an HTML5-compliant tokenizer and parser. |
atom
Package atom provides integer codes (also known as atoms) for a fixed set of frequently occurring HTML strings: tag names and attribute keys such as "p" and "id".
|
Package atom provides integer codes (also known as atoms) for a fixed set of frequently occurring HTML strings: tag names and attribute keys such as "p" and "id". |