@cherry-markdown/cherry-markdown-dev 0.9.0-dev.202504110650.834443a → 0.9.0-dev.202504160300.d23d141
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/README.md +2 -2
- package/dist/addons/advance/cherry-table-echarts-plugin.js +1 -1
- package/dist/addons/cherry-code-block-mermaid-plugin.js +1 -1
- package/dist/cherry-markdown.core.common.js +1 -1
- package/dist/cherry-markdown.core.js +1 -1
- package/dist/cherry-markdown.engine.core.common.js +1 -1
- package/dist/cherry-markdown.engine.core.esm.js +1 -1
- package/dist/cherry-markdown.engine.core.js +1 -1
- package/dist/cherry-markdown.esm.js +1 -1
- package/dist/cherry-markdown.js +1 -1
- package/dist/cherry-markdown.min.js +1 -1
- package/dist/fonts/ch-icon.eot +0 -0
- package/dist/fonts/ch-icon.ttf +0 -0
- package/dist/fonts/ch-icon.woff +0 -0
- package/dist/fonts/ch-icon.woff2 +0 -0
- package/package.json +1 -3
- package/src/Cherry.config.js +0 -634
- package/src/Cherry.js +0 -1104
- package/src/CherryStatic.js +0 -70
- package/src/Editor.js +0 -748
- package/src/Engine.js +0 -402
- package/src/Event.js +0 -140
- package/src/Factory.js +0 -180
- package/src/Logger.js +0 -31
- package/src/Previewer.js +0 -1192
- package/src/Sanitizer.js +0 -4
- package/src/Sanitizer.node.js +0 -7
- package/src/UrlCache.js +0 -98
- package/src/addons/advance/cherry-table-echarts-plugin.js +0 -170
- package/src/addons/cherry-code-block-mermaid-plugin.js +0 -158
- package/src/addons/cherry-code-block-plantuml-plugin.js +0 -106
- package/src/core/HookCenter.js +0 -297
- package/src/core/HooksConfig.js +0 -105
- package/src/core/ParagraphBase.js +0 -332
- package/src/core/SentenceBase.js +0 -65
- package/src/core/SyntaxBase.js +0 -194
- package/src/core/hooks/AutoLink.js +0 -232
- package/src/core/hooks/BackgroundColor.js +0 -46
- package/src/core/hooks/Blockquote.js +0 -70
- package/src/core/hooks/Br.js +0 -85
- package/src/core/hooks/CodeBlock.js +0 -456
- package/src/core/hooks/Color.js +0 -46
- package/src/core/hooks/CommentReference.js +0 -96
- package/src/core/hooks/Detail.js +0 -108
- package/src/core/hooks/Emoji.config.js +0 -1825
- package/src/core/hooks/Emoji.js +0 -119
- package/src/core/hooks/Emphasis.js +0 -113
- package/src/core/hooks/Footnote.js +0 -125
- package/src/core/hooks/FrontMatter.js +0 -51
- package/src/core/hooks/Header.js +0 -234
- package/src/core/hooks/HighLight.js +0 -37
- package/src/core/hooks/Hr.js +0 -52
- package/src/core/hooks/HtmlBlock.js +0 -199
- package/src/core/hooks/Image.js +0 -174
- package/src/core/hooks/InlineCode.js +0 -48
- package/src/core/hooks/InlineMath.js +0 -108
- package/src/core/hooks/Link.js +0 -160
- package/src/core/hooks/List.js +0 -264
- package/src/core/hooks/MathBlock.js +0 -104
- package/src/core/hooks/Panel.js +0 -145
- package/src/core/hooks/Paragraph.js +0 -84
- package/src/core/hooks/Ruby.js +0 -34
- package/src/core/hooks/Size.js +0 -51
- package/src/core/hooks/Strikethrough.js +0 -54
- package/src/core/hooks/Sub.js +0 -47
- package/src/core/hooks/SuggestList.js +0 -333
- package/src/core/hooks/Suggester.js +0 -707
- package/src/core/hooks/Sup.js +0 -47
- package/src/core/hooks/Table.js +0 -275
- package/src/core/hooks/Toc.js +0 -292
- package/src/core/hooks/Transfer.js +0 -47
- package/src/core/hooks/Underline.js +0 -37
- package/src/index.core.js +0 -29
- package/src/index.engine.core.js +0 -68
- package/src/index.engine.js +0 -28
- package/src/index.js +0 -32
- package/src/libs/mermaidAPI.8.4.8.js +0 -1
- package/src/libs/mermaidAPI.8.5.2.js +0 -42
- package/src/libs/rawdeflate.js +0 -1663
- package/src/locales/en_US.js +0 -139
- package/src/locales/index.js +0 -25
- package/src/locales/ru_RU.js +0 -139
- package/src/locales/zh_CN.js +0 -142
- package/src/sass/base.scss +0 -26
- package/src/sass/bubble_formula.scss +0 -166
- package/src/sass/ch-icon.scss +0 -118
- package/src/sass/cherry.scss +0 -1116
- package/src/sass/components/bubble.scss +0 -173
- package/src/sass/components/shortcut_key_config.scss +0 -108
- package/src/sass/formula_utils_bubble.scss +0 -82
- package/src/sass/icon_template.scss +0 -24
- package/src/sass/icons/uEA03-list.svg +0 -19
- package/src/sass/icons/uEA04-check.svg +0 -14
- package/src/sass/icons/uEA09-square.svg +0 -10
- package/src/sass/icons/uEA0A-bold.svg +0 -20
- package/src/sass/icons/uEA0B-code.svg +0 -18
- package/src/sass/icons/uEA0C-color.svg +0 -13
- package/src/sass/icons/uEA0D-header.svg +0 -8
- package/src/sass/icons/uEA0E-image.svg +0 -15
- package/src/sass/icons/uEA0F-italic.svg +0 -8
- package/src/sass/icons/uEA10-link.svg +0 -16
- package/src/sass/icons/uEA11-ol.svg +0 -21
- package/src/sass/icons/uEA12-size.svg +0 -11
- package/src/sass/icons/uEA13-strike.svg +0 -16
- package/src/sass/icons/uEA14-table.svg +0 -12
- package/src/sass/icons/uEA15-ul.svg +0 -17
- package/src/sass/icons/uEA16-underline.svg +0 -13
- package/src/sass/icons/uEA17-word.svg +0 -16
- package/src/sass/icons/uEA18-blockquote.svg +0 -11
- package/src/sass/icons/uEA19-font.svg +0 -10
- package/src/sass/icons/uEA1F-insertClass.svg +0 -39
- package/src/sass/icons/uEA20-insertFlow.svg +0 -8
- package/src/sass/icons/uEA21-insertFormula.svg +0 -23
- package/src/sass/icons/uEA22-insertGantt.svg +0 -13
- package/src/sass/icons/uEA23-insertGraph.svg +0 -13
- package/src/sass/icons/uEA24-insertPie.svg +0 -19
- package/src/sass/icons/uEA25-insertSeq.svg +0 -20
- package/src/sass/icons/uEA26-insertState.svg +0 -35
- package/src/sass/icons/uEA27-line.svg +0 -11
- package/src/sass/icons/uEA28-preview.svg +0 -18
- package/src/sass/icons/uEA29-previewClose.svg +0 -24
- package/src/sass/icons/uEA2A-toc.svg +0 -24
- package/src/sass/icons/uEA2D-sub.svg +0 -15
- package/src/sass/icons/uEA2E-sup.svg +0 -15
- package/src/sass/icons/uEA2F-h1.svg +0 -16
- package/src/sass/icons/uEA30-h2.svg +0 -20
- package/src/sass/icons/uEA31-h3.svg +0 -23
- package/src/sass/icons/uEA32-h4.svg +0 -16
- package/src/sass/icons/uEA33-h5.svg +0 -20
- package/src/sass/icons/uEA34-h6.svg +0 -17
- package/src/sass/icons/uEA35-video.svg +0 -20
- package/src/sass/icons/uEA36-insert.svg +0 -25
- package/src/sass/icons/uEA37-little_table.svg +0 -30
- package/src/sass/icons/uEA38-pdf.svg +0 -27
- package/src/sass/icons/uEA39-checklist.svg +0 -22
- package/src/sass/icons/uEA40-close.svg +0 -12
- package/src/sass/icons/uEA41-fullscreen.svg +0 -81
- package/src/sass/icons/uEA42-minscreen.svg +0 -77
- package/src/sass/icons/uEA43-insertChart.svg +0 -23
- package/src/sass/icons/uEA44-question.svg +0 -25
- package/src/sass/icons/uEA45-settings.svg +0 -32
- package/src/sass/icons/uEA46-ok.svg +0 -7
- package/src/sass/icons/uEA47-br.svg +0 -22
- package/src/sass/icons/uEA48-normal.svg +0 -15
- package/src/sass/icons/uEA49-undo.svg +0 -19
- package/src/sass/icons/uEA50-redo.svg +0 -21
- package/src/sass/icons/uEA51-copy.svg +0 -6
- package/src/sass/icons/uEA52-phone.svg +0 -5
- package/src/sass/icons/uEA53-cherry-table-delete.svg +0 -17
- package/src/sass/icons/uEA54-cherry-table-insert-bottom.svg +0 -16
- package/src/sass/icons/uEA55-cherry-table-insert-left.svg +0 -15
- package/src/sass/icons/uEA56-cherry-table-insert-right.svg +0 -16
- package/src/sass/icons/uEA57-cherry-table-insert-top.svg +0 -16
- package/src/sass/icons/uEA58-sort-s.svg +0 -13
- package/src/sass/icons/uEA59-pinyin.svg +0 -1
- package/src/sass/icons/uEA5A-create.svg +0 -24
- package/src/sass/icons/uEA5B-download.svg +0 -34
- package/src/sass/icons/uEA5C-edit.svg +0 -3
- package/src/sass/icons/uEA5D-export.svg +0 -53
- package/src/sass/icons/uEA5E-folder-open.svg +0 -3
- package/src/sass/icons/uEA5F-folder.svg +0 -3
- package/src/sass/icons/uEA60-help.svg +0 -5
- package/src/sass/icons/uEA61-pen-fill.svg +0 -13
- package/src/sass/icons/uEA62-pen.svg +0 -3
- package/src/sass/icons/uEA64-tips.svg +0 -5
- package/src/sass/icons/uEA65-warn.svg +0 -5
- package/src/sass/icons/uEA66-mistake.svg +0 -4
- package/src/sass/icons/uEA67-success.svg +0 -4
- package/src/sass/icons/uEA68-danger.svg +0 -4
- package/src/sass/icons/uEA69-info.svg +0 -5
- package/src/sass/icons/uEA6A-primary.svg +0 -5
- package/src/sass/icons/uEA6B-warning.svg +0 -5
- package/src/sass/icons/uEA6C-justify.svg +0 -19
- package/src/sass/icons/uEA6D-justifyCenter.svg +0 -19
- package/src/sass/icons/uEA6E-justifyLeft.svg +0 -19
- package/src/sass/icons/uEA6F-justifyRight.svg +0 -19
- package/src/sass/icons/uEA70-chevronsLeft.svg +0 -1
- package/src/sass/icons/uEA71-chevronsRight.svg +0 -1
- package/src/sass/icons/uEA72-trendingUp.svg +0 -1
- package/src/sass/icons/uEA74-codeBlock.svg +0 -1
- package/src/sass/icons/uEA75-expand.svg +0 -3
- package/src/sass/icons/uEA76-unExpand.svg +0 -3
- package/src/sass/icons/uEA77-swap-vert.svg +0 -1
- package/src/sass/icons/uEA78-swap.svg +0 -1
- package/src/sass/icons/uEA79-keyboard.svg +0 -1
- package/src/sass/icons/uEA7A-command.svg +0 -1
- package/src/sass/icons/uEA7B-search.svg +0 -1
- package/src/sass/index.scss +0 -3
- package/src/sass/markdown.scss +0 -668
- package/src/sass/markdown_pure.scss +0 -9
- package/src/sass/prettyprint/prettyprint.scss +0 -118
- package/src/sass/previewer.scss +0 -179
- package/src/sass/print.scss +0 -13
- package/src/sass/prism/coy.scss +0 -220
- package/src/sass/prism/dark.scss +0 -132
- package/src/sass/prism/default.scss +0 -143
- package/src/sass/prism/funky.scss +0 -133
- package/src/sass/prism/okaidia.scss +0 -126
- package/src/sass/prism/one-dark.scss +0 -440
- package/src/sass/prism/one-light.scss +0 -428
- package/src/sass/prism/solarized-light.scss +0 -153
- package/src/sass/prism/tomorrow-night.scss +0 -125
- package/src/sass/prism/twilight.scss +0 -202
- package/src/sass/prism/vs-dark.scss +0 -275
- package/src/sass/prism/vs-light.scss +0 -168
- package/src/sass/themes/blue.scss +0 -411
- package/src/sass/themes/dark.scss +0 -517
- package/src/sass/themes/default.scss +0 -255
- package/src/sass/themes/green.scss +0 -395
- package/src/sass/themes/light.scss +0 -368
- package/src/sass/themes/red.scss +0 -397
- package/src/sass/themes/violet.scss +0 -410
- package/src/sass/variable.scss +0 -84
- package/src/toolbars/Bubble.js +0 -234
- package/src/toolbars/BubbleFormula.js +0 -298
- package/src/toolbars/BubbleTable.js +0 -147
- package/src/toolbars/FloatMenu.js +0 -131
- package/src/toolbars/HiddenToolbar.js +0 -36
- package/src/toolbars/HookCenter.js +0 -231
- package/src/toolbars/MenuBase.js +0 -569
- package/src/toolbars/PreviewerBubble.js +0 -608
- package/src/toolbars/ShortcutKeyConfigPanel.js +0 -345
- package/src/toolbars/Sidebar.js +0 -36
- package/src/toolbars/Toc.js +0 -242
- package/src/toolbars/Toolbar.js +0 -449
- package/src/toolbars/ToolbarRight.js +0 -37
- package/src/toolbars/hooks/Audio.js +0 -79
- package/src/toolbars/hooks/BarTable.js +0 -41
- package/src/toolbars/hooks/Bold.js +0 -73
- package/src/toolbars/hooks/Br.js +0 -34
- package/src/toolbars/hooks/ChangeLocale.js +0 -62
- package/src/toolbars/hooks/ChatGpt.js +0 -182
- package/src/toolbars/hooks/CheckList.js +0 -41
- package/src/toolbars/hooks/Code.js +0 -49
- package/src/toolbars/hooks/CodeTheme.js +0 -66
- package/src/toolbars/hooks/Color.js +0 -298
- package/src/toolbars/hooks/Copy.js +0 -141
- package/src/toolbars/hooks/Detail.js +0 -69
- package/src/toolbars/hooks/DrawIo.js +0 -57
- package/src/toolbars/hooks/Export.js +0 -49
- package/src/toolbars/hooks/File.js +0 -79
- package/src/toolbars/hooks/Formula.js +0 -69
- package/src/toolbars/hooks/FullScreen.js +0 -50
- package/src/toolbars/hooks/Graph.js +0 -263
- package/src/toolbars/hooks/H1.js +0 -71
- package/src/toolbars/hooks/H2.js +0 -71
- package/src/toolbars/hooks/H3.js +0 -71
- package/src/toolbars/hooks/Header.js +0 -118
- package/src/toolbars/hooks/Hr.js +0 -35
- package/src/toolbars/hooks/Image.js +0 -91
- package/src/toolbars/hooks/InlineCode.js +0 -53
- package/src/toolbars/hooks/Insert.js +0 -193
- package/src/toolbars/hooks/Italic.js +0 -72
- package/src/toolbars/hooks/Justify.js +0 -49
- package/src/toolbars/hooks/LineTable.js +0 -41
- package/src/toolbars/hooks/Link.js +0 -49
- package/src/toolbars/hooks/List.js +0 -55
- package/src/toolbars/hooks/MobilePreview.js +0 -44
- package/src/toolbars/hooks/Ol.js +0 -41
- package/src/toolbars/hooks/Panel.js +0 -140
- package/src/toolbars/hooks/Pdf.js +0 -78
- package/src/toolbars/hooks/Publish.js +0 -123
- package/src/toolbars/hooks/QuickTable.js +0 -43
- package/src/toolbars/hooks/Quote.js +0 -45
- package/src/toolbars/hooks/Redo.js +0 -33
- package/src/toolbars/hooks/Ruby.js +0 -59
- package/src/toolbars/hooks/Search.js +0 -53
- package/src/toolbars/hooks/Settings.js +0 -220
- package/src/toolbars/hooks/ShortcutKey.js +0 -62
- package/src/toolbars/hooks/Size.js +0 -118
- package/src/toolbars/hooks/Split.js +0 -37
- package/src/toolbars/hooks/Strikethrough.js +0 -71
- package/src/toolbars/hooks/Sub.js +0 -58
- package/src/toolbars/hooks/Sup.js +0 -58
- package/src/toolbars/hooks/SwitchModel.js +0 -56
- package/src/toolbars/hooks/Table.js +0 -56
- package/src/toolbars/hooks/Theme.js +0 -62
- package/src/toolbars/hooks/Toc.js +0 -35
- package/src/toolbars/hooks/TogglePreview.js +0 -91
- package/src/toolbars/hooks/Ul.js +0 -41
- package/src/toolbars/hooks/Underline.js +0 -68
- package/src/toolbars/hooks/Undo.js +0 -30
- package/src/toolbars/hooks/Video.js +0 -79
- package/src/toolbars/hooks/Word.js +0 -78
- package/src/toolbars/hooks/WordCount.js +0 -106
- package/src/utils/autoindent.js +0 -58
- package/src/utils/cm-search-replace.js +0 -794
- package/src/utils/code-preview-language-setting.js +0 -180
- package/src/utils/codeBlockContentHandler.js +0 -400
- package/src/utils/config.js +0 -174
- package/src/utils/copy.js +0 -55
- package/src/utils/dialog.js +0 -214
- package/src/utils/dom.js +0 -163
- package/src/utils/downloadUtil.js +0 -23
- package/src/utils/env.js +0 -22
- package/src/utils/error.js +0 -61
- package/src/utils/event.js +0 -38
- package/src/utils/export.js +0 -166
- package/src/utils/file.js +0 -164
- package/src/utils/formulaUtilsHandler.js +0 -232
- package/src/utils/htmlparser.js +0 -976
- package/src/utils/image.js +0 -99
- package/src/utils/imgSizeHandler.js +0 -279
- package/src/utils/lazyLoadImg.js +0 -327
- package/src/utils/lineFeed.js +0 -49
- package/src/utils/listContentHandler.js +0 -227
- package/src/utils/lookbehind-replace.js +0 -81
- package/src/utils/mathjax.js +0 -89
- package/src/utils/myersDiff.js +0 -211
- package/src/utils/pasteHelper.js +0 -253
- package/src/utils/platformTransform.js +0 -71
- package/src/utils/recount-pos.js +0 -59
- package/src/utils/regexp.js +0 -295
- package/src/utils/sanitize.js +0 -477
- package/src/utils/selection.js +0 -50
- package/src/utils/shortcutKey.js +0 -291
- package/src/utils/svgUtils.js +0 -96
- package/src/utils/tableContentHandler.js +0 -876
- package/test/core/CommonMark.spec.ts +0 -62
- package/test/core/hooks/AutoLink.spec.ts +0 -28
- package/test/core/hooks/List.spec.ts +0 -79
- package/test/core/hooks/__snapshots__/List.spec.ts.snap +0 -11
- package/test/example.md +0 -778
- package/test/node.js +0 -10
- package/test/suites/commonmark.spec.json +0 -5218
- package/test/tsconfig.test.json +0 -6
- package/test/utils/regexp.spec.ts +0 -28
|
@@ -1,456 +0,0 @@
|
|
|
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 } 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 default class CodeBlock extends ParagraphBase {
|
|
29
|
-
static HOOK_NAME = 'codeBlock';
|
|
30
|
-
static inlineCodeCache = {};
|
|
31
|
-
|
|
32
|
-
constructor({ externals, config }) {
|
|
33
|
-
super({ needCache: true });
|
|
34
|
-
CodeBlock.inlineCodeCache = {};
|
|
35
|
-
this.codeCache = {};
|
|
36
|
-
this.customLang = [];
|
|
37
|
-
this.customParser = {};
|
|
38
|
-
this.lineNumber = config.lineNumber; // 是否显示行号
|
|
39
|
-
this.copyCode = config.copyCode; // 是否显示“复制”按钮
|
|
40
|
-
this.expandCode = config.expandCode; // 是否显示“展开”按钮
|
|
41
|
-
this.editCode = config.editCode; // 是否显示“编辑”按钮
|
|
42
|
-
this.changeLang = config.changeLang; // 是否显示“切换语言”按钮
|
|
43
|
-
this.selfClosing = config.selfClosing; // 自动闭合,为true时,当md中有奇数个```时,会自动在md末尾追加一个```
|
|
44
|
-
this.mermaid = config.mermaid; // mermaid的配置,目前仅支持格式设置,svg2img=true 展示成图片,false 展示成svg
|
|
45
|
-
this.indentedCodeBlock = typeof config.indentedCodeBlock === 'undefined' ? true : config.indentedCodeBlock; // 是否支持缩进代码块
|
|
46
|
-
this.INLINE_CODE_REGEX = /(`+)(.+?(?:\n.+?)*?)\1/g;
|
|
47
|
-
if (config && config.customRenderer) {
|
|
48
|
-
this.customLang = Object.keys(config.customRenderer).map((lang) => lang.toLowerCase());
|
|
49
|
-
this.customParser = { ...config.customRenderer };
|
|
50
|
-
}
|
|
51
|
-
this.customHighlighter = config.highlighter;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
$codeCache(sign, str) {
|
|
55
|
-
if (sign && str) {
|
|
56
|
-
this.codeCache[sign] = str;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (this.codeCache[sign]) {
|
|
60
|
-
return this.codeCache[sign];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (this.codeCache.length > 40) {
|
|
64
|
-
this.codeCache.length = 0;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 渲染特定语言代码块
|
|
71
|
-
parseCustomLanguage(lang, codeSrc, props) {
|
|
72
|
-
const engine = this.customParser[lang];
|
|
73
|
-
if (!engine || typeof engine.render !== 'function') {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
const html = engine.render(codeSrc, props.sign, this.$engine, this.mermaid);
|
|
77
|
-
if (!html) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
const tag = CUSTOM_WRAPPER[engine.constructor.TYPE] || 'div';
|
|
81
|
-
return `<${tag} data-sign="${props.sign}" data-type="${lang}" data-lines="${props.lines}">${html}</${tag}>`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// 修复渲染行号时打散的标签
|
|
85
|
-
fillTag(lines) {
|
|
86
|
-
const tagStack = []; // 存储未闭合标签
|
|
87
|
-
return lines.map((rawLine) => {
|
|
88
|
-
if (!rawLine) return '';
|
|
89
|
-
let line = rawLine;
|
|
90
|
-
// 补全上一行未闭合标签
|
|
91
|
-
while (tagStack.length) {
|
|
92
|
-
const tag = tagStack.pop();
|
|
93
|
-
line = `${tag}${line}`;
|
|
94
|
-
}
|
|
95
|
-
// 计算未闭合标签
|
|
96
|
-
const tags = line.match(/<span class="(.+?)">|<\/span>/g);
|
|
97
|
-
let close = 0;
|
|
98
|
-
if (!tags) return line;
|
|
99
|
-
while (tags.length) {
|
|
100
|
-
const tag = tags.pop();
|
|
101
|
-
if (/<\/span>/.test(tag)) close += 1;
|
|
102
|
-
else if (!close) {
|
|
103
|
-
tagStack.unshift(tag.match(/<span class="(.+?)">/)[0]);
|
|
104
|
-
} else {
|
|
105
|
-
close -= 1;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
// 补全未闭合标签
|
|
109
|
-
for (let i = 0; i < tagStack.length; i++) {
|
|
110
|
-
line = `${line}</span>`;
|
|
111
|
-
}
|
|
112
|
-
return line;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// 渲染行号
|
|
117
|
-
renderLineNumber(code) {
|
|
118
|
-
if (!this.lineNumber) return code;
|
|
119
|
-
let codeLines = code.split('\n');
|
|
120
|
-
codeLines.pop(); // 末尾回车不增加行号
|
|
121
|
-
codeLines = this.fillTag(codeLines);
|
|
122
|
-
return `<span class="code-line">${codeLines.join('</span>\n<span class="code-line">')}</span>`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 判断内置转换语法是否被覆盖
|
|
127
|
-
* @param {string} lang
|
|
128
|
-
*/
|
|
129
|
-
isInternalCustomLangCovered(lang) {
|
|
130
|
-
return this.customLang.indexOf(lang) !== -1;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 预处理代码块
|
|
135
|
-
* @param {string} match
|
|
136
|
-
* @param {string} leadingContent
|
|
137
|
-
* @param {string} code
|
|
138
|
-
*/
|
|
139
|
-
computeLines(match, leadingContent, code) {
|
|
140
|
-
const leadingSpaces = leadingContent;
|
|
141
|
-
const lines = this.getLineCount(match, leadingSpaces);
|
|
142
|
-
const sign = this.$engine.hash(match.replace(/^\n+/, '') + lines);
|
|
143
|
-
return {
|
|
144
|
-
sign,
|
|
145
|
-
lines,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* 补齐用codeBlock承载的mermaid
|
|
151
|
-
* @param {string} $code
|
|
152
|
-
* @param {string} $lang
|
|
153
|
-
*/
|
|
154
|
-
appendMermaid($code, $lang) {
|
|
155
|
-
let [code, lang] = [$code, $lang];
|
|
156
|
-
// 临时实现流程图、时序图缩略写法
|
|
157
|
-
if (/^flow([ ](TD|LR))?$/i.test(lang) && !this.isInternalCustomLangCovered(lang)) {
|
|
158
|
-
const suffix = lang.match(/^flow(?:[ ](TD|LR))?$/i) || [];
|
|
159
|
-
code = `graph ${suffix[1] || 'TD'}\n${code}`;
|
|
160
|
-
lang = 'mermaid';
|
|
161
|
-
}
|
|
162
|
-
if (/^seq$/i.test(lang) && !this.isInternalCustomLangCovered(lang)) {
|
|
163
|
-
code = `sequenceDiagram\n${code}`;
|
|
164
|
-
lang = 'mermaid';
|
|
165
|
-
}
|
|
166
|
-
if (lang === 'mermaid') {
|
|
167
|
-
// 8.4.8版本兼容8.5.2版本的语法
|
|
168
|
-
code = code.replace(/(^[\s]*)stateDiagram-v2\n/, '$1stateDiagram\n');
|
|
169
|
-
// code = code.replace(/(^[\s]*)sequenceDiagram[ \t]*\n[\s]*autonumber[ \t]*\n/, '$1sequenceDiagram\n');
|
|
170
|
-
}
|
|
171
|
-
return [code, lang];
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 包裹代码块,解决单行代码超出长度
|
|
176
|
-
* @param {string} $code
|
|
177
|
-
* @param {string} lang
|
|
178
|
-
*/
|
|
179
|
-
wrapCode($code, lang) {
|
|
180
|
-
return `<code class="language-${lang}">${$code}</code>`;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* 使用渲染引擎处理代码块
|
|
185
|
-
* @param {string} $code
|
|
186
|
-
* @param {string} $lang
|
|
187
|
-
* @param {string} sign
|
|
188
|
-
* @param {number} lines
|
|
189
|
-
*/
|
|
190
|
-
renderCodeBlock($code, $lang, sign, lines) {
|
|
191
|
-
let cacheCode = $code;
|
|
192
|
-
let lang = $lang;
|
|
193
|
-
// 兼容流式输出时占位光标影响代码块语言识别的场景
|
|
194
|
-
if (/\s*CHERRY_FLOW_SESSION_CURSOR/.test(lang)) {
|
|
195
|
-
lang = lang.replace(/\s*CHERRY_FLOW_SESSION_CURSOR/, '');
|
|
196
|
-
}
|
|
197
|
-
lang = lang.toLowerCase();
|
|
198
|
-
if (this.customHighlighter) {
|
|
199
|
-
// 平台自定义代码块样式
|
|
200
|
-
cacheCode = this.customHighlighter(cacheCode, lang);
|
|
201
|
-
} else {
|
|
202
|
-
// 默认使用prism渲染代码块
|
|
203
|
-
if (!lang || !Prism.languages[lang]) lang = 'javascript'; // 如果没有写语言,默认用js样式渲染
|
|
204
|
-
cacheCode = Prism.highlight(cacheCode, Prism.languages[lang], lang);
|
|
205
|
-
cacheCode = this.renderLineNumber(cacheCode);
|
|
206
|
-
}
|
|
207
|
-
const needUnExpand = this.expandCode && $code.match(/\n/g)?.length > 10; // 是否需要收起代码块
|
|
208
|
-
cacheCode = `<div
|
|
209
|
-
data-sign="${sign}"
|
|
210
|
-
data-type="codeBlock"
|
|
211
|
-
data-lines="${lines}"
|
|
212
|
-
data-edit-code="${this.editCode}"
|
|
213
|
-
data-copy-code="${this.copyCode}"
|
|
214
|
-
data-expand-code="${this.expandCode}"
|
|
215
|
-
data-change-lang="${this.changeLang}"
|
|
216
|
-
data-lang="${lang}"
|
|
217
|
-
style="position:relative"
|
|
218
|
-
class="${needUnExpand ? 'cherry-code-unExpand' : 'cherry-code-expand'}"
|
|
219
|
-
>
|
|
220
|
-
<pre class="language-${lang}">${this.wrapCode(cacheCode, lang)}</pre>
|
|
221
|
-
`;
|
|
222
|
-
if (needUnExpand) {
|
|
223
|
-
cacheCode += `<div class="cherry-mask-code-block">
|
|
224
|
-
<div class="expand-btn ">
|
|
225
|
-
<i class="ch-icon ch-icon-expand"></i>
|
|
226
|
-
</div>
|
|
227
|
-
</div>`;
|
|
228
|
-
}
|
|
229
|
-
cacheCode += '</div>';
|
|
230
|
-
return cacheCode;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* 获取缩进代码块语法的正则
|
|
235
|
-
* 缩进代码块必须要以连续两个以上的换行符开头
|
|
236
|
-
*/
|
|
237
|
-
$getIndentedCodeReg() {
|
|
238
|
-
const ret = {
|
|
239
|
-
begin: '(?:^|\\n\\s*\\n)(?: {4}|\\t)',
|
|
240
|
-
end: '(?=$|\\n( {0,3}[^ \\t\\n]|\\n[^ \\t\\n]))',
|
|
241
|
-
content: '([\\s\\S]+?)',
|
|
242
|
-
};
|
|
243
|
-
return new RegExp(ret.begin + ret.content + ret.end, 'g');
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* 生成缩进代码块(没有行号、没有代码高亮)
|
|
248
|
-
*/
|
|
249
|
-
$getIndentCodeBlock(str) {
|
|
250
|
-
if (!this.indentedCodeBlock) {
|
|
251
|
-
return str;
|
|
252
|
-
}
|
|
253
|
-
return this.$recoverCodeInIndent(str).replace(this.$getIndentedCodeReg(), (match, code) => {
|
|
254
|
-
const lineCount = (match.match(/\n/g) || []).length;
|
|
255
|
-
const sign = this.$engine.hash(match);
|
|
256
|
-
const html = `<pre data-sign="${sign}" data-lines="${lineCount}"><code>${escapeHTMLSpecialChar(
|
|
257
|
-
code.replace(/\n( {4}|\t)/g, '\n'),
|
|
258
|
-
)}</code></pre>`;
|
|
259
|
-
// return this.getCacheWithSpace(this.pushCache(html), match, true);
|
|
260
|
-
return prependLineFeedForParagraph(match, this.pushCache(html, sign, lineCount));
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* 预处理缩进代码块,将缩进代码块里的高亮代码块和行内代码进行占位处理
|
|
266
|
-
*/
|
|
267
|
-
$replaceCodeInIndent(str) {
|
|
268
|
-
if (!this.indentedCodeBlock) {
|
|
269
|
-
return str;
|
|
270
|
-
}
|
|
271
|
-
return str.replace(this.$getIndentedCodeReg(), (match) => {
|
|
272
|
-
return match.replace(/`/g, '~~~IndentCode');
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* 恢复预处理的内容
|
|
278
|
-
*/
|
|
279
|
-
$recoverCodeInIndent(str) {
|
|
280
|
-
if (!this.indentedCodeBlock) {
|
|
281
|
-
return str;
|
|
282
|
-
}
|
|
283
|
-
return str.replace(this.$getIndentedCodeReg(), (match) => {
|
|
284
|
-
return match.replace(/~~~IndentCode/g, '`');
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
$dealUnclosingCode(str) {
|
|
289
|
-
const codes = str.match(
|
|
290
|
-
/(?:^|\n)(\n*((?:>[\t ]*)*)(?:[^\S\n]*))(`{3,})([^`]*?)(?=CHERRY_FLOW_SESSION_CURSOR|$|\n)/g,
|
|
291
|
-
);
|
|
292
|
-
if (!codes || codes.length <= 0) {
|
|
293
|
-
return str;
|
|
294
|
-
}
|
|
295
|
-
// 剔除异常的数据
|
|
296
|
-
let codeBegin = false;
|
|
297
|
-
const $codes = codes.filter((value) => {
|
|
298
|
-
if (codeBegin === false) {
|
|
299
|
-
codeBegin = true;
|
|
300
|
-
return true;
|
|
301
|
-
}
|
|
302
|
-
if (/```[^`\s]+/.test(value)) {
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
codeBegin = false;
|
|
306
|
-
return true;
|
|
307
|
-
});
|
|
308
|
-
// 如果有奇数个代码块关键字,则进行自动闭合
|
|
309
|
-
if ($codes.length % 2 === 1) {
|
|
310
|
-
const lastCode = $codes[$codes.length - 1].replace(/(`)[^`]+$/, '$1').replace(/\n+/, '');
|
|
311
|
-
const $str = str
|
|
312
|
-
.replace(/\n+`{1,2}\n*(CHERRY_FLOW_SESSION_CURSOR|$)/, '')
|
|
313
|
-
.replace(/\n+CHERRY_FLOW_SESSION_CURSOR\n+$/, '')
|
|
314
|
-
.replace(/\n+$/, '');
|
|
315
|
-
return `${$str}\n${lastCode}\n`;
|
|
316
|
-
}
|
|
317
|
-
return str.replace(/(`{2,})CHERRY_FLOW_SESSION_CURSOR/, '$1\nCHERRY_FLOW_SESSION_CURSOR');
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
beforeMakeHtml(str, sentenceMakeFunc, markdownParams) {
|
|
321
|
-
let $str = str;
|
|
322
|
-
|
|
323
|
-
if (this.selfClosing || this.$engine.$cherry.options.engine.global.flowSessionContext) {
|
|
324
|
-
$str = this.$dealUnclosingCode($str);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// 预处理缩进代码块
|
|
328
|
-
$str = this.$replaceCodeInIndent($str);
|
|
329
|
-
|
|
330
|
-
$str = $str.replace(this.RULE.reg, (match, leadingContent, leadingContentBlockQuote, begin, lang, code) => {
|
|
331
|
-
function addBlockQuoteSignToResult(result) {
|
|
332
|
-
if (leadingContentBlockQuote) {
|
|
333
|
-
const regex = new RegExp(`^\n*`, '');
|
|
334
|
-
const leadingNewline = result.match(regex)[0];
|
|
335
|
-
// eslint-disable-next-line no-param-reassign
|
|
336
|
-
result = leadingNewline + leadingContentBlockQuote + result.replace(regex, (_) => '');
|
|
337
|
-
}
|
|
338
|
-
return result;
|
|
339
|
-
}
|
|
340
|
-
let $code = code;
|
|
341
|
-
const { sign, lines } = this.computeLines(match, leadingContent, code);
|
|
342
|
-
// 从缓存中获取html
|
|
343
|
-
let cacheCode = this.$codeCache(sign);
|
|
344
|
-
if (cacheCode && cacheCode !== '') {
|
|
345
|
-
// 别忘了把 ">"(引用块)加回来
|
|
346
|
-
const result = this.getCacheWithSpace(this.pushCache(cacheCode, sign, lines), match);
|
|
347
|
-
return addBlockQuoteSignToResult(result);
|
|
348
|
-
}
|
|
349
|
-
$code = this.$recoverCodeInIndent($code);
|
|
350
|
-
$code = $code.replace(/~D/g, '$');
|
|
351
|
-
$code = $code.replace(/~T/g, '~');
|
|
352
|
-
|
|
353
|
-
/** 处理缩进 - start: 当首行反引号前存在多个空格缩进时,代码内容要相应去除相同数量的空格 */
|
|
354
|
-
const indentSpaces = leadingContent?.match(/[ ]/g)?.length ?? 0;
|
|
355
|
-
if (indentSpaces > 0) {
|
|
356
|
-
const regex = new RegExp(`(^|\\n)[ ]{1,${indentSpaces}}`, 'g');
|
|
357
|
-
$code = $code.replace(regex, '$1');
|
|
358
|
-
}
|
|
359
|
-
/** 处理缩进 - end */
|
|
360
|
-
|
|
361
|
-
// 如果本代码块处于一个引用块(形如 "> " 或 "> > ")中,那么需要从代码中每一行去掉引用块的符号
|
|
362
|
-
if (leadingContentBlockQuote) {
|
|
363
|
-
const regex = new RegExp(`(^|\\n)${leadingContentBlockQuote}`, 'g');
|
|
364
|
-
$code = $code.replace(regex, '$1');
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// 未命中缓存,执行渲染
|
|
368
|
-
let $lang = lang.trim();
|
|
369
|
-
// 如果是公式关键字,则直接返回
|
|
370
|
-
if (/^(math|katex|latex)$/i.test($lang) && !this.isInternalCustomLangCovered($lang)) {
|
|
371
|
-
const prefix = match.match(/^\s*/g);
|
|
372
|
-
// ~D为经编辑器中间转义后的$,code结尾包含结束```前的所有换行符,所以不需要补换行
|
|
373
|
-
return `${prefix}~D~D\n${$code}~D~D`; // 提供公式语法供公式钩子解析
|
|
374
|
-
}
|
|
375
|
-
[$code, $lang] = this.appendMermaid($code, $lang);
|
|
376
|
-
// 自定义语言渲染,可覆盖内置的自定义语言逻辑
|
|
377
|
-
if (this.customLang.indexOf($lang.toLowerCase()) !== -1) {
|
|
378
|
-
cacheCode = this.parseCustomLanguage($lang, $code, { lines, sign });
|
|
379
|
-
if (cacheCode && cacheCode !== '') {
|
|
380
|
-
this.$codeCache(sign, cacheCode);
|
|
381
|
-
return this.getCacheWithSpace(this.pushCache(cacheCode, sign, lines), match);
|
|
382
|
-
}
|
|
383
|
-
// 渲染出错则按正常code进行渲染
|
|
384
|
-
}
|
|
385
|
-
// $code = this.$replaceSpecialChar($code);
|
|
386
|
-
$code = $code.replace(/~X/g, '\\`');
|
|
387
|
-
cacheCode = this.renderCodeBlock($code, $lang, sign, lines);
|
|
388
|
-
cacheCode = cacheCode.replace(/\\/g, '\\\\');
|
|
389
|
-
cacheCode = this.$codeCache(sign, cacheCode);
|
|
390
|
-
const result = this.getCacheWithSpace(this.pushCache(cacheCode, sign, lines), match);
|
|
391
|
-
return addBlockQuoteSignToResult(result);
|
|
392
|
-
});
|
|
393
|
-
// 表格里处理行内代码,让一个td里的行内代码语法生效,让跨td的行内代码语法失效
|
|
394
|
-
$str = $str.replace(getTableRule(true), (whole, ...args) => {
|
|
395
|
-
return whole
|
|
396
|
-
.split('|')
|
|
397
|
-
.map((oneTd) => {
|
|
398
|
-
return this.makeInlineCode(oneTd);
|
|
399
|
-
})
|
|
400
|
-
.join('|')
|
|
401
|
-
.replace(/`/g, '\\`');
|
|
402
|
-
});
|
|
403
|
-
// 为了避免InlineCode被HtmlBlock转义,需要在这里提前缓存
|
|
404
|
-
// InlineBlock只需要在afterMakeHtml还原即可
|
|
405
|
-
$str = this.makeInlineCode($str);
|
|
406
|
-
|
|
407
|
-
// 处理缩进代码块
|
|
408
|
-
$str = this.$getIndentCodeBlock($str);
|
|
409
|
-
|
|
410
|
-
return $str;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
makeInlineCode(str) {
|
|
414
|
-
let $str = str;
|
|
415
|
-
if (this.INLINE_CODE_REGEX.test($str)) {
|
|
416
|
-
$str = $str.replace(/\\`/g, '~~not~inlineCode');
|
|
417
|
-
$str = $str.replace(this.INLINE_CODE_REGEX, (match, syntax, code) => {
|
|
418
|
-
if (code.trim() === '`') {
|
|
419
|
-
return match;
|
|
420
|
-
}
|
|
421
|
-
let $code = code.replace(/~~not~inlineCode/g, '\\`');
|
|
422
|
-
$code = this.$replaceSpecialChar($code);
|
|
423
|
-
$code = $code.replace(/\\/g, '\\\\');
|
|
424
|
-
const html = `<code>${escapeHTMLSpecialChar($code)}</code>`;
|
|
425
|
-
const sign = this.$engine.hash(html);
|
|
426
|
-
CodeBlock.inlineCodeCache[sign] = html;
|
|
427
|
-
return `~~CODE${sign}$`;
|
|
428
|
-
});
|
|
429
|
-
$str = $str.replace(/~~not~inlineCode/g, '\\`');
|
|
430
|
-
}
|
|
431
|
-
return $str;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
makeHtml(str) {
|
|
435
|
-
return str;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
$replaceSpecialChar(str) {
|
|
439
|
-
let $str = str.replace(/~Q/g, '\\~');
|
|
440
|
-
$str = $str.replace(/~Y/g, '\\!');
|
|
441
|
-
$str = $str.replace(/~Z/g, '\\#');
|
|
442
|
-
$str = $str.replace(/~&/g, '\\&');
|
|
443
|
-
$str = $str.replace(/~K/g, '\\/');
|
|
444
|
-
// $str = $str.replace(/~D/g, '$');
|
|
445
|
-
// $str = $str.replace(/~T/g, '~');
|
|
446
|
-
return $str;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
rule() {
|
|
450
|
-
return getCodeBlockRule();
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
mounted(dom) {
|
|
454
|
-
// prettyPrint.prettyPrint();
|
|
455
|
-
}
|
|
456
|
-
}
|
package/src/core/hooks/Color.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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 SyntaxBase from '@/core/SyntaxBase';
|
|
17
|
-
import { isLookbehindSupported } from '@/utils/regexp';
|
|
18
|
-
import { replaceLookbehind } from '@/utils/lookbehind-replace';
|
|
19
|
-
|
|
20
|
-
export default class Color extends SyntaxBase {
|
|
21
|
-
static HOOK_NAME = 'fontColor';
|
|
22
|
-
// constructor() {
|
|
23
|
-
// super();
|
|
24
|
-
// }
|
|
25
|
-
|
|
26
|
-
toHtml(whole, leadingChar, m1, m2) {
|
|
27
|
-
return `${leadingChar}<span style="color:${m1}">${m2}</span>`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
makeHtml(str) {
|
|
31
|
-
if (isLookbehindSupported()) {
|
|
32
|
-
return str.replace(this.RULE.reg, this.toHtml);
|
|
33
|
-
}
|
|
34
|
-
return replaceLookbehind(str, this.RULE.reg, this.toHtml, true, 1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
rule() {
|
|
38
|
-
const ret = {
|
|
39
|
-
begin: isLookbehindSupported() ? '((?<!\\\\))!!' : '(^|[^\\\\])!!',
|
|
40
|
-
end: '!!',
|
|
41
|
-
content: '(#[0-9a-zA-Z]{3,6}|[a-z]{3,20})[\\s]([\\w\\W]+?)',
|
|
42
|
-
};
|
|
43
|
-
ret.reg = new RegExp(ret.begin + ret.content + ret.end, 'g');
|
|
44
|
-
return ret;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
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 { compileRegExp } from '@/utils/regexp';
|
|
18
|
-
import UrlCache from '@/UrlCache';
|
|
19
|
-
/**
|
|
20
|
-
* 脚注和引用语法
|
|
21
|
-
* 示例:
|
|
22
|
-
* 这里需要一个脚注[^脚注别名1],另外这里也需要一个脚注[^another]。
|
|
23
|
-
* [^脚注别名1]: 无论脚注内容写在哪里,脚注的内容总会显示在页面最底部
|
|
24
|
-
* 以两次回车结束
|
|
25
|
-
*
|
|
26
|
-
* [^another]: 另外,脚注里也可以使用一些简单的markdown语法
|
|
27
|
-
* >比如 !!#ff0000 这里!!有一段**引用**
|
|
28
|
-
*/
|
|
29
|
-
export default class CommentReference extends ParagraphBase {
|
|
30
|
-
static HOOK_NAME = 'commentReference';
|
|
31
|
-
|
|
32
|
-
constructor({ externals, config }) {
|
|
33
|
-
super();
|
|
34
|
-
this.commentCache = {};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
$cleanCache() {
|
|
38
|
-
this.commentCache = {};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
pushCommentReferenceCache(key, cache) {
|
|
42
|
-
const [url, ...args] = cache.split(/[ ]+/g);
|
|
43
|
-
const innerUrl = UrlCache.set(url);
|
|
44
|
-
this.commentCache[`${key}`.toLowerCase()] = [innerUrl, ...args].join(' ');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getCommentReferenceCache(key) {
|
|
48
|
-
return this.commentCache[`${key}`.toLowerCase()] || null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
beforeMakeHtml(str) {
|
|
52
|
-
let $str = str;
|
|
53
|
-
if (this.test($str)) {
|
|
54
|
-
$str = $str.replace(this.RULE.reg, (match, leading, key, content) => {
|
|
55
|
-
this.pushCommentReferenceCache(key, content);
|
|
56
|
-
const lineFeeds = match.match(/\n/g) ?? [];
|
|
57
|
-
return lineFeeds.join('');
|
|
58
|
-
});
|
|
59
|
-
// 替换实际引用
|
|
60
|
-
const refRegex = /(\[[^\]\n]+?\])?(?:\[([^\]\n]+?)\])/g; // 匹配[xxx][ref]形式的内容,不严格大小写
|
|
61
|
-
$str = $str.replace(refRegex, (match, leadingContent, key) => {
|
|
62
|
-
const cache = this.getCommentReferenceCache(key);
|
|
63
|
-
if (cache) {
|
|
64
|
-
if (leadingContent) {
|
|
65
|
-
return `${leadingContent}(${cache})`; // 替换为[xx](cache)形式,交给Link或多媒体标签处理
|
|
66
|
-
}
|
|
67
|
-
return `[${key}](${cache})`; // 替换为[ref](cache)形式,交给Link或多媒体标签处理
|
|
68
|
-
}
|
|
69
|
-
return match;
|
|
70
|
-
});
|
|
71
|
-
this.$cleanCache();
|
|
72
|
-
}
|
|
73
|
-
return $str;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
makeHtml(str, sentenceMakeFunc) {
|
|
77
|
-
return str;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
afterMakeHtml(str) {
|
|
81
|
-
return UrlCache.restoreAll(str);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
rule() {
|
|
85
|
-
const ret = {
|
|
86
|
-
begin: '(^|\\n)[ \t]*',
|
|
87
|
-
content: [
|
|
88
|
-
'\\[([^^][^\\]]*?)\\]:\\h*', // comment key
|
|
89
|
-
'([^\\n]+?)', // comment content
|
|
90
|
-
].join(''),
|
|
91
|
-
end: '(?=$|\\n)',
|
|
92
|
-
};
|
|
93
|
-
ret.reg = compileRegExp(ret, 'g', true);
|
|
94
|
-
return ret;
|
|
95
|
-
}
|
|
96
|
-
}
|