Skip to content

Commit 792634d

Browse files
committed
更新:markdown(GFM) - v2.0.0
1 parent ff83bf4 commit 792634d

File tree

1 file changed

+78
-51
lines changed

1 file changed

+78
-51
lines changed

mtsx/github_markdown.mtsx

Lines changed: 78 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
2-
name: ["github_markdown", ".markdown", ".md", ".mkd", ".mkdn", ".mdtxt", ".mdown"]
2+
name: ["GitHub Flavored Markdown", ".md"]
33
ignoreCase: false
44
colors: [
55
"title", #E06C75, #E06C75
66
"escape" > "strEscape"
7-
"ordered_list" > "number"
8-
"unordered_list" > "number"
9-
"short_code" > "string"
10-
"code_block", #7050E0, #835CBD
7+
"list" > "number"
8+
"footnote", #4493F8, #4493F8
9+
"math_short" > "meta"
10+
"code_short" > "string"
11+
"code_block", #7050E0, #7050E0
1112
"syntax_name", #871094, #A64EAD
12-
"code_content", #BABABA, #BABABA
13+
"code_content", #AA9AB8, #AA9AB8
1314
"quote_note", #2F81F7, #2F81F7
1415
"quote_note_text", #2F81F7, #2F81F7
1516
"quote_tip", #238636, #238636
@@ -22,70 +23,95 @@
2223
"quote_caution_text", #F85149, #F85149
2324
"quote_text", #777, #858F9A
2425
"quote_background", #DDD, #444
25-
"感叹号", #E8BF6A, #E8BF6A
26+
"exclamation_mark", #FF7000, #D2B72D
2627
"url_text", #508090, #58908A
2728
"url_title" > "string"
2829
"url", #508090, #58908A
29-
"括号", #999, #999
30+
"bracket", #999, #999
3031
"split_line", #FFF000, #BBB529
3132
]
3233
// github可以使用html标签,注释后不渲染
3334
comment: {startsWith: "<!--", endsWith: "-->"}
3435

35-
// 暂时不打算适配制表符(因为会有bug/:
36+
// 暂时不打算适配制表符(因为会有bug)
3637
defines: [
3738
// (?m) ^匹配每行开头
38-
// 不使用是因为会导致代码块不渲染,优化暂时搁置
39+
// 但这里使用会导致代码块不渲染
3940
"prefix": /(?:^|\n) */
40-
"title": {match: include("prefix") + /#{1,6} .*/, 0: "title"}
41-
"escape": {match: /\\./, 0: "escape"}
41+
42+
// lineBackground有点bug暂时没法用include
43+
// "quoteBackground": /(?m)^ *>.*/
4244

43-
// 实现了基本渲染,暂时搁置优化匹配
44-
"link": {match: /(!)?(\[)(.*)(\])(\()(.*?)( ".*?")?(\))/, 1: "感叹号" 2: "括号" 3: "url_text" 4: "括号" 5: "括号" 6: "url" 7: "url_title" 8: "括号"}
45-
46-
"setextTitle": {match: /(?m)^.+(?<!^-+|=+)\n^(=+|-+)$/, 0: "title"}
47-
// "setextTitle": {match: /(?m)^\s^(?:.+\n){1,}^( {0,3}|-{3,}|={3,}) {0,}$/, recordAllGroups: true, 0: "title"}
45+
"title": [
46+
{match: /(?m)^ {0,3}#{1,6} .*/, 0: "title"}
47+
// setext 标题
48+
{match: /(?m)^.+(?<!^-+|=+)\n^(=+|-+)$/, 0: "title"}
49+
]
4850

4951
"splitLine": {match: /(?m)^(\s*?$|[-=]*)^ {0,3}(\*{3,}|-{3,}|_{3,}) {0,}$/, 0: "split_line"}
52+
"escape": {match: /\\[!"#$%&'()*+,-.\\\/:;<=>?@\[\]\^_`{|}~]/, 0: "escape"}
53+
54+
// 实现了基本渲染,暂时搁置优化
55+
// 感觉已经没必要再改了……改复杂了不说,逻辑和效果也会变,暂时就这样
56+
"link": {match: /(!)?(\[)(.*)(\])(\()(.*?)( ".*?")?(\))/, 1: "exclamation_mark" 2: "bracket" 3: "url_text" 4: "bracket" 5: "bracket" 6: "url" 7: "url_title" 8: "bracket"}
57+
58+
"all_list": [
59+
{match: include("prefix") + /[1-9][0-9]*\. /}
60+
{match: include("prefix") + /[*+-] /}
61+
]
62+
63+
"list": [
64+
{start: {include: "all_list"}
65+
end: {match: /(?m)$/}
66+
color: "list"
67+
matchEndFirst: true
68+
contains: [
69+
{include: "escape"}
70+
{include: "footnote"}
71+
{include: "link"}
72+
]}
73+
]
74+
75+
// LaTeX
76+
"math": [
77+
{start: {match: /\$/, 0: "math_short"}
78+
end: {match: /(?m)\$|$/, 0: "math_short"}
79+
color: "string"
80+
matchEndFirst: true
81+
contains: {
82+
{match: /\\\$/, 0: "escape"}
83+
}}
84+
]
85+
86+
"quote": [
87+
{match: /(?m)^> *\[(!)(?:(NOTE)|(TIP)|(IMPORTANT)|(WARNING)|(CAUTION))\](?:\n>(.*))+/, recordAllGroups: true,0: "quote_text" 1: "exclamation_mark" 2: "quote_note_text" 3: "quote_tip_text" 4: "quote_important_text" 5: "quote_warning_text" 6: "quote_caution_text" 7: "default"}
88+
{match: /(?m)^ *>.*/, 0: "quote_text"}
89+
]
5090

51-
// 有点bug暂时没法用
52-
// "quoteBackground": include("prefix") + />.*/
91+
"footnote": [
92+
{match: /(?m)^\[\^.+?\]: /, 0: "footnote"}
93+
{match: /\[\^.+?\]/, 0: "footnote"}
94+
]
5395
]
5496

55-
// lineBackground: {match: include("quoteBackground"), color: "quote_background"}
56-
lineBackground: {match: /(?m)^ *>.*/, color: "quote_background"}
57-
97+
// ##################################################################
5898
// 取消注释下行,为分割线添加背景
5999
// lineBackground: {match: /^( {0,3}\*{3,}|-{3,}|_{3,})$/, color: "default"}
100+
// ##################################################################
101+
102+
// lineBackground: {match: include("quoteBackground"), color: "quote_background"}
103+
lineBackground: {match: /(?m)^ *>.*/, color: "quote_background"}
60104

61105
contains: [
106+
// 这样写是为了后续方便调整顺序,以最佳顺序高亮语法,避免bug
62107
{include: "title"}
63-
{include: "setextTitle"}
64108
{include: "link"}
65109
{include: "escape"}
110+
{include: "footnote"}
111+
{include: "math"}
66112
{include: "splitLine"}
67-
{match: include("prefix") + /[1-9][0-9]*\. .*/, 0: "ordered_list"}
68-
{match: include("prefix") + /[*+-] .*/, 0: "unordered_list"}
69-
{match: /> *\[(!)(?:(NOTE)|(TIP)|(IMPORTANT)|(WARNING)|(CAUTION))\](?:\n>(.*))+/, recordAllGroups: true,0: "quote_text" 1: "感叹号" 2: "quote_note_text" 3: "quote_tip_text" 4: "quote_important_text" 5: "quote_warning_text" 6: "quote_caution_text" 7: "default"}
70-
{match: /(?m)^ *>.*/, 0: "quote_text"}
71-
72-
// 已经把链接匹配的优化雏形放这了,等待我的后续更新吧~
73-
// 或者你也可以自行将下方代码补全
74-
// {
75-
// start: {
76-
// start: {match: /\[/}
77-
// end: {match: /\]/}
78-
// }
79-
// end: {
80-
// start: {match: /\(/}
81-
// end: {match: /\)/}
82-
// }
83-
// color: "string"
84-
// matchEndFirst: true //优先匹配结尾
85-
// contains: [
86-
87-
// ]
88-
// }
113+
{include: "list"}
114+
{include: "quote"}
89115

90116
{
91117
start: {match: include("prefix") + /(?i)`{3}([ a-z]*)/, 0: "code_block" 1: "syntax_name"}
@@ -99,12 +125,13 @@
99125
}
100126
{
101127
start: {match: /`/}
102-
end: {match: /`|$/}
103-
color: "short_code"
104-
contains: [
105-
{include: "escape"}
106-
]
128+
end: {match: /(?m)`|$/}
129+
color: "code_short"
130+
// matchEndFirst: true
131+
// contains: [
132+
// 以我当前水平和mt的局限性,只能做到没有`闭合的后面所有字符不渲染,但这个`还是会渲染,有能力的大牛可以自己尝试一下(: 但这又会让后面所有内容全都不渲染……放弃了):
133+
// {match: /(?m)(?<=`).*$/, 0: "default"}
134+
// ]
107135
}
108-
{builtin: #ESCAPED_CHAR#}
109136
]
110137
}

0 commit comments

Comments
 (0)