cherry-muse 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +162 -0
- package/README.md +139 -0
- package/dist/addons/cherry-code-block-card-plugin.js +1 -0
- package/dist/addons/cherry-code-block-echarts-plugin.js +1 -0
- package/dist/addons/cherry-code-block-mermaid-plugin.js +1 -0
- package/dist/cherry-markdown.core.common.js +1 -0
- package/dist/cherry-markdown.core.js +1 -0
- package/dist/cherry-markdown.css +4089 -0
- package/dist/cherry-markdown.engine.core.common.js +1 -0
- package/dist/cherry-markdown.engine.core.esm.js +1 -0
- package/dist/cherry-markdown.engine.core.js +1 -0
- package/dist/cherry-markdown.esm.js +1 -0
- package/dist/cherry-markdown.js +70837 -0
- package/dist/cherry-markdown.js.map +1 -0
- package/dist/cherry-markdown.min.css +1 -0
- package/dist/cherry-markdown.min.js +1 -0
- package/dist/stats.html +4838 -0
- package/examples/scripts/pinyin/README.md +53 -0
- package/package.json +167 -0
- package/src/Cherry.config.js +411 -0
- package/src/Cherry.js +788 -0
- package/src/CherryStatic.js +70 -0
- package/src/Editor.js +746 -0
- package/src/Engine.js +334 -0
- package/src/Event.js +74 -0
- package/src/Factory.js +180 -0
- package/src/Logger.js +31 -0
- package/src/Previewer.js +1147 -0
- package/src/Sanitizer.js +4 -0
- package/src/Sanitizer.node.js +7 -0
- package/src/Stats.js +101 -0
- package/src/Theme.js +46 -0
- package/src/UrlCache.js +98 -0
- package/src/addons/cherry-code-block-card-plugin.js +213 -0
- package/src/addons/cherry-code-block-echarts-plugin.js +161 -0
- package/src/addons/cherry-code-block-mermaid-plugin.js +118 -0
- package/src/core/HookCenter.js +303 -0
- package/src/core/HooksConfig.js +106 -0
- package/src/core/ParagraphBase.js +314 -0
- package/src/core/SentenceBase.js +65 -0
- package/src/core/SyntaxBase.js +197 -0
- package/src/core/hooks/AutoLink.js +251 -0
- package/src/core/hooks/BackgroundColor.js +46 -0
- package/src/core/hooks/Badge.js +100 -0
- package/src/core/hooks/Blockquote.js +113 -0
- package/src/core/hooks/Br.js +85 -0
- package/src/core/hooks/CodeBlock.js +876 -0
- package/src/core/hooks/Color.js +78 -0
- package/src/core/hooks/CommentReference.js +96 -0
- package/src/core/hooks/Detail.js +138 -0
- package/src/core/hooks/Emoji.config.js +9388 -0
- package/src/core/hooks/Emoji.js +223 -0
- package/src/core/hooks/Emphasis.js +113 -0
- package/src/core/hooks/Footnote.js +125 -0
- package/src/core/hooks/FrontMatter.js +52 -0
- package/src/core/hooks/FrontMatterVars.js +82 -0
- package/src/core/hooks/Header.js +229 -0
- package/src/core/hooks/HighLight.js +37 -0
- package/src/core/hooks/Hr.js +52 -0
- package/src/core/hooks/HtmlBlock.js +159 -0
- package/src/core/hooks/Iframe.js +80 -0
- package/src/core/hooks/Image.js +276 -0
- package/src/core/hooks/InlineCode.js +45 -0
- package/src/core/hooks/InlineMath.js +142 -0
- package/src/core/hooks/Link.js +169 -0
- package/src/core/hooks/List.js +260 -0
- package/src/core/hooks/Mark.js +55 -0
- package/src/core/hooks/MathBlock.js +97 -0
- package/src/core/hooks/Panel.js +170 -0
- package/src/core/hooks/Paragraph.js +84 -0
- package/src/core/hooks/Ruby.js +34 -0
- package/src/core/hooks/Size.js +84 -0
- package/src/core/hooks/Strikethrough.js +54 -0
- package/src/core/hooks/Sub.js +47 -0
- package/src/core/hooks/SuggestList.js +317 -0
- package/src/core/hooks/Suggester.js +759 -0
- package/src/core/hooks/Sup.js +47 -0
- package/src/core/hooks/Table.js +315 -0
- package/src/core/hooks/Toc.js +290 -0
- package/src/core/hooks/Transfer.js +47 -0
- package/src/core/hooks/Underline.js +37 -0
- package/src/index.core.js +29 -0
- package/src/index.engine.core.js +62 -0
- package/src/index.engine.js +30 -0
- package/src/index.js +28 -0
- package/src/locales/index.js +21 -0
- package/src/locales/zh_CN.js +170 -0
- package/src/sass/cherry.scss +122 -0
- package/src/sass/components/bubble.scss +122 -0
- package/src/sass/components/codemirror.scss +628 -0
- package/src/sass/components/dropdown.scss +37 -0
- package/src/sass/components/editor.scss +78 -0
- package/src/sass/components/preview.scss +71 -0
- package/src/sass/components/prism.scss +142 -0
- package/src/sass/components/stats.scss +32 -0
- package/src/sass/components/toc.scss +184 -0
- package/src/sass/components/toolbar.scss +117 -0
- package/src/sass/core/AutoLink.scss +20 -0
- package/src/sass/core/BackgroundColor.scss +0 -0
- package/src/sass/core/Badge.scss +116 -0
- package/src/sass/core/Blockquote.scss +12 -0
- package/src/sass/core/Br.scss +0 -0
- package/src/sass/core/Card.scss +219 -0
- package/src/sass/core/CodeBlock.scss +205 -0
- package/src/sass/core/Color.scss +37 -0
- package/src/sass/core/CommentReference.scss +0 -0
- package/src/sass/core/Detail.scss +107 -0
- package/src/sass/core/Emoji.scss +127 -0
- package/src/sass/core/Emphasis.scss +9 -0
- package/src/sass/core/Footnote.scss +21 -0
- package/src/sass/core/FrontMatterVars.scss +19 -0
- package/src/sass/core/Header.scss +103 -0
- package/src/sass/core/HighLight.scss +0 -0
- package/src/sass/core/Hr.scss +10 -0
- package/src/sass/core/HtmlBlock.scss +0 -0
- package/src/sass/core/Iframe.scss +36 -0
- package/src/sass/core/Image.scss +59 -0
- package/src/sass/core/InlineCode.scss +10 -0
- package/src/sass/core/InlineMath.scss +11 -0
- package/src/sass/core/Link.scss +16 -0
- package/src/sass/core/List.scss +61 -0
- package/src/sass/core/Mark.scss +15 -0
- package/src/sass/core/MathBlock.scss +0 -0
- package/src/sass/core/Panel.scss +150 -0
- package/src/sass/core/Paragraph.scss +6 -0
- package/src/sass/core/Ruby.scss +0 -0
- package/src/sass/core/Size.scss +8 -0
- package/src/sass/core/Strikethrough.scss +0 -0
- package/src/sass/core/Sub.scss +5 -0
- package/src/sass/core/Suggester.scss +62 -0
- package/src/sass/core/Sup.scss +5 -0
- package/src/sass/core/Table.scss +127 -0
- package/src/sass/core/Toc.scss +28 -0
- package/src/sass/core/Transfer.scss +0 -0
- package/src/sass/core/Underline.scss +0 -0
- package/src/sass/google-fonts.scss +34 -0
- package/src/sass/index.scss +3 -0
- package/src/sass/prism/dark.scss +131 -0
- package/src/sass/prism/light.scss +143 -0
- package/src/sass/variables/colors.scss +96 -0
- package/src/toolbars/Bubble.js +232 -0
- package/src/toolbars/BubbleTable.js +147 -0
- package/src/toolbars/HookCenter.js +185 -0
- package/src/toolbars/MenuBase.js +357 -0
- package/src/toolbars/PreviewerBubble.js +558 -0
- package/src/toolbars/Toc.js +246 -0
- package/src/toolbars/Toolbar.js +401 -0
- package/src/toolbars/hooks/Audio.js +53 -0
- package/src/toolbars/hooks/Badge.js +80 -0
- package/src/toolbars/hooks/BarTable.js +41 -0
- package/src/toolbars/hooks/Bold.js +70 -0
- package/src/toolbars/hooks/Br.js +34 -0
- package/src/toolbars/hooks/Card.js +64 -0
- package/src/toolbars/hooks/CheckList.js +41 -0
- package/src/toolbars/hooks/Code.js +46 -0
- package/src/toolbars/hooks/Color.js +285 -0
- package/src/toolbars/hooks/Copy.js +139 -0
- package/src/toolbars/hooks/Detail.js +70 -0
- package/src/toolbars/hooks/ECharts.js +303 -0
- package/src/toolbars/hooks/Emoji.js +303 -0
- package/src/toolbars/hooks/Export.js +47 -0
- package/src/toolbars/hooks/File.js +54 -0
- package/src/toolbars/hooks/Formula.js +36 -0
- package/src/toolbars/hooks/FullScreen.js +55 -0
- package/src/toolbars/hooks/Graph.js +281 -0
- package/src/toolbars/hooks/H1.js +71 -0
- package/src/toolbars/hooks/H2.js +71 -0
- package/src/toolbars/hooks/H3.js +71 -0
- package/src/toolbars/hooks/Header.js +100 -0
- package/src/toolbars/hooks/Hr.js +35 -0
- package/src/toolbars/hooks/Iframe.js +35 -0
- package/src/toolbars/hooks/Image.js +60 -0
- package/src/toolbars/hooks/Insert.js +36 -0
- package/src/toolbars/hooks/Italic.js +70 -0
- package/src/toolbars/hooks/LineTable.js +41 -0
- package/src/toolbars/hooks/Link.js +46 -0
- package/src/toolbars/hooks/List.js +55 -0
- package/src/toolbars/hooks/Ol.js +41 -0
- package/src/toolbars/hooks/Panel.js +155 -0
- package/src/toolbars/hooks/Quote.js +45 -0
- package/src/toolbars/hooks/Redo.js +33 -0
- package/src/toolbars/hooks/Ruby.js +59 -0
- package/src/toolbars/hooks/Size.js +100 -0
- package/src/toolbars/hooks/Split.js +37 -0
- package/src/toolbars/hooks/Strikethrough.js +65 -0
- package/src/toolbars/hooks/Sub.js +58 -0
- package/src/toolbars/hooks/Sup.js +58 -0
- package/src/toolbars/hooks/SwitchModel.js +78 -0
- package/src/toolbars/hooks/Table.js +56 -0
- package/src/toolbars/hooks/Toc.js +35 -0
- package/src/toolbars/hooks/TogglePreview.js +79 -0
- package/src/toolbars/hooks/Ul.js +41 -0
- package/src/toolbars/hooks/Underline.js +65 -0
- package/src/toolbars/hooks/Undo.js +30 -0
- package/src/toolbars/hooks/Video.js +53 -0
- package/src/utils/LazyLoadImg.js +341 -0
- package/src/utils/autoindent.js +58 -0
- package/src/utils/codeBlockContentHandler.js +351 -0
- package/src/utils/config.js +98 -0
- package/src/utils/copy.js +55 -0
- package/src/utils/dialog.js +196 -0
- package/src/utils/dom.js +162 -0
- package/src/utils/downloadUtil.js +23 -0
- package/src/utils/env.js +22 -0
- package/src/utils/error.js +61 -0
- package/src/utils/event.js +38 -0
- package/src/utils/export.js +115 -0
- package/src/utils/file.js +121 -0
- package/src/utils/formulaUtilsHandler.js +230 -0
- package/src/utils/htmlparser.js +977 -0
- package/src/utils/image.js +99 -0
- package/src/utils/imgSizeHandler.js +279 -0
- package/src/utils/jsonUtils.js +17 -0
- package/src/utils/lineFeed.js +49 -0
- package/src/utils/listContentHandler.js +227 -0
- package/src/utils/lookbehind-replace.js +81 -0
- package/src/utils/mathjax.js +89 -0
- package/src/utils/myersDiff.js +211 -0
- package/src/utils/pasteHelper.js +253 -0
- package/src/utils/recount-pos.js +59 -0
- package/src/utils/regexp.js +295 -0
- package/src/utils/sanitize.js +477 -0
- package/src/utils/selection.js +50 -0
- package/src/utils/svgUtils.js +96 -0
- package/src/utils/tableContentHandler.js +592 -0
- package/tools/README.md +3 -0
|
@@ -0,0 +1,876 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import ParagraphBase from '@/core/ParagraphBase';
|
|
17
|
+
import Prism from 'prismjs';
|
|
18
|
+
import { escapeHTMLSpecialChar, unescapeHTMLSpecialChar } from '@/utils/sanitize';
|
|
19
|
+
import { getTableRule, getCodeBlockRule } from '@/utils/regexp';
|
|
20
|
+
import { prependLineFeedForParagraph } from '@/utils/lineFeed';
|
|
21
|
+
|
|
22
|
+
Prism.manual = true;
|
|
23
|
+
|
|
24
|
+
const CUSTOM_WRAPPER = {
|
|
25
|
+
figure: 'figure',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const supportLanguages = [
|
|
29
|
+
'markup',
|
|
30
|
+
'html',
|
|
31
|
+
'xml',
|
|
32
|
+
'svg',
|
|
33
|
+
'mathml',
|
|
34
|
+
'ssml',
|
|
35
|
+
'atom',
|
|
36
|
+
'rss',
|
|
37
|
+
'css',
|
|
38
|
+
'clike',
|
|
39
|
+
'javascript',
|
|
40
|
+
'js',
|
|
41
|
+
'abap',
|
|
42
|
+
'abnf',
|
|
43
|
+
'actionscript',
|
|
44
|
+
'ada',
|
|
45
|
+
'agda',
|
|
46
|
+
'al',
|
|
47
|
+
'antlr4',
|
|
48
|
+
'g4',
|
|
49
|
+
'apacheconf',
|
|
50
|
+
'apex',
|
|
51
|
+
'apl',
|
|
52
|
+
'applescript',
|
|
53
|
+
'aql',
|
|
54
|
+
'arduino',
|
|
55
|
+
'ino',
|
|
56
|
+
'arff',
|
|
57
|
+
'armasm',
|
|
58
|
+
'arm-asm',
|
|
59
|
+
'arturo',
|
|
60
|
+
'art',
|
|
61
|
+
'asciidoc',
|
|
62
|
+
'adoc',
|
|
63
|
+
'aspnet',
|
|
64
|
+
'asm6502',
|
|
65
|
+
'asmatmel',
|
|
66
|
+
'autohotkey',
|
|
67
|
+
'autoit',
|
|
68
|
+
'avisynth',
|
|
69
|
+
'avs',
|
|
70
|
+
'avro-idl',
|
|
71
|
+
'avdl',
|
|
72
|
+
'awk',
|
|
73
|
+
'gawk',
|
|
74
|
+
'bash',
|
|
75
|
+
'sh',
|
|
76
|
+
'shell',
|
|
77
|
+
'basic',
|
|
78
|
+
'batch',
|
|
79
|
+
'bbcode',
|
|
80
|
+
'shortcode',
|
|
81
|
+
'bbj',
|
|
82
|
+
'bicep',
|
|
83
|
+
'birb',
|
|
84
|
+
'bison',
|
|
85
|
+
'bnf',
|
|
86
|
+
'rbnf',
|
|
87
|
+
'bqn',
|
|
88
|
+
'brainfuck',
|
|
89
|
+
'brightscript',
|
|
90
|
+
'bro',
|
|
91
|
+
'bsl',
|
|
92
|
+
'oscript',
|
|
93
|
+
'c',
|
|
94
|
+
'csharp',
|
|
95
|
+
'cs',
|
|
96
|
+
'dotnet',
|
|
97
|
+
'cpp',
|
|
98
|
+
'cfscript',
|
|
99
|
+
'cfc',
|
|
100
|
+
'chaiscript',
|
|
101
|
+
'cil',
|
|
102
|
+
'cilkc',
|
|
103
|
+
'cilk-c',
|
|
104
|
+
'cilkcpp',
|
|
105
|
+
'cilk-cpp',
|
|
106
|
+
'cilk',
|
|
107
|
+
'clojure',
|
|
108
|
+
'cmake',
|
|
109
|
+
'cobol',
|
|
110
|
+
'coffeescript',
|
|
111
|
+
'coffee',
|
|
112
|
+
'concurnas',
|
|
113
|
+
'conc',
|
|
114
|
+
'csp',
|
|
115
|
+
'cooklang',
|
|
116
|
+
'coq',
|
|
117
|
+
'crystal',
|
|
118
|
+
'css-extras',
|
|
119
|
+
'csv',
|
|
120
|
+
'cue',
|
|
121
|
+
'cypher',
|
|
122
|
+
'd',
|
|
123
|
+
'dart',
|
|
124
|
+
'dataweave',
|
|
125
|
+
'dax',
|
|
126
|
+
'dhall',
|
|
127
|
+
'diff',
|
|
128
|
+
'django',
|
|
129
|
+
'jinja2',
|
|
130
|
+
'dns-zone-file',
|
|
131
|
+
'dns-zone',
|
|
132
|
+
'docker',
|
|
133
|
+
'dockerfile',
|
|
134
|
+
'dot',
|
|
135
|
+
'gv',
|
|
136
|
+
'ebnf',
|
|
137
|
+
'editorconfig',
|
|
138
|
+
'eiffel',
|
|
139
|
+
'ejs',
|
|
140
|
+
'eta',
|
|
141
|
+
'elixir',
|
|
142
|
+
'elm',
|
|
143
|
+
'etlua',
|
|
144
|
+
'erb',
|
|
145
|
+
'erlang',
|
|
146
|
+
'excel-formula',
|
|
147
|
+
'xlsx',
|
|
148
|
+
'xls',
|
|
149
|
+
'fsharp',
|
|
150
|
+
'factor',
|
|
151
|
+
'false',
|
|
152
|
+
'firestore-security-rules',
|
|
153
|
+
'flow',
|
|
154
|
+
'fortran',
|
|
155
|
+
'ftl',
|
|
156
|
+
'gml',
|
|
157
|
+
'gamemakerlanguage',
|
|
158
|
+
'gap',
|
|
159
|
+
'gcode',
|
|
160
|
+
'gdscript',
|
|
161
|
+
'gedcom',
|
|
162
|
+
'gettext',
|
|
163
|
+
'po',
|
|
164
|
+
'gherkin',
|
|
165
|
+
'git',
|
|
166
|
+
'glsl',
|
|
167
|
+
'gn',
|
|
168
|
+
'gni',
|
|
169
|
+
'linker-script',
|
|
170
|
+
'ld',
|
|
171
|
+
'go',
|
|
172
|
+
'go-module',
|
|
173
|
+
'go-mod',
|
|
174
|
+
'gradle',
|
|
175
|
+
'graphql',
|
|
176
|
+
'groovy',
|
|
177
|
+
'haml',
|
|
178
|
+
'handlebars',
|
|
179
|
+
'hbs',
|
|
180
|
+
'mustache',
|
|
181
|
+
'haskell',
|
|
182
|
+
'hs',
|
|
183
|
+
'haxe',
|
|
184
|
+
'hcl',
|
|
185
|
+
'hlsl',
|
|
186
|
+
'hoon',
|
|
187
|
+
'http',
|
|
188
|
+
'hpkp',
|
|
189
|
+
'hsts',
|
|
190
|
+
'ichigojam',
|
|
191
|
+
'icon',
|
|
192
|
+
'icu-message-format',
|
|
193
|
+
'idris',
|
|
194
|
+
'idr',
|
|
195
|
+
'ignore',
|
|
196
|
+
'gitignore',
|
|
197
|
+
'hgignore',
|
|
198
|
+
'npmignore',
|
|
199
|
+
'inform7',
|
|
200
|
+
'ini',
|
|
201
|
+
'io',
|
|
202
|
+
'j',
|
|
203
|
+
'java',
|
|
204
|
+
'javadoc',
|
|
205
|
+
'javadoclike',
|
|
206
|
+
'javastacktrace',
|
|
207
|
+
'jexl',
|
|
208
|
+
'jolie',
|
|
209
|
+
'jq',
|
|
210
|
+
'jsdoc',
|
|
211
|
+
'js-extras',
|
|
212
|
+
'json',
|
|
213
|
+
'webmanifest',
|
|
214
|
+
'json5',
|
|
215
|
+
'jsonp',
|
|
216
|
+
'jsstacktrace',
|
|
217
|
+
'js-templates',
|
|
218
|
+
'julia',
|
|
219
|
+
'keepalived',
|
|
220
|
+
'keyman',
|
|
221
|
+
'kotlin',
|
|
222
|
+
'kt',
|
|
223
|
+
'kts',
|
|
224
|
+
'kumir',
|
|
225
|
+
'kum',
|
|
226
|
+
'kusto',
|
|
227
|
+
'latex',
|
|
228
|
+
'tex',
|
|
229
|
+
'context',
|
|
230
|
+
'latte',
|
|
231
|
+
'less',
|
|
232
|
+
'lilypond',
|
|
233
|
+
'ly',
|
|
234
|
+
'liquid',
|
|
235
|
+
'lisp',
|
|
236
|
+
'emacs',
|
|
237
|
+
'elisp',
|
|
238
|
+
'emacs-lisp',
|
|
239
|
+
'livescript',
|
|
240
|
+
'llvm',
|
|
241
|
+
'log',
|
|
242
|
+
'lolcode',
|
|
243
|
+
'lua',
|
|
244
|
+
'magma',
|
|
245
|
+
'makefile',
|
|
246
|
+
'markdown',
|
|
247
|
+
'md',
|
|
248
|
+
'markup-templating',
|
|
249
|
+
'mata',
|
|
250
|
+
'matlab',
|
|
251
|
+
'maxscript',
|
|
252
|
+
'mel',
|
|
253
|
+
'mermaid',
|
|
254
|
+
'metafont',
|
|
255
|
+
'mizar',
|
|
256
|
+
'mongodb',
|
|
257
|
+
'monkey',
|
|
258
|
+
'moonscript',
|
|
259
|
+
'moon',
|
|
260
|
+
'n1ql',
|
|
261
|
+
'n4js',
|
|
262
|
+
'n4jsd',
|
|
263
|
+
'nand2tetris-hdl',
|
|
264
|
+
'naniscript',
|
|
265
|
+
'nani',
|
|
266
|
+
'nasm',
|
|
267
|
+
'neon',
|
|
268
|
+
'nevod',
|
|
269
|
+
'nginx',
|
|
270
|
+
'nim',
|
|
271
|
+
'nix',
|
|
272
|
+
'nsis',
|
|
273
|
+
'objectivec',
|
|
274
|
+
'objc',
|
|
275
|
+
'ocaml',
|
|
276
|
+
'odin',
|
|
277
|
+
'opencl',
|
|
278
|
+
'openqasm',
|
|
279
|
+
'qasm',
|
|
280
|
+
'oz',
|
|
281
|
+
'parigp',
|
|
282
|
+
'parser',
|
|
283
|
+
'pascal',
|
|
284
|
+
'objectpascal',
|
|
285
|
+
'pascaligo',
|
|
286
|
+
'psl',
|
|
287
|
+
'pcaxis',
|
|
288
|
+
'px',
|
|
289
|
+
'peoplecode',
|
|
290
|
+
'pcode',
|
|
291
|
+
'perl',
|
|
292
|
+
'php',
|
|
293
|
+
'phpdoc',
|
|
294
|
+
'php-extras',
|
|
295
|
+
'plant-uml',
|
|
296
|
+
'plantuml',
|
|
297
|
+
'plsql',
|
|
298
|
+
'powerquery',
|
|
299
|
+
'pq',
|
|
300
|
+
'mscript',
|
|
301
|
+
'powershell',
|
|
302
|
+
'processing',
|
|
303
|
+
'prolog',
|
|
304
|
+
'promql',
|
|
305
|
+
'properties',
|
|
306
|
+
'protobuf',
|
|
307
|
+
'pug',
|
|
308
|
+
'puppet',
|
|
309
|
+
'pure',
|
|
310
|
+
'purebasic',
|
|
311
|
+
'pbfasm',
|
|
312
|
+
'purescript',
|
|
313
|
+
'purs',
|
|
314
|
+
'python',
|
|
315
|
+
'py',
|
|
316
|
+
'qsharp',
|
|
317
|
+
'qs',
|
|
318
|
+
'q',
|
|
319
|
+
'qml',
|
|
320
|
+
'qore',
|
|
321
|
+
'r',
|
|
322
|
+
'racket',
|
|
323
|
+
'rkt',
|
|
324
|
+
'cshtml',
|
|
325
|
+
'razor',
|
|
326
|
+
'jsx',
|
|
327
|
+
'tsx',
|
|
328
|
+
'reason',
|
|
329
|
+
'regex',
|
|
330
|
+
'rego',
|
|
331
|
+
'renpy',
|
|
332
|
+
'rpy',
|
|
333
|
+
'rescript',
|
|
334
|
+
'res',
|
|
335
|
+
'rest',
|
|
336
|
+
'rip',
|
|
337
|
+
'roboconf',
|
|
338
|
+
'robotframework',
|
|
339
|
+
'robot',
|
|
340
|
+
'ruby',
|
|
341
|
+
'rb',
|
|
342
|
+
'rust',
|
|
343
|
+
'sas',
|
|
344
|
+
'sass',
|
|
345
|
+
'scss',
|
|
346
|
+
'scala',
|
|
347
|
+
'scheme',
|
|
348
|
+
'shell-session',
|
|
349
|
+
'sh-session',
|
|
350
|
+
'shellsession',
|
|
351
|
+
'smali',
|
|
352
|
+
'smalltalk',
|
|
353
|
+
'smarty',
|
|
354
|
+
'sml',
|
|
355
|
+
'smlnj',
|
|
356
|
+
'solidity',
|
|
357
|
+
'sol',
|
|
358
|
+
'solution-file',
|
|
359
|
+
'sln',
|
|
360
|
+
'soy',
|
|
361
|
+
'sparql',
|
|
362
|
+
'rq',
|
|
363
|
+
'splunk-spl',
|
|
364
|
+
'sqf',
|
|
365
|
+
'sql',
|
|
366
|
+
'squirrel',
|
|
367
|
+
'stan',
|
|
368
|
+
'stata',
|
|
369
|
+
'iecst',
|
|
370
|
+
'stylus',
|
|
371
|
+
'supercollider',
|
|
372
|
+
'sclang',
|
|
373
|
+
'swift',
|
|
374
|
+
'systemd',
|
|
375
|
+
't4-templating',
|
|
376
|
+
't4-cs',
|
|
377
|
+
't4',
|
|
378
|
+
't4-vb',
|
|
379
|
+
'tap',
|
|
380
|
+
'tcl',
|
|
381
|
+
'tt2',
|
|
382
|
+
'textile',
|
|
383
|
+
'toml',
|
|
384
|
+
'tremor',
|
|
385
|
+
'trickle',
|
|
386
|
+
'troy',
|
|
387
|
+
'turtle',
|
|
388
|
+
'trig',
|
|
389
|
+
'twig',
|
|
390
|
+
'typescript',
|
|
391
|
+
'ts',
|
|
392
|
+
'typoscript',
|
|
393
|
+
'tsconfig',
|
|
394
|
+
'unrealscript',
|
|
395
|
+
'uscript',
|
|
396
|
+
'uc',
|
|
397
|
+
'uorazor',
|
|
398
|
+
'uri',
|
|
399
|
+
'url',
|
|
400
|
+
'v',
|
|
401
|
+
'vala',
|
|
402
|
+
'vbnet',
|
|
403
|
+
'velocity',
|
|
404
|
+
'verilog',
|
|
405
|
+
'vhdl',
|
|
406
|
+
'vim',
|
|
407
|
+
'visual-basic',
|
|
408
|
+
'vb',
|
|
409
|
+
'vba',
|
|
410
|
+
'warpscript',
|
|
411
|
+
'wasm',
|
|
412
|
+
'web-idl',
|
|
413
|
+
'webidl',
|
|
414
|
+
'wgsl',
|
|
415
|
+
'wiki',
|
|
416
|
+
'wolfram',
|
|
417
|
+
'mathematica',
|
|
418
|
+
'nb',
|
|
419
|
+
'wl',
|
|
420
|
+
'wren',
|
|
421
|
+
'xeora',
|
|
422
|
+
'xeoracube',
|
|
423
|
+
'xml-doc',
|
|
424
|
+
'xojo',
|
|
425
|
+
'xquery',
|
|
426
|
+
'yaml',
|
|
427
|
+
'yml',
|
|
428
|
+
'yang',
|
|
429
|
+
'zig',
|
|
430
|
+
];
|
|
431
|
+
export default class CodeBlock extends ParagraphBase {
|
|
432
|
+
static HOOK_NAME = 'codeBlock';
|
|
433
|
+
static inlineCodeCache = {};
|
|
434
|
+
|
|
435
|
+
constructor({ externals, config }) {
|
|
436
|
+
super({ needCache: true });
|
|
437
|
+
|
|
438
|
+
CodeBlock.inlineCodeCache = {};
|
|
439
|
+
this.codeCache = {};
|
|
440
|
+
this.customLang = [];
|
|
441
|
+
this.customParser = {};
|
|
442
|
+
this.wrap = config.wrap; // 超出是否换行
|
|
443
|
+
this.lineNumber = config.lineNumber; // 是否显示行号
|
|
444
|
+
this.copyCode = config.copyCode; // 是否显示“复制”按钮
|
|
445
|
+
this.editCode = config.editCode; // 是否显示“编辑”按钮
|
|
446
|
+
this.cdn = config.cdn; // 是否使用cdn
|
|
447
|
+
this.expandCode = config.expandCode; // 是否支持展开代码块
|
|
448
|
+
Prism.plugins.autoloader.languages_path = this.cdn;
|
|
449
|
+
this.selfClosing = config.selfClosing; // 自动闭合,为true时,当md中有奇数个```时,会自动在md末尾追加一个```
|
|
450
|
+
|
|
451
|
+
this.indentedCodeBlock = typeof config.indentedCodeBlock === 'undefined' ? true : config.indentedCodeBlock; // 是否支持缩进代码块
|
|
452
|
+
this.INLINE_CODE_REGEX = /(`+)(.+?(?:\n.+?)*?)\1/g;
|
|
453
|
+
if (config && config.customRenderer) {
|
|
454
|
+
this.customLang = Object.keys(config.customRenderer).map((lang) => lang.toLowerCase());
|
|
455
|
+
this.customParser = { ...config.customRenderer };
|
|
456
|
+
}
|
|
457
|
+
this.customHighlighter = config.highlighter;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
$codeCache(sign, str) {
|
|
461
|
+
if (sign && str) {
|
|
462
|
+
this.codeCache[sign] = str;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (this.codeCache[sign]) {
|
|
466
|
+
return this.codeCache[sign];
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (this.codeCache.length > 40) {
|
|
470
|
+
this.codeCache.length = 0;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// 渲染特定语言代码块
|
|
477
|
+
parseCustomLanguage(lang, codeSrc, props) {
|
|
478
|
+
const engine = this.customParser[lang];
|
|
479
|
+
if (!engine || typeof engine.render !== 'function') {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
const html = engine.render(codeSrc, props.sign, this.$engine);
|
|
483
|
+
if (!html) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
const tag = CUSTOM_WRAPPER[engine.constructor.TYPE] || 'div';
|
|
487
|
+
return `<${tag} data-sign="${props.sign}" data-type="${lang}" data-lines="${props.lines}">${html}</${tag}>`;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// 修复渲染行号时打散的标签
|
|
491
|
+
fillTag(lines) {
|
|
492
|
+
const tagStack = []; // 存储未闭合标签
|
|
493
|
+
return lines.map((rawLine) => {
|
|
494
|
+
if (!rawLine) return '';
|
|
495
|
+
let line = rawLine;
|
|
496
|
+
// 补全上一行未闭合标签
|
|
497
|
+
while (tagStack.length) {
|
|
498
|
+
const tag = tagStack.pop();
|
|
499
|
+
line = `${tag}${line}`;
|
|
500
|
+
}
|
|
501
|
+
// 计算未闭合标签
|
|
502
|
+
const tags = line.match(/<span class="(.+?)">|<\/span>/g);
|
|
503
|
+
let close = 0;
|
|
504
|
+
if (!tags) return line;
|
|
505
|
+
while (tags.length) {
|
|
506
|
+
const tag = tags.pop();
|
|
507
|
+
if (/<\/span>/.test(tag)) close += 1;
|
|
508
|
+
else if (!close) {
|
|
509
|
+
tagStack.unshift(tag.match(/<span class="(.+?)">/)[0]);
|
|
510
|
+
} else {
|
|
511
|
+
close -= 1;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// 补全未闭合标签
|
|
515
|
+
for (let i = 0; i < tagStack.length; i++) {
|
|
516
|
+
line = `${line}</span>`;
|
|
517
|
+
}
|
|
518
|
+
return line;
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// 渲染行号
|
|
523
|
+
renderLineNumber(code) {
|
|
524
|
+
if (!this.lineNumber) return code;
|
|
525
|
+
let codeLines = code.split('\n');
|
|
526
|
+
codeLines.pop(); // 末尾回车不增加行号
|
|
527
|
+
codeLines = this.fillTag(codeLines);
|
|
528
|
+
return `<span class="code-line">${codeLines.join('</span>\n<span class="code-line">')}</span>`;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* 判断内置转换语法是否被覆盖
|
|
533
|
+
* @param {string} lang
|
|
534
|
+
*/
|
|
535
|
+
isInternalCustomLangCovered(lang) {
|
|
536
|
+
return this.customLang.indexOf(lang) !== -1;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* 预处理代码块
|
|
541
|
+
* @param {string} match
|
|
542
|
+
* @param {string} leadingContent
|
|
543
|
+
* @param {string} code
|
|
544
|
+
*/
|
|
545
|
+
computeLines(match, leadingContent, code) {
|
|
546
|
+
const leadingSpaces = leadingContent;
|
|
547
|
+
const lines = this.getLineCount(match, leadingSpaces);
|
|
548
|
+
const sign = this.$engine.md5(match.replace(/^\n+/, '') + lines);
|
|
549
|
+
return {
|
|
550
|
+
sign,
|
|
551
|
+
lines,
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* 包裹代码块,解决单行代码超出长度
|
|
557
|
+
* @param {string} $code
|
|
558
|
+
* @param {string} lang
|
|
559
|
+
*/
|
|
560
|
+
wrapCode($code, lang) {
|
|
561
|
+
return `<code class="language-${lang}${this.wrap ? ' wrap' : ''}">${$code}</code>`;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* 使用渲染引擎处理代码块
|
|
566
|
+
* @param {string} $code
|
|
567
|
+
* @param {string} $lang
|
|
568
|
+
* @param {string} sign
|
|
569
|
+
* @param {number} lines
|
|
570
|
+
*/
|
|
571
|
+
renderCodeBlock($code, $lang, sign, lines) {
|
|
572
|
+
let cacheCode = $code;
|
|
573
|
+
let lang = $lang;
|
|
574
|
+
const highlighted = false;
|
|
575
|
+
const that = this;
|
|
576
|
+
if (this.customHighlighter) {
|
|
577
|
+
// 平台自定义代码块样式
|
|
578
|
+
cacheCode = this.customHighlighter(cacheCode, lang);
|
|
579
|
+
} else {
|
|
580
|
+
if (!supportLanguages.includes(lang)) {
|
|
581
|
+
lang = 'text';
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (Prism.languages[lang]) {
|
|
585
|
+
cacheCode = Prism.highlight(cacheCode, Prism.languages[lang], lang);
|
|
586
|
+
cacheCode = this.renderLineNumber(cacheCode);
|
|
587
|
+
} else {
|
|
588
|
+
cacheCode = escapeHTMLSpecialChar(cacheCode);
|
|
589
|
+
Prism.plugins.autoloader.loadLanguages(
|
|
590
|
+
[lang],
|
|
591
|
+
function () {
|
|
592
|
+
that.$highlightCodeBlock($code, lang, `.code-${sign}`);
|
|
593
|
+
},
|
|
594
|
+
function () {
|
|
595
|
+
that.$highlightCodeBlock($code, 'text', `.code-${sign}`);
|
|
596
|
+
},
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
const needUnExpand = this.expandCode && $code.match(/\n/g)?.length > 10; // 是否需要收起代码块
|
|
601
|
+
cacheCode = `<div
|
|
602
|
+
data-sign="${sign}"
|
|
603
|
+
data-type="codeBlock"
|
|
604
|
+
data-lines="${lines}"
|
|
605
|
+
data-edit-code="${this.editCode}"
|
|
606
|
+
data-copy-code="${this.copyCode}"
|
|
607
|
+
data-expand-code="${this.expandCode}"
|
|
608
|
+
data-lang="${$lang}"
|
|
609
|
+
style="position:relative"
|
|
610
|
+
class="code-container-${sign} ${needUnExpand ? 'cherry-code-unExpand' : 'cherry-code-expand'}"
|
|
611
|
+
>
|
|
612
|
+
|
|
613
|
+
<pre class="language-${lang} code-${sign}">${this.wrapCode(cacheCode, lang)}</pre>
|
|
614
|
+
`;
|
|
615
|
+
if (needUnExpand) {
|
|
616
|
+
cacheCode += `<div class="cherry-mask-code-block">
|
|
617
|
+
<div class="expand-btn">
|
|
618
|
+
<span class="expand-btn material-symbols-outlined">keyboard_arrow_down</span>
|
|
619
|
+
</div>
|
|
620
|
+
</div>`;
|
|
621
|
+
}
|
|
622
|
+
cacheCode += '</div>';
|
|
623
|
+
return cacheCode;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
$highlightCodeBlock(code, lang, clazz) {
|
|
627
|
+
const language = lang;
|
|
628
|
+
let cacheCode = Prism.highlight(unescapeHTMLSpecialChar(code), Prism.languages[language], language);
|
|
629
|
+
cacheCode = this.renderLineNumber(cacheCode);
|
|
630
|
+
cacheCode = this.wrapCode(cacheCode, language);
|
|
631
|
+
const cherry = this.$engine.$cherry;
|
|
632
|
+
// 查找指定id
|
|
633
|
+
setTimeout(function () {
|
|
634
|
+
console.log(clazz, cherry.wrapperDom.querySelectorAll(clazz), document.querySelectorAll(clazz));
|
|
635
|
+
}, 20000);
|
|
636
|
+
this.$waitElement(clazz, 0, function (elements) {
|
|
637
|
+
elements.forEach((codeBlock) => {
|
|
638
|
+
codeBlock.innerHTML = cacheCode;
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
$waitElement(clazz, times, cb) {
|
|
644
|
+
const that = this;
|
|
645
|
+
if (times > 100) {
|
|
646
|
+
console.warn(`times ${times} milliseconds, clazz ${clazz} not found`);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
if (document.querySelectorAll(clazz).length === 0) {
|
|
650
|
+
setTimeout(function () {
|
|
651
|
+
that.$waitElement(clazz, times + 1, cb);
|
|
652
|
+
}, 500);
|
|
653
|
+
} else {
|
|
654
|
+
cb(document.querySelectorAll(clazz));
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* 获取缩进代码块语法的正则
|
|
660
|
+
* 缩进代码块必须要以连续两个以上的换行符开头
|
|
661
|
+
*/
|
|
662
|
+
$getIndentedCodeReg() {
|
|
663
|
+
const ret = {
|
|
664
|
+
begin: '(?:^|\\n\\s*\\n)(?: {4}|\\t)',
|
|
665
|
+
end: '(?=$|\\n( {0,3}[^ \\t\\n]|\\n[^ \\t\\n]))',
|
|
666
|
+
content: '([\\s\\S]+?)',
|
|
667
|
+
};
|
|
668
|
+
return new RegExp(ret.begin + ret.content + ret.end, 'g');
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* 生成缩进代码块(没有行号、没有代码高亮)
|
|
673
|
+
*/
|
|
674
|
+
$getIndentCodeBlock(str) {
|
|
675
|
+
if (!this.indentedCodeBlock) {
|
|
676
|
+
return str;
|
|
677
|
+
}
|
|
678
|
+
return this.$recoverCodeInIndent(str).replace(this.$getIndentedCodeReg(), (match, code) => {
|
|
679
|
+
const lineCount = (match.match(/\n/g) || []).length;
|
|
680
|
+
const sign = this.$engine.md5(match);
|
|
681
|
+
const html = `<pre data-sign="${sign}" data-lines="${lineCount}"><code>${escapeHTMLSpecialChar(
|
|
682
|
+
code.replace(/\n( {4}|\t)/g, '\n'),
|
|
683
|
+
)}</code></pre>`;
|
|
684
|
+
// return this.getCacheWithSpace(this.pushCache(html), match, true);
|
|
685
|
+
return prependLineFeedForParagraph(match, this.pushCache(html, sign, lineCount));
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* 预处理缩进代码块,将缩进代码块里的高亮代码块和行内代码进行占位处理
|
|
691
|
+
*/
|
|
692
|
+
$replaceCodeInIndent(str) {
|
|
693
|
+
if (!this.indentedCodeBlock) {
|
|
694
|
+
return str;
|
|
695
|
+
}
|
|
696
|
+
return str.replace(this.$getIndentedCodeReg(), (match) => {
|
|
697
|
+
return match.replace(/`/g, '~~~IndentCode');
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* 恢复预处理的内容
|
|
703
|
+
*/
|
|
704
|
+
$recoverCodeInIndent(str) {
|
|
705
|
+
if (!this.indentedCodeBlock) {
|
|
706
|
+
return str;
|
|
707
|
+
}
|
|
708
|
+
return str.replace(this.$getIndentedCodeReg(), (match) => {
|
|
709
|
+
return match.replace(/~~~IndentCode/g, '`');
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
$dealUnclosingCode(str) {
|
|
714
|
+
const codes = str.match(/(?:^|\n)(\n*((?:>[\t ]*)*)[^\S\n]*)(`{3,})([^`]*?)(?=$|\n)/g);
|
|
715
|
+
if (!codes || codes.length <= 0) {
|
|
716
|
+
return str;
|
|
717
|
+
}
|
|
718
|
+
// 剔除异常的数据
|
|
719
|
+
let codeBegin = false;
|
|
720
|
+
const $codes = codes.filter((value) => {
|
|
721
|
+
if (codeBegin === false) {
|
|
722
|
+
codeBegin = true;
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
725
|
+
if (/```[^`\s]+/.test(value)) {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
codeBegin = false;
|
|
729
|
+
return true;
|
|
730
|
+
});
|
|
731
|
+
// 如果有奇数个代码块关键字,则进行自动闭合
|
|
732
|
+
if ($codes.length % 2 === 1) {
|
|
733
|
+
const lastCode = $codes[$codes.length - 1].replace(/(`)[^`]+$/, '$1').replace(/\n+/, '');
|
|
734
|
+
const $str = str.replace(/\n+$/, '').replace(/\n`{1,2}$/, '');
|
|
735
|
+
return `${$str}\n${lastCode}\n`;
|
|
736
|
+
}
|
|
737
|
+
return str;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
beforeMakeHtml(str, sentenceMakeFunc, markdownParams) {
|
|
741
|
+
let $str = str;
|
|
742
|
+
|
|
743
|
+
if (this.selfClosing || this.$engine.$cherry.options.engine.global.flowSessionContext) {
|
|
744
|
+
$str = this.$dealUnclosingCode($str);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// 预处理缩进代码块
|
|
748
|
+
$str = this.$replaceCodeInIndent($str);
|
|
749
|
+
|
|
750
|
+
$str = $str.replace(this.RULE.reg, (match, leadingContent, leadingContentBlockQuote, begin, lang, code) => {
|
|
751
|
+
function addBlockQuoteSignToResult(result) {
|
|
752
|
+
if (leadingContentBlockQuote) {
|
|
753
|
+
const regex = new RegExp(`^\n*`, '');
|
|
754
|
+
const leadingNewline = result.match(regex)[0];
|
|
755
|
+
// eslint-disable-next-line no-param-reassign
|
|
756
|
+
result = leadingNewline + leadingContentBlockQuote + result.replace(regex, (_) => '');
|
|
757
|
+
}
|
|
758
|
+
return result;
|
|
759
|
+
}
|
|
760
|
+
let $code = code;
|
|
761
|
+
const { sign, lines } = this.computeLines(match, leadingContent, code);
|
|
762
|
+
// 从缓存中获取html
|
|
763
|
+
let cacheCode = this.$codeCache(sign);
|
|
764
|
+
if (cacheCode && cacheCode !== '') {
|
|
765
|
+
// 别忘了把 ">"(引用块)加回来
|
|
766
|
+
const result = this.getCacheWithSpace(this.pushCache(cacheCode, sign, lines), match);
|
|
767
|
+
return addBlockQuoteSignToResult(result);
|
|
768
|
+
}
|
|
769
|
+
$code = this.$recoverCodeInIndent($code);
|
|
770
|
+
$code = $code.replace(/~D/g, '$');
|
|
771
|
+
$code = $code.replace(/~T/g, '~');
|
|
772
|
+
|
|
773
|
+
/** 处理缩进 - start: 当首行反引号前存在多个空格缩进时,代码内容要相应去除相同数量的空格 */
|
|
774
|
+
const indentSpaces = leadingContent?.match(/[ ]/g)?.length ?? 0;
|
|
775
|
+
if (indentSpaces > 0) {
|
|
776
|
+
const regex = new RegExp(`(^|\\n)[ ]{1,${indentSpaces}}`, 'g');
|
|
777
|
+
$code = $code.replace(regex, '$1');
|
|
778
|
+
}
|
|
779
|
+
/** 处理缩进 - end */
|
|
780
|
+
|
|
781
|
+
// 如果本代码块处于一个引用块(形如 "> " 或 "> > ")中,那么需要从代码中每一行去掉引用块的符号
|
|
782
|
+
if (leadingContentBlockQuote) {
|
|
783
|
+
const regex = new RegExp(`(^|\\n)${leadingContentBlockQuote}`, 'g');
|
|
784
|
+
$code = $code.replace(regex, '$1');
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// 未命中缓存,执行渲染
|
|
788
|
+
const $lang = lang.trim();
|
|
789
|
+
// 如果是公式关键字,则直接返回
|
|
790
|
+
if (/^(math|katex|latex)$/i.test($lang) && !this.isInternalCustomLangCovered($lang)) {
|
|
791
|
+
const prefix = match.match(/^\s*/g);
|
|
792
|
+
// ~D为经编辑器中间转义后的$,code结尾包含结束```前的所有换行符,所以不需要补换行
|
|
793
|
+
return `${prefix}~D~D\n${$code}~D~D`; // 提供公式语法供公式钩子解析
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// 自定义语言渲染,可覆盖内置的自定义语言逻辑
|
|
797
|
+
if (this.customLang.indexOf($lang.toLowerCase()) !== -1) {
|
|
798
|
+
cacheCode = this.parseCustomLanguage($lang, $code, { lines, sign });
|
|
799
|
+
if (cacheCode && cacheCode !== '') {
|
|
800
|
+
this.$codeCache(sign, cacheCode);
|
|
801
|
+
return this.getCacheWithSpace(this.pushCache(cacheCode, sign, lines), match);
|
|
802
|
+
}
|
|
803
|
+
// 渲染出错则按正常code进行渲染
|
|
804
|
+
}
|
|
805
|
+
// $code = this.$replaceSpecialChar($code);
|
|
806
|
+
$code = $code.replace(/~X/g, '\\`');
|
|
807
|
+
cacheCode = this.renderCodeBlock($code, $lang, sign, lines);
|
|
808
|
+
cacheCode = cacheCode.replace(/\\/g, '\\\\');
|
|
809
|
+
cacheCode = this.$codeCache(sign, cacheCode);
|
|
810
|
+
const result = this.getCacheWithSpace(this.pushCache(cacheCode, sign, lines), match);
|
|
811
|
+
return addBlockQuoteSignToResult(result);
|
|
812
|
+
});
|
|
813
|
+
// 表格里处理行内代码,让一个td里的行内代码语法生效,让跨td的行内代码语法失效
|
|
814
|
+
$str = $str.replace(getTableRule(true), (whole, ...args) => {
|
|
815
|
+
return whole
|
|
816
|
+
.split('|')
|
|
817
|
+
.map((oneTd) => {
|
|
818
|
+
return this.makeInlineCode(oneTd);
|
|
819
|
+
})
|
|
820
|
+
.join('|')
|
|
821
|
+
.replace(/`/g, '\\`');
|
|
822
|
+
});
|
|
823
|
+
// 为了避免InlineCode被HtmlBlock转义,需要在这里提前缓存
|
|
824
|
+
// InlineBlock只需要在afterMakeHtml还原即可
|
|
825
|
+
$str = this.makeInlineCode($str);
|
|
826
|
+
|
|
827
|
+
// 处理缩进代码块
|
|
828
|
+
$str = this.$getIndentCodeBlock($str);
|
|
829
|
+
|
|
830
|
+
return $str;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
makeInlineCode(str) {
|
|
834
|
+
let $str = str;
|
|
835
|
+
if (this.INLINE_CODE_REGEX.test($str)) {
|
|
836
|
+
$str = $str.replace(/\\`/g, '~~not~inlineCode');
|
|
837
|
+
$str = $str.replace(this.INLINE_CODE_REGEX, (match, syntax, code) => {
|
|
838
|
+
if (code.trim() === '`') {
|
|
839
|
+
return match;
|
|
840
|
+
}
|
|
841
|
+
let $code = code.replace(/~~not~inlineCode/g, '\\`');
|
|
842
|
+
$code = this.$replaceSpecialChar($code);
|
|
843
|
+
$code = $code.replace(/\\/g, '\\\\');
|
|
844
|
+
const html = `<code>${escapeHTMLSpecialChar($code)}</code>`;
|
|
845
|
+
const sign = this.$engine.md5(html);
|
|
846
|
+
CodeBlock.inlineCodeCache[sign] = html;
|
|
847
|
+
return `~~CODE${sign}$`;
|
|
848
|
+
});
|
|
849
|
+
$str = $str.replace(/~~not~inlineCode/g, '\\`');
|
|
850
|
+
}
|
|
851
|
+
return $str;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
makeHtml(str) {
|
|
855
|
+
return str;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
$replaceSpecialChar(str) {
|
|
859
|
+
let $str = str.replace(/~Q/g, '\\~');
|
|
860
|
+
$str = $str.replace(/~Y/g, '\\!');
|
|
861
|
+
$str = $str.replace(/~Z/g, '\\#');
|
|
862
|
+
$str = $str.replace(/~&/g, '\\&');
|
|
863
|
+
$str = $str.replace(/~K/g, '\\/');
|
|
864
|
+
// $str = $str.replace(/~D/g, '$');
|
|
865
|
+
// $str = $str.replace(/~T/g, '~');
|
|
866
|
+
return $str;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
rule() {
|
|
870
|
+
return getCodeBlockRule();
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
mounted(dom) {
|
|
874
|
+
// prettyPrint.prettyPrint();
|
|
875
|
+
}
|
|
876
|
+
}
|