README
¶
一款结构化的 Markdown 引擎,支持 Go 和 JavaScript
千呼万唤始出来 犹抱琵琶半遮面
转轴拨弦三两声 未成曲调先有情
💡 简介
Lute 是一款结构化的 Markdown 引擎,完整实现了最新的 GFM/CommonMark 规范,对中文语境支持更好。
欢迎到 Lute 官方讨论区了解更多。同时也欢迎关注 B3log 开源社区微信公众号 B3log开源
:
📽️ 背景
之前我一直在使用其他 Markdown 引擎,它们或多或少都有些“瑕疵”:
- 对标准规范的支持不一致
- 对“怪异”文本处理非常耗时,甚至挂死
- 对中文支持不够好
Lute 的目标是构建一个结构化的 Markdown 引擎,实现 GFM/CM 规范并对中文提供更好的支持。所谓的“结构化”指的是从输入的 MD 文本构建抽象语法树,通过操作树来进行 HTML 输出、原文格式化等。 实现规范是为了保证 Markdown 渲染不存在二义性,让同一份 Markdown 文本可以在实现规范的 Markdown 引擎处理后得到一样的结果,这一点非常重要。
实现规范的引擎并不多,我想试试看自己能不能写上一个,这也是 Lute 的动机之一。关于如何实现一个 Markdown 引擎,网上众说纷纭:
- 有的人说 Markdown 适合用正则解析,因为文法规则太简单
- 也有的人说 Markdown 可以用编译原理来处理,正则太难维护
我赞同后者,因为正则确实太难维护而且运行效率较低。最重要的原因是符合 GFM/CM 规范的 Markdown 引擎的核心解析算法不可能用正则写出来,因为规范定义的规则实在是太复杂了。
最后,还有一个很重要的动机就是 B3log 开源社区需要一款自己的 Markdown 引擎:
✨ 特性
- 实现最新版 GFM/CM 规范
- 零正则,非常快
- 内置代码块语法高亮
- 对中文语境支持更好
- 术语拼写修正
- Markdown 格式化
- Emoji 解析
- HTML 转换 Markdown
- 自定义渲染函数
- 支持 JavaScript 端使用
🗃 案例
🇨🇳 中文语境优化
- 自动链接识别加强
- 在中西文间自动插入空格
♍ 格式化
格式化功能可将“不整洁”的 Markdown 文本格式化为统一风格,在需要公共编辑的场景下,统一的排版风格能让大家更容易协作。
点此展开格式化示例。
Markdown 原文:
# ATX 标题也有可能需要格式化的 ##
一个简短的段落。
Setext 说实话我不喜欢 Setext 标题
----
0. 有序列表可以从 0 开始
0. 应该自增序号的
1. 对齐对齐对齐
我们再来看看另一个有序列表。
1. 没空行的情况下序号要从 1 开始才能打断段落开始一个新列表
3. 虽然乱序不影响渲染
2. 但是随意写序号容易引起误解
试下贴段代码:
```go
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
```
对了,缩进代码块建议换成围栏代码块:
缩进代码块太隐晦了
也没法指定编程语言,容易导致代码高亮失效
所以建议大家用 ``` 围栏代码块
试下围栏代码块匹配场景:
````markdown
围栏代码块只要开头的 ` 和结束的 ` 数量匹配即可,这样可以实现在围栏代码块中显示围栏代码块:
```
这里只有 3 个 `,所以不会匹配markdown代码块结束
```
下面匹配到就真的结束了。
````
以上块级内容都挤在一坨了,插入合理的空行也很有必要。
但是过多的空行分段也不好啊,用来分段的话一个空行就够了。
接下来让我们试试稍微复杂点的场景,比如列表项包含多个段落的情况:
1. 列表项中的第一段
这里是第二个段落,贴段代码:
```markdown
要成为Markdown程序员并不容易,同理PPT架构师也是。
注意代码块中的中西文间并没有插入空格。
```
这里是最后一段了。
1. 整个有序列表是“松散”的:列表项内容要用 `<p>` 标签
最后,我们试下对 GFM 的格式化支持:
|col1|col2 | col3 |
--- |---------------|--
col1 without left pipe | this is col2 | col3 without right pipe
||need align cell|
**以上就是为什么我们需要Markdown Format,而且是带中西文自动空格的格式化。**
格式化后:
# ATX 标题也有可能需要格式化的
一个简短的段落。
## Setext 说实话我不喜欢 Setext 标题
0. 有序列表可以从 0 开始
1. 应该自增序号的
2. 对齐对齐对齐
我们再来看看另一个有序列表。
1. 没空行的情况下序号要从 1 开始才能打断段落开始一个新列表
2. 虽然乱序不影响渲染
3. 但是随意写序号容易引起误解
试下贴段代码:
```go
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
```
对了,缩进代码块建议换成围栏代码块:
```
缩进代码块太隐晦了
也没法指定编程语言,容易导致代码高亮失效
所以建议大家用 ``` 围栏代码块
```
试下围栏代码块匹配场景:
````markdown
围栏代码块只要开头的 ` 和结束的 ` 数量匹配即可,这样可以实现在围栏代码块中显示围栏代码块:
```
这里只有 3 个 `,所以不会匹配markdown代码块结束
```
下面匹配到就真的结束了。
````
以上块级内容都挤在一坨了,插入合理的空行也很有必要。
但是过多的空行分段也不好啊,用来分段的话一个空行就够了。
接下来让我们试试稍微复杂点的场景,比如列表项包含多个段落的情况:
1. 列表项中的第一段
这里是第二个段落,贴段代码:
```markdown
要成为Markdown程序员并不容易,同理PPT架构师也是。
注意代码块中的中西文间并没有插入空格。
```
这里是最后一段了。
2. 整个有序列表是“松散”的:列表项内容要用 `<p>` 标签
最后,我们试下对 GFM 的格式化支持:
| col1 | col2 | col3 |
| ---------------------- | --------------- | ----------------------- |
| col1 without left pipe | this is col2 | col3 without right pipe |
| | need align cell | |
**以上就是为什么我们需要 Markdown Format,而且是带中西文自动空格的格式化。**
✍️ 术语修正
Markdown 原文:
在github上做开源项目是一件很开心的事情,请不要把Github拼写成`github`哦!
特别是简历中千万不要出现这样的情况:
> 熟练使用JAVA、Javascript、GIT,对android、ios开发有一定了解,熟练使用Mysql、postgresql数据库。
修正后:
在 GitHub 上做开源项目是一件很开心的事情,请不要把 GitHub 拼写成`github`哦!
特别是简历中千万不要出现这样的情况:
> 熟练使用 Java、JavaScript、Git,对 Android、iOS 开发有一定了解,熟练使用 MySQL、PostgreSQL 数据库。
⚡ 性能
💪 健壮性
Lute 承载了链滴上的所有 Markdown 处理,每天处理数百万解析渲染请求,运行表现稳定。
🔒 安全性
Lute 没有实现实现 GFM 中的 Disallowed Raw HTML (extension),因为该扩展还是存在一定漏洞(比如没有处理 <input>
)。
建议通过其他库(比如 bluemonday)来进行 HTML 安全过滤,这样也能更好地适配应用场景。
🛠️ 使用
有三种方式使用 Lute:
- 后端:用 Go 语言的话引入
github.com/88250/lute
包 - 后端:将 Lute 启动为一个 HTTP 服务进程供其他进程调用,具体请参考这里
- 前端:引入 js 目录下的 lute.min.js,支持 Node.js
Go
引入 Lute 库:
go get -u github.com/88250/lute
最小化可工作示例:
package main
import (
"fmt"
"github.com/88250/lute"
)
func main() {
luteEngine := lute.New() // 默认已经启用 GFM 支持以及中文语境优化
html:= luteEngine.MarkdownStr("demo", "**Lute** - A structured markdown engine.")
fmt.Println(html)
// <p><strong>Lute</strong> - A structured Markdown engine.</p>
}
关于代码块语法高亮:
- 默认使用外部样式表,主题为 github.css,可从 chroma-styles 目录下拷贝该样式文件到项目中引入
- 可通过
lutenEngine.SetCodeSyntaxHighlightXXX()
来指定高亮相关参数,比如是否启用内联样式、行号以及主题
JavaScript
简单示例可参考 JavaScript 目录下的 demo,结合前端编辑器的完整用法请参考 Vditor 中的示例。
一些细节:
- lute.js 没有内置语法高亮特性
- lute.js 编译后大小为 ~3.5MB,GZip 压缩后大小 ~500KB
📜 文档
🏘️ 社区
📄 授权
Lute 使用 木兰宽松许可证, 第2版 开源协议。
🙏 鸣谢
Lute 的诞生离不开以下开源项目,在此对这些项目的贡献者们致敬!
- commonmark.js:该项目是 CommonMark 官方参考实现的 JavaScript 版,Lute 参考了其解析器实现部分
- goldmark:另一款用 golang 写的 Markdown 引擎,Lute 参考了其树遍历实现部分
- golang-commonmark:另一款用 golang 写的 Markdown 引擎,Lute 参考了其 URL 编码以及 HTML 转义算法
- Chroma:用 golang 写的语法高亮引擎
- 中文文案排版指北:统一中文文案、排版的相关用法,降低团队成员之间的沟通成本,增强网站气质
- GopherJS:将 Go 代码编译成 JavaScript 代码
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". |