Skip to content

Commit

Permalink
🎨 Supports disabling Markdown syntax input for some inline elements s…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Apr 26, 2024
1 parent 4cbc4ae commit 2753763
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion javascript/lute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/lute.min.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions parse/delimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,19 @@ func (t *Tree) scanDelims(ctx *InlineContext) *delimiter {
canOpen = isLeftFlanking
canClose = isRightFlanking
}
} else if t.Context.ParseOption.GFMStrikethrough && lex.ItemTilde == token {
if 1 == delimitersCount {
if !t.Context.ParseOption.GFMStrikethrough1 {
canOpen = false
canClose = false
} else {
canOpen = isLeftFlanking
canClose = isRightFlanking
}
} else {
canOpen = isLeftFlanking
canClose = isRightFlanking
}
} else {
canOpen = isLeftFlanking
canClose = isRightFlanking
Expand Down
37 changes: 37 additions & 0 deletions test/spin_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,40 @@ func TestSpinBlockDOM(t *testing.T) {
}
ast.Testing = false
}

var spinBlockDOMStrikethrough1DisabledTests = []parseTest{
{"0", "<div data-node-id=\"20240426104632-617yt47\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240426112128\"><div contenteditable=\"true\" spellcheck=\"false\">~foo~<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">​</div></div>", "<div data-node-id=\"20240426104632-617yt47\" data-node-index=\"1\" data-type=\"NodeParagraph\" class=\"p\" updated=\"20240426112128\"><div contenteditable=\"true\" spellcheck=\"false\">~foo~<wbr></div><div class=\"protyle-attr\" contenteditable=\"false\">\u200b</div></div>"},
}

func TestSpinBlockDOMStrikethrough1Disabled(t *testing.T) {
luteEngine := lute.New()
luteEngine.SetProtyleWYSIWYG(true)
luteEngine.ParseOptions.Mark = true
luteEngine.ParseOptions.BlockRef = true
luteEngine.SetKramdownIAL(true)
luteEngine.SetSuperBlock(true)
luteEngine.SetTag(true)
luteEngine.SetGFMStrikethrough(true)
luteEngine.SetGFMStrikethrough1(false)
luteEngine.SetSub(false)
luteEngine.SetSup(true)
luteEngine.SetGitConflict(true)
luteEngine.SetIndentCodeBlock(false)
luteEngine.SetEmojiSite("http://127.0.0.1:6806/stage/protyle/images/emoji")
luteEngine.SetAutoSpace(true)
luteEngine.SetParagraphBeginningSpace(true)
luteEngine.SetFileAnnotationRef(true)
luteEngine.SetInlineMathAllowDigitAfterOpenMarker(true)
luteEngine.SetTextMark(true)
luteEngine.SetSpin(true)

ast.Testing = true
for _, test := range spinBlockDOMStrikethrough1DisabledTests {
html := luteEngine.SpinBlockDOM(test.from)

if test.to != html {
t.Fatalf("test case [%s] failed\nexpected\n\t%q\ngot\n\t%q\noriginal html\n\t%q", test.name, test.to, html, test.from)
}
}
ast.Testing = false
}

0 comments on commit 2753763

Please sign in to comment.