@@ -18,6 +18,50 @@ import (
18
18
"github.com/88250/lute"
19
19
)
20
20
21
+ func TestCodeSyntaxHighlightDetectLang (t * testing.T ) {
22
+ // 围栏代码块自动探测语言 https://github.com/88250/lute/issues/22
23
+
24
+ luteEngine := lute .New ()
25
+ luteEngine .SetCodeSyntaxHighlightDetectLang (true )
26
+ for _ , test := range issue22Tests {
27
+ html := luteEngine .MarkdownStr (test .name , test .from )
28
+ if test .to != html {
29
+ t .Fatalf ("test case [%s] failed\n expected\n \t %q\n got\n \t %q\n original markdown text\n \t %q" , test .name , test .to , html , test .from )
30
+ }
31
+ }
32
+ }
33
+
34
+ var issue22Tests = []parseTest {
35
+ {"0" , issue22Case0 [0 ], issue22Case0 [1 ]},
36
+ }
37
+
38
+ var issue22Case0 = []string {
39
+ "```" + `
40
+ package lute
41
+
42
+ func test() {
43
+ return
44
+ }
45
+ ` + "```" ,
46
+ "<pre><code class=\" language-go highlight-chroma\" ><span class=\" highlight-line\" ><span class=\" highlight-cl\" ><span class=\" highlight-kn\" >package</span> <span class=\" highlight-nx\" >lute</span>\n </span></span><span class=\" highlight-line\" ><span class=\" highlight-cl\" >\n </span></span><span class=\" highlight-line\" ><span class=\" highlight-cl\" ><span class=\" highlight-kd\" >func</span> <span class=\" highlight-nf\" >test</span><span class=\" highlight-p\" >()</span> <span class=\" highlight-p\" >{</span>\n </span></span><span class=\" highlight-line\" ><span class=\" highlight-cl\" >\t <span class=\" highlight-k\" >return</span>\n </span></span><span class=\" highlight-line\" ><span class=\" highlight-cl\" ><span class=\" highlight-p\" >}</span>\n </span></span></code></pre>\n " ,
47
+ }
48
+
49
+ func TestCodeSyntaxHighlightDetectLang1 (t * testing.T ) {
50
+ luteEngine := lute .New ()
51
+ luteEngine .SetCodeSyntaxHighlight (false )
52
+ luteEngine .SetCodeSyntaxHighlightDetectLang (true )
53
+ for _ , test := range codeSyntaxHighlightDetectLang1Tests {
54
+ html := luteEngine .MarkdownStr (test .name , test .from )
55
+ if test .to != html {
56
+ t .Fatalf ("test case [%s] failed\n expected\n \t %q\n got\n \t %q\n original markdown text\n \t %q" , test .name , test .to , html , test .from )
57
+ }
58
+ }
59
+ }
60
+
61
+ var codeSyntaxHighlightDetectLang1Tests = []parseTest {
62
+ {"0" , "```\n mysql> SELECT * FROM `test_table`;\n ```\n " , "<pre><code class=\" language-mysql\" >mysql> SELECT * FROM `test_table`;\n </code></pre>\n " },
63
+ }
64
+
21
65
func TestCodeSyntaxHighlightIssue17 (t * testing.T ) {
22
66
// 语法高亮支持内联样式 https://github.com/b3log/lute/issues/17
23
67
0 commit comments