Skip to content

Commit

Permalink
🐛 # 1. foo ref as anchor text template will be rendered to foo si…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Apr 6, 2021
1 parent 16184d2 commit d45ac02
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
26 changes: 26 additions & 0 deletions test/m2v_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,29 @@ func TestMd2VditorIRBlockDOM(t *testing.T) {
}
ast.Testing = false
}

var inlineMd2VditorIRBlockDOMTests = []parseTest{

{"0", "1. foo", "<p data-block=\"0\" data-node-id=\"20060102150405-1a2b3c4\" data-type=\"p\">1. foo</p>"},
}

func TestInlineMd2VditorIRBlockDOM(t *testing.T) {
luteEngine := lute.New()
luteEngine.SetVditorIR(true)
luteEngine.SetToC(true)
luteEngine.ParseOptions.BlockRef = true
luteEngine.ParseOptions.KramdownBlockIAL = true
luteEngine.RenderOptions.KramdownBlockIAL = true
luteEngine.ParseOptions.Tag = true
luteEngine.ParseOptions.SuperBlock = true
luteEngine.ParseOptions.GitConflict = true

ast.Testing = true
for _, test := range inlineMd2VditorIRBlockDOMTests {
result := luteEngine.InlineMd2VditorIRBlockDOM(test.from)
if test.to != result {
t.Fatalf("test case [%s] failed\nexpected\n\t%q\ngot\n\t%q\noriginal html\n\t%q", test.name, test.to, result, test.from)
}
}
ast.Testing = false
}
22 changes: 17 additions & 5 deletions vditor_ir_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/88250/lute/util"
)

// SpinVditorIRBlockDOM 自旋 Vditor Instant-Rendering Block DOM,用于即时渲染块模式下的编辑
// SpinVditorIRBlockDOM 自旋 Vditor Instant-Rendering Block DOM。
func (lute *Lute) SpinVditorIRBlockDOM(ivHTML string) (ovHTML string) {
// 替换插入符
ivHTML = strings.ReplaceAll(ivHTML, "<wbr>", util.Caret)
Expand All @@ -38,7 +38,7 @@ func (lute *Lute) SpinVditorIRBlockDOM(ivHTML string) (ovHTML string) {
return
}

// HTML2VditorIRBlockDOM 将 HTML 转换为 Vditor Instant-Rendering Block DOM,用于即时渲染块模式下粘贴
// HTML2VditorIRBlockDOM 将 HTML 转换为 Vditor Instant-Rendering Block DOM。
func (lute *Lute) HTML2VditorIRBlockDOM(sHTML string) (vHTML string) {
//fmt.Println(sHTML)
markdown, err := lute.HTML2Markdown(sHTML)
Expand All @@ -64,7 +64,7 @@ func (lute *Lute) VditorIRBlockDOM2HTML(vhtml string) (sHTML string) {
return
}

// Md2VditorIRBlockDOM 将 markdown 转换为 Vditor Instant-Rendering Block DOM,用于从源码模式切换至即时渲染块模式
// Md2VditorIRBlockDOM 将 markdown 转换为 Vditor Instant-Rendering Block DOM。
func (lute *Lute) Md2VditorIRBlockDOM(markdown string) (vHTML string) {
//fmt.Println(markdown)
tree := parse.Parse("", []byte(markdown), lute.ParseOptions)
Expand All @@ -77,7 +77,19 @@ func (lute *Lute) Md2VditorIRBlockDOM(markdown string) (vHTML string) {
return
}

// VditorIRBlockDOM2Md 将 Vditor Instant-Rendering DOM 转换为 markdown,用于从即时渲染块模式切换至源码模式。
// InlineMd2VditorIRBlockDOM 将 markdown 以行级方式转换为 Vditor Instant-Rendering Block DOM。
func (lute *Lute) InlineMd2VditorIRBlockDOM(markdown string) (vHTML string) {
tree := parse.Inline("", []byte(markdown), lute.ParseOptions)
renderer := render.NewVditorIRBlockRenderer(tree, lute.RenderOptions)
for nodeType, rendererFunc := range lute.Md2VditorIRBlockDOMRendererFuncs {
renderer.ExtRendererFuncs[nodeType] = rendererFunc
}
output := renderer.Render()
vHTML = string(output)
return
}

// VditorIRBlockDOM2Md 将 Vditor Instant-Rendering DOM 转换为 markdown。
func (lute *Lute) VditorIRBlockDOM2Md(htmlStr string) (markdown string) {
//fmt.Println(htmlStr)
htmlStr = strings.ReplaceAll(htmlStr, parse.Zwsp, "")
Expand All @@ -86,7 +98,7 @@ func (lute *Lute) VditorIRBlockDOM2Md(htmlStr string) (markdown string) {
return
}

// VditorIRBlockDOM2StdMd 将 Vditor Instant-Rendering DOM 转换为标准 markdown,用于复制剪切
// VditorIRBlockDOM2StdMd 将 Vditor Instant-Rendering DOM 转换为标准 markdown。
func (lute *Lute) VditorIRBlockDOM2StdMd(htmlStr string) (markdown string) {
htmlStr = strings.ReplaceAll(htmlStr, parse.Zwsp, "")

Expand Down

0 comments on commit d45ac02

Please sign in to comment.