package main import ( "log" "github.com/88250/lute/parse" "github.com/88250/lute/render" "github.com/jinzhu/copier" ) type LuteParseOptions struct { // GFMTable 设置是否打开“GFM 表”支持。 GFMTable bool `yaml:"GFMTable"` // GFMTaskListItem 设置是否打开“GFM 任务列表项”支持。 GFMTaskListItem bool `yaml:"GFMTaskListItem"` // GFMStrikethrough 设置是否打开“GFM 删除线”支持。 GFMStrikethrough bool `yaml:"GFMStrikethrough"` // GFMAutoLink 设置是否打开“GFM 自动链接”支持。 GFMAutoLink bool `yaml:"GFMAutoLink"` // Footnotes 设置是否打开“脚注”支持。 Footnotes bool `yaml:"Footnotes"` // HeadingID 设置是否打开“自定义标题 ID”支持。 HeadingID bool `yaml:"HeadingID"` // ToC 设置是否打开“目录”支持。 ToC bool `yaml:"ToC"` // Emoji 设置是否对 Emoji 别名替换为原生 Unicode 字符。 Emoji bool `yaml:"Emoji"` // AliasEmoji 存储 ASCII 别名到表情 Unicode 映射。 AliasEmoji map[string]string `yaml:"AliasEmoji"` // EmojiAlias 存储表情 Unicode 到 ASCII 别名映射。 EmojiAlias map[string]string `yaml:"EmojiAlias"` // EmojiSite 设置图片 Emoji URL 的路径前缀。 EmojiSite string `yaml:"EmojiSite"` // Vditor 所见即所得支持。 VditorWYSIWYG bool `yaml:"VditorWYSIWYG"` // Vditor 即时渲染支持。 VditorIR bool `yaml:"VditorIR"` // Vditor 分屏预览支持。 VditorSV bool `yaml:"VditorSV"` // Protyle 所见即所得支持。 ProtyleWYSIWYG bool `yaml:"ProtyleWYSIWYG"` // InlineMathAllowDigitAfterOpenMarker 设置内联数学公式是否允许起始 $ 后紧跟数字 https://github.com/b3log/lute/issues/38 InlineMathAllowDigitAfterOpenMarker bool `yaml:"InlineMathAllowDigitAfterOpenMarker"` // Setext 设置是否解析 Setext 标题 https://github.com/88250/lute/issues/50 Setext bool `yaml:"Setext"` // YamlFrontMatter 设置是否开启 YAML Front Matter 支持。 YamlFrontMatter bool `yaml:"YamlFrontMatter"` // BlockRef 设置是否开启内容块引用支持。 BlockRef bool `yaml:"BlockRef"` // FileAnnotationRef 设置是否开启文件注解引用支持。 FileAnnotationRef bool `yaml:"FileAnnotationRef"` // Mark 设置是否打开 ==标记== 支持。 Mark bool `yaml:"Mark"` // KramdownBlockIAL 设置是否打开 kramdown 块级内联属性列表支持。 https://kramdown.gettalong.org/syntax.html#inline-attribute-lists KramdownBlockIAL bool `yaml:"KramdownBlockIAL"` // KramdownSpanIAL 设置是否打开 kramdown 行级内联属性列表支持。 KramdownSpanIAL bool `yaml:"KramdownSpanIAL"` // Tag 设置是否开启 #标签# 支持。 Tag bool `yaml:"Tag"` // ImgPathAllowSpace 设置是否支持图片路径带空格。 ImgPathAllowSpace bool `yaml:"ImgPathAllowSpace"` // SuperBlock 设置是否支持超级块。 https://github.com/88250/lute/issues/111 SuperBlock bool `yaml:"SuperBlock"` // Sup 设置是否打开 ^上标^ 支持。 Sup bool `yaml:"Sup"` // Sub 设置是否打开 ~下标~ 支持。 Sub bool `yaml:"Sub"` // GitConflict 设置是否打开 Git 冲突标记支持。 GitConflict bool `yaml:"GitConflict"` // LinkRef 设置是否打开“链接引用”支持。 LinkRef bool `yaml:"LinkRef"` // IndentCodeBlock 设置是否打开“缩进代码块”支持。 IndentCodeBlock bool `yaml:"IndentCodeBlock"` // ParagraphBeginningSpace 设置是否打开“段首空格”支持。 ParagraphBeginningSpace bool `yaml:"ParagraphBeginningSpace"` // DataImage 设置是否打开 ![foo](data:image...) 形式的图片支持。 DataImage bool `yaml:"DataImage"` // TextMark 设置是否打开通用行级节点解析支持。 TextMark bool `yaml:"TextMark"` // HTMLTag2TextMark 设置是否打开 HTML 某些标签解析为 TextMark 节点支持。目前仅支持 标签。 // 这个开关主要用于兼容 Markdown 输入 API 上 https://github.com/siyuan-note/siyuan/issues/6039 // 不用于 Protyle 自旋过程 https://github.com/siyuan-note/siyuan/issues/5877 HTMLTag2TextMark bool `yaml:"HTMLTag2TextMark"` // 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 `yaml:"Spin"` } type LuteRenderOptions struct { // SoftBreak2HardBreak 设置是否将软换行(\n)渲染为硬换行(
)。 SoftBreak2HardBreak bool `yaml:"SoftBreak2HardBreak"` // AutoSpace 设置是否对普通文本中的中西文间自动插入空格。 // https://github.com/sparanoid/chinese-copywriting-guidelines AutoSpace bool `yaml:"AutoSpace"` // RenderListStyle 设置在渲染 OL、UL 时是否添加 data-style 属性 https://github.com/88250/lute/issues/48 RenderListStyle bool `yaml:"RenderListStyle"` // CodeSyntaxHighlight 设置是否对代码块进行语法高亮。 CodeSyntaxHighlight bool `yaml:"CodeSyntaxHighlight"` // CodeSyntaxHighlightDetectLang bool CodeSyntaxHighlightDetectLang bool `yaml:"CodeSyntaxHighlightDetectLang"` // CodeSyntaxHighlightInlineStyle 设置语法高亮是否为内联样式,默认不内联。 CodeSyntaxHighlightInlineStyle bool `yaml:"CodeSyntaxHighlightInlineStyle"` // CodeSyntaxHightLineNum 设置语法高亮是否显示行号,默认不显示。 CodeSyntaxHighlightLineNum bool `yaml:"CodeSyntaxHighlightLineNum"` // CodeSyntaxHighlightStyleName 指定语法高亮样式名,默认为 "github"。 CodeSyntaxHighlightStyleName string `yaml:"CodeSyntaxHighlightStyleName"` // Vditor 所见即所得支持。 VditorWYSIWYG bool `yaml:"VditorWYSIWYG"` // Vditor 即时渲染支持。 VditorIR bool `yaml:"VditorIR"` // Vditor 分屏预览支持。 VditorSV bool `yaml:"VditorSV"` // Protyle 所见即所得支持。 ProtyleWYSIWYG bool `yaml:"ProtyleWYSIWYG"` // KramdownBlockIAL 设置是否打开 kramdown 块级内联属性列表支持。 https://kramdown.gettalong.org/syntax.html#inline-attribute-lists KramdownBlockIAL bool `yaml:"KramdownBlockIAL"` // KramdownSpanIAL 设置是否打开 kramdown 行级内联属性列表支持。 KramdownSpanIAL bool `yaml:"KramdownSpanIAL"` // SuperBlock 设置是否支持超级块。 https://github.com/88250/lute/issues/111 SuperBlock bool `yaml:"SuperBlock"` // ImageLazyLoading 设置图片懒加载时使用的图片路径,配置该字段后将启用图片懒加载。 // 图片 src 的值会复制给新属性 data-src,然后使用该参数值作为 src 的值 https://github.com/88250/lute/issues/55 ImageLazyLoading string `yaml:"ImageLazyLoading"` // ChineseParagraphBeginningSpace 设置是否使用传统中文排版“段落开头空两格”。 ChineseParagraphBeginningSpace bool `yaml:"ChineseParagraphBeginningSpace"` // Sanitize 设置是否启用 XSS 安全过滤 https://github.com/88250/lute/issues/51 // 注意:Lute 目前的实现存在一些漏洞,请不要依赖它来防御 XSS 攻击。 Sanitize bool `yaml:"Sanitize"` // FixTermTypo 设置是否对普通文本中出现的术语进行修正。 // https://github.com/sparanoid/chinese-copywriting-guidelines // 注意:开启术语修正的话会默认在中西文之间插入空格。 FixTermTypo bool `yaml:"FixTermTypo"` // Terms 将传入的 terms 合并覆盖到已有的 Terms 字典。 Terms map[string]string `yaml:"Terms"` // ToC 设置是否打开“目录”支持。 ToC bool `yaml:"ToC"` // HeadingID 设置是否打开“自定义标题 ID”支持。 HeadingID bool `yaml:"HeadingID"` // KramdownIALIDRenderName 设置 kramdown 内联属性列表中出现 id 属性时渲染 id 属性用的 name(key) 名称,默认为 "id"。 // 仅在 HTML 渲染器 HtmlRenderer 中支持。 KramdownIALIDRenderName string `yaml:"KramdownIALIDRenderName"` // HeadingAnchor 设置是否对标题生成链接锚点。 HeadingAnchor bool `yaml:"HeadingAnchor"` // GFMTaskListItemClass 作为 GFM 任务列表项类名,默认为 "vditor-task"。 GFMTaskListItemClass string `yaml:"GFMTaskListItemClass"` // VditorCodeBlockPreview 设置 Vditor 代码块是否需要渲染预览部分 VditorCodeBlockPreview bool `yaml:"VditorCodeBlockPreview"` // VditorMathBlockPreview 设置 Vditor 数学公式块是否需要渲染预览部分 VditorMathBlockPreview bool `yaml:"VditorMathBlockPreview"` // VditorHTMLBlockPreview 设置 Vditor HTML 块是否需要渲染预览部分 VditorHTMLBlockPreview bool `yaml:"VditorHTMLBlockPreview"` // LinkBase 设置链接、图片、脚注的基础路径。如果用户在链接或者图片地址中使用相对路径(没有协议前缀且不以 / 开头)并且 LinkBase 不为空则会用该值作为前缀。 // 比如 LinkBase 设置为 http://domain.com/,对于 ![foo](bar.png) 则渲染为 foo LinkBase string `yaml:"LinkBase"` // LinkPrefix 设置连接、图片的路径前缀。一旦设置该值,链接渲染将强制添加该值作为链接前缀,这有别于 LinkBase。 // 比如 LinkPrefix 设置为 http://domain.com,对于使用绝对路径的 ![foo](/local/path/bar.png) 则渲染为 foo; // 在 LinkBase 和 LinkPrefix 同时设置的情况下,会先处理 LinkBase 逻辑,最后再在 LinkBase 处理结果上加上 LinkPrefix。 LinkPrefix string `yaml:"LinkPrefix"` // NodeIndexStart 用于设置块级节点编号起始值。 NodeIndexStart int `yaml:"NodeIndexStart"` // ProtyleContenteditable 设置 Protyle 渲染时标签中的 contenteditable 属性。 ProtyleContenteditable bool `yaml:"ProtyleContenteditable"` // KeepParagraphBeginningSpace 设置是否保留段首空格 KeepParagraphBeginningSpace bool `yaml:"KeepParagraphBeginningSpace"` // NetImgMarker 设置 Protyle 是否标记网络图片 ProtyleMarkNetImg bool `yaml:"ProtyleMarkNetImg"` // Spellcheck 设置是否启用拼写检查 Spellcheck bool `yaml:"Spellcheck"` } func (p LuteParseOptions)toLuteParseOptions() *parse.Options { var output = parse.Options{} err := copier.Copy(&output, &p) if err != nil { log.Println(err) } return &output } func toPrivateParseOptions(P *parse.Options) LuteParseOptions { var output = LuteParseOptions{} err := copier.Copy(&output, P) if err != nil { log.Println(err) } return output } func (r LuteRenderOptions)toLuteRenderOptions() *render.Options { var output = render.Options{} err := copier.Copy(&output, &r) if err != nil { log.Println(err) } return &output } func toPrivateRenderOptions(R *render.Options) LuteRenderOptions { var output = LuteRenderOptions{} err := copier.Copy(&output, R) if err != nil { log.Println(err) } return output }