Skip to content

Commit

Permalink
✨ 支持 ==mark== 高亮语法 #84
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Aug 17, 2020
1 parent f744e4a commit a5b6493
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
27 changes: 21 additions & 6 deletions parse/delimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
package parse

import (
"unicode"
"unicode/utf8"

"github.com/88250/lute/ast"
"github.com/88250/lute/lex"
"github.com/88250/lute/util"
"unicode"
"unicode/utf8"
)

// delimiter 描述了强调、链接和图片解析过程中用到的分隔符([, ![, *, _, ~)相关信息。
Expand Down Expand Up @@ -122,10 +123,24 @@ func (t *Tree) processEmphasis(stackBottom *delimiter, ctx *InlineContext) {
openerInl = opener.node
closerInl = closer.node

if ((t.Context.Option.GFMStrikethrough && lex.ItemTilde == closercc) ||
t.Context.Option.Mark && lex.ItemEqual == closercc) &&
opener.num != closer.num {
break
if t.Context.Option.GFMStrikethrough {
if lex.ItemTilde == closercc && opener.num != closer.num {
break
}
} else {
if lex.ItemTilde == closercc {
break
}
}

if t.Context.Option.Mark {
if lex.ItemEqual == closercc && (2 != opener.num || (opener.num != closer.num)) {
break
}
} else {
if lex.ItemEqual == closercc {
break
}
}

// remove used delimiters from stack elts and inlines
Expand Down
23 changes: 22 additions & 1 deletion test/mark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
package test

import (
"github.com/88250/lute"
"testing"

"github.com/88250/lute"
)

var markTests = []parseTest{

{"4", "=foo=\n", "<p>=foo=</p>\n"},
{"3", "==**foo==**\n", "<p><mark>**foo</mark>**</p>\n"},
{"2", "**==foo==**\n", "<p><strong><mark>foo</mark></strong></p>\n"},
{"1", "==**foo**==\n", "<p><mark><strong>foo</strong></mark></p>\n"},
Expand All @@ -34,3 +36,22 @@ func TestMark(t *testing.T) {
}
}
}

var markDisableTests = []parseTest{

{"2", "*=foo*=\n", "<p><em>=foo</em>=</p>\n"},
{"1", "=foo=\n", "<p>=foo=</p>\n"},
{"0", "==foo==\n", "<p>==foo==</p>\n"},
}

func TestMarkDisable(t *testing.T) {
luteEngine := lute.New()
luteEngine.Mark = false

for _, test := range markDisableTests {
html := luteEngine.MarkdownStr(test.name, test.from)
if test.to != html {
t.Fatalf("test case [%s] failed\nexpected\n\t%q\ngot\n\t%q\noriginal markdown text\n\t%q", test.name, test.to, html, test.from)
}
}
}

0 comments on commit a5b6493

Please sign in to comment.