Skip to content

Commit

Permalink
🎨 Supports disabling Markdown * and _ syntax input siyuan-note/si…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 13, 2024
1 parent 019dc0c commit dd8f3f4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions 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.

8 changes: 8 additions & 0 deletions lute.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,14 @@ func (lute *Lute) SetSub(b bool) {
lute.ParseOptions.Sub = b
}

func (lute *Lute) SetInlineAsterisk(b bool) {
lute.ParseOptions.InlineAsterisk = b
}

func (lute *Lute) SetInlineUnderscore(b bool) {
lute.ParseOptions.InlineUnderscore = b
}

func (lute *Lute) SetGitConflict(b bool) {
lute.ParseOptions.GitConflict = b
}
Expand Down
12 changes: 12 additions & 0 deletions parse/delimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ func (t *Tree) processEmphasis(stackBottom *delimiter, ctx *InlineContext) {
}
}

if !t.Context.ParseOption.InlineAsterisk {
if lex.ItemAsterisk == closercc {
break
}
}

if !t.Context.ParseOption.InlineUnderscore {
if lex.ItemUnderscore == closercc {
break
}
}

if t.Context.ParseOption.Mark {
if lex.ItemEqual == closercc && opener.num != closer.num {
break
Expand Down
6 changes: 6 additions & 0 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ type Options struct {
Sup bool
// Sub 设置是否打开 ~下标~ 支持。
Sub bool
// InlineAsterisk 设置是否打开行级 * 语法支持(*foo* 和 **foo**)。
InlineAsterisk bool
// InlineUnderscore 设置是否打开行级 _ 语法支持(_foo_ 和 __foo__)。
InlineUnderscore bool
// GitConflict 设置是否打开 Git 冲突标记支持。
GitConflict bool
// LinkRef 设置是否打开“链接引用”支持。
Expand Down Expand Up @@ -433,6 +437,8 @@ func NewOptions() *Options {
BlockRef: false,
FileAnnotationRef: false,
Mark: false,
InlineAsterisk: true,
InlineUnderscore: true,
KramdownBlockIAL: false,
HeadingID: true,
LinkRef: true,
Expand Down
1 change: 1 addition & 0 deletions test/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var parseTests = []parseTest{
{"spec483", "[link]()\n", "<p><a href=\"\">link</a></p>\n"},
{"spec479", "**a<http://foo.bar/?q=**>\n", "<p>**a<a href=\"http://foo.bar/?q=**\">http://foo.bar/?q=**</a></p>\n"},
{"spec416", "foo******bar*********baz\n", "<p>foo<strong><strong><strong>bar</strong></strong></strong>***baz</p>\n"},
{"spec408", "__foo_ bar_\n", "<p><em><em>foo</em> bar</em></p>\n"},
{"spec403", "*foo [bar](/url)*\n", "<p><em>foo <a href=\"/url\">bar</a></em></p>\n"},
{"spec353", "* a *\n", "<p>* a *</p>\n"},
{"spec352", "a*\"foo\"*\n", "<p>a*&quot;foo&quot;*</p>\n"},
Expand Down

0 comments on commit dd8f3f4

Please sign in to comment.