Skip to content

Commit

Permalink
🎨 Vditor 支持 支持类似 Typora 的及时渲染模式(保留 Markdown 标记符) Vanessa219/vditor#27
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Mar 11, 2020
1 parent b695991 commit dd4b26b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vditorir.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
// SpinVditorIRDOM 自旋 Vditor Instant-Rendering DOM,用于及时渲染模式下的编辑。
func (lute *Lute) SpinVditorIRDOM(ivHTML string) (ovHTML string) {
lute.VditorIR = true
lute.VditorWYSIWYG = true

// 替换插入符
ivHTML = strings.ReplaceAll(ivHTML, "<wbr>", parse.Caret)
Expand All @@ -44,6 +45,7 @@ func (lute *Lute) SpinVditorIRDOM(ivHTML string) (ovHTML string) {
// HTML2VditorIRDOM 将 HTML 转换为 Vditor Instant-Rendering DOM,用于及时渲染模式下粘贴。
func (lute *Lute) HTML2VditorIRDOM(sHTML string) (vHTML string) {
lute.VditorIR = true
lute.VditorWYSIWYG = true

markdown, err := lute.HTML2Markdown(sHTML)
if nil != err {
Expand All @@ -67,6 +69,7 @@ func (lute *Lute) HTML2VditorIRDOM(sHTML string) (vHTML string) {
// VditorIRDOM2HTML 将 Vditor Instant-Rendering DOM 转换为 HTML,用于 Vditor.getHTML() 接口。
func (lute *Lute) VditorIRDOM2HTML(vhtml string) (sHTML string) {
lute.VditorIR = true
lute.VditorWYSIWYG = true

markdown := lute.vditorIRDOM2Md(vhtml)
sHTML = lute.Md2HTML(markdown)
Expand All @@ -76,6 +79,7 @@ func (lute *Lute) VditorIRDOM2HTML(vhtml string) (sHTML string) {
// Md2VditorIRDOM 将 markdown 转换为 Vditor Instant-Rendering DOM,用于从源码模式切换至所见即所得模式。
func (lute *Lute) Md2VditorIRDOM(markdown string) (vHTML string) {
lute.VditorIR = true
lute.VditorWYSIWYG = true

tree := parse.Parse("", []byte(markdown), lute.Options)
renderer := render.NewVditorRenderer(tree)
Expand All @@ -90,6 +94,7 @@ func (lute *Lute) Md2VditorIRDOM(markdown string) (vHTML string) {
// VditorIRDOM2Md 将 Vditor Instant-Rendering DOM 转换为 markdown,用于从所见即所得模式切换至源码模式。
func (lute *Lute) VditorIRDOM2Md(htmlStr string) (markdown string) {
lute.VditorIR = true
lute.VditorWYSIWYG = true

htmlStr = strings.ReplaceAll(htmlStr, parse.Zwsp, "")
markdown = lute.vditorIRDOM2Md(htmlStr)
Expand Down

0 comments on commit dd4b26b

Please sign in to comment.