@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
package/src/core/hooks/Link.js
DELETED
|
@@ -1,160 +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 { escapeHTMLSpecialChar as _e, isValidScheme, encodeURIOnce } from '@/utils/sanitize';
|
|
18
|
-
import { compileRegExp, isLookbehindSupported, NOT_ALL_WHITE_SPACES_INLINE } from '@/utils/regexp';
|
|
19
|
-
import { replaceLookbehind } from '@/utils/lookbehind-replace';
|
|
20
|
-
import UrlCache from '@/UrlCache';
|
|
21
|
-
|
|
22
|
-
export default class Link extends SyntaxBase {
|
|
23
|
-
static HOOK_NAME = 'link';
|
|
24
|
-
|
|
25
|
-
constructor({ config, globalConfig }) {
|
|
26
|
-
super({ config });
|
|
27
|
-
// eslint-disable-next-line no-nested-ternary
|
|
28
|
-
this.target = config.target ? `target="${config.target}"` : !!config.openNewPage ? 'target="_blank"' : '';
|
|
29
|
-
this.rel = config.rel ? `rel="${config.rel}"` : '';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 校验link中text的方括号是否符合规则
|
|
34
|
-
* @param {string} rawText
|
|
35
|
-
*/
|
|
36
|
-
checkBrackets(rawText) {
|
|
37
|
-
const stack = [];
|
|
38
|
-
const text = `[${rawText}]`;
|
|
39
|
-
// 前方有奇数个\当前字符被转义
|
|
40
|
-
const checkEscape = (place) => text.slice(0, place).match(/\\*$/)[0].length & 1;
|
|
41
|
-
for (let i = text.length - 1; text[i]; i--) {
|
|
42
|
-
if (i === text.length - 1 && checkEscape(i)) break;
|
|
43
|
-
if (text[i] === ']' && !checkEscape(i)) stack.push(']');
|
|
44
|
-
if (text[i] === '[' && !checkEscape(i)) {
|
|
45
|
-
stack.pop();
|
|
46
|
-
if (!stack.length) {
|
|
47
|
-
return {
|
|
48
|
-
isValid: true,
|
|
49
|
-
coreText: text.slice(i + 1, text.length - 1),
|
|
50
|
-
extraLeadingChar: text.slice(0, i),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
isValid: false, // 方括号匹配不上
|
|
57
|
-
coreText: rawText,
|
|
58
|
-
extraLeadingChar: '',
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
* @param {string} match 匹配的完整字符串
|
|
65
|
-
* @param {string} leadingChar 正则分组一:前置字符
|
|
66
|
-
* @param {string} text 正则分组二:链接文字
|
|
67
|
-
* @param {string|undefined} link 正则分组三:链接URL
|
|
68
|
-
* @param {string|undefined} title 正则分组四:链接title
|
|
69
|
-
* @param {string|undefined} ref 正则分组五:链接引用
|
|
70
|
-
* @param {string|undefined} target 正则分组六:新窗口打开
|
|
71
|
-
* @returns
|
|
72
|
-
*/
|
|
73
|
-
toHtml(match, leadingChar, text, link, title, ref, target) {
|
|
74
|
-
const refType = typeof link === 'undefined' ? 'ref' : 'url';
|
|
75
|
-
let attrs = '';
|
|
76
|
-
if (refType === 'ref') {
|
|
77
|
-
// 全局引用,理应在CommentReference中被替换,没有被替换说明没有定义引用项
|
|
78
|
-
return match;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (refType === 'url') {
|
|
82
|
-
const { isValid, coreText, extraLeadingChar } = this.checkBrackets(text);
|
|
83
|
-
if (!isValid) return match;
|
|
84
|
-
attrs = title && title.trim() !== '' ? ` title="${_e(title.replace(/["']/g, ''))}"` : '';
|
|
85
|
-
if (target) {
|
|
86
|
-
attrs += ` target="${target.replace(/{target\s*=\s*(.*?)}/, '$1')}"`;
|
|
87
|
-
} else if (this.target) {
|
|
88
|
-
attrs += ` ${this.target}`;
|
|
89
|
-
}
|
|
90
|
-
let processedURL = link.trim().replace(/~1D/g, '~D'); // 还原替换的$符号
|
|
91
|
-
const processedText = coreText.replace(/~1D/g, '~D'); // 还原替换的$符号
|
|
92
|
-
// text可能是html标签,依赖htmlBlock进行处理
|
|
93
|
-
if (isValidScheme(processedURL)) {
|
|
94
|
-
processedURL = this.$engine.urlProcessor(processedURL, 'link');
|
|
95
|
-
processedURL = encodeURIOnce(processedURL);
|
|
96
|
-
return `${leadingChar + extraLeadingChar}<a href="${UrlCache.set(processedURL)}" ${
|
|
97
|
-
this.rel
|
|
98
|
-
} ${attrs}>${processedText}</a>`;
|
|
99
|
-
}
|
|
100
|
-
return `${leadingChar + extraLeadingChar}<span>${text}</span>`;
|
|
101
|
-
}
|
|
102
|
-
// should never happen
|
|
103
|
-
return match;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
toStdMarkdown(match) {
|
|
107
|
-
return match;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
makeHtml(str) {
|
|
111
|
-
let $str = str.replace(this.RULE.reg, (match) => {
|
|
112
|
-
return match.replace(/~D/g, '~1D');
|
|
113
|
-
});
|
|
114
|
-
if (isLookbehindSupported()) {
|
|
115
|
-
$str = $str.replace(this.RULE.reg, this.toHtml.bind(this));
|
|
116
|
-
} else {
|
|
117
|
-
$str = replaceLookbehind($str, this.RULE.reg, this.toHtml.bind(this), true, 1);
|
|
118
|
-
}
|
|
119
|
-
$str = $str.replace(this.RULE.reg, (match) => {
|
|
120
|
-
return match.replace(/~1D/g, '~D');
|
|
121
|
-
});
|
|
122
|
-
return $str;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
rule() {
|
|
126
|
-
// (?<protocol>\\w+:)\\/\\/
|
|
127
|
-
const ret = {
|
|
128
|
-
// lookbehind启用分组是为了和不兼容lookbehind的场景共用一个回调
|
|
129
|
-
begin: isLookbehindSupported() ? '((?<!\\\\))' : '(^|[^\\\\])',
|
|
130
|
-
content: [
|
|
131
|
-
'\\[([^\\n]*?)\\]', // ?<text>
|
|
132
|
-
'[ \\t]*', // any spaces
|
|
133
|
-
`${
|
|
134
|
-
'(?:' +
|
|
135
|
-
'\\(' +
|
|
136
|
-
/**
|
|
137
|
-
* allow double quotes
|
|
138
|
-
* e.g.
|
|
139
|
-
* [link](") ⭕️ valid
|
|
140
|
-
* [link]("") ⭕️ valid
|
|
141
|
-
* [link](()) ⭕️ valid
|
|
142
|
-
* [link](" ") ❌ invalid
|
|
143
|
-
*/
|
|
144
|
-
'((?:[^\\s()]*\\([^\\s()]*\\)[^\\s()]*)+|[^\\s)]+)' + // ?<link> url
|
|
145
|
-
'(?:[ \\t]((?:".*?")|(?:\'.*?\')))?' + // ?<title> optional
|
|
146
|
-
'\\)' +
|
|
147
|
-
'|' + // or
|
|
148
|
-
'\\[('
|
|
149
|
-
}${NOT_ALL_WHITE_SPACES_INLINE})\\]` + // ?<ref> global ref
|
|
150
|
-
')',
|
|
151
|
-
'(\\{target\\s*=\\s*(_blank|_parent|_self|_top)\\})?',
|
|
152
|
-
].join(''),
|
|
153
|
-
end: '',
|
|
154
|
-
};
|
|
155
|
-
// let ret = {begin:'((^|[^\\\\])\\*\\*|([\\s]|^)__)',
|
|
156
|
-
// end:'(\\*\\*([\\s\\S]|$)|__([\\s]|$))', content:'([^\\n]+?)'};
|
|
157
|
-
ret.reg = compileRegExp(ret, 'g');
|
|
158
|
-
return ret;
|
|
159
|
-
}
|
|
160
|
-
}
|
package/src/core/hooks/List.js
DELETED
|
@@ -1,264 +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
|
-
|
|
18
|
-
const INDENT_SPACE_NUM = 4; // commonmark default use 1~4 spaces for indent
|
|
19
|
-
const TAB_SPACE_NUM = 4; // 1 tab === 4 space
|
|
20
|
-
|
|
21
|
-
function attrsToAttributeString(object) {
|
|
22
|
-
if (typeof object !== 'object' && Object.keys(object).length < 1) {
|
|
23
|
-
return '';
|
|
24
|
-
}
|
|
25
|
-
const attrs = ['']; // 为了join一步到位
|
|
26
|
-
Object.keys(object).forEach((key) => {
|
|
27
|
-
attrs.push(`${key}="${object[key]}"`);
|
|
28
|
-
});
|
|
29
|
-
return attrs.join(' ');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function makeChecklist(text) {
|
|
33
|
-
return text.replace(/^((?:|[\t ]+)[*+-]\s+)\[(\s|x)\]/gm, (whole, pre, test) => {
|
|
34
|
-
const checkHtml = /\s/.test(test)
|
|
35
|
-
? '<span class="ch-icon ch-icon-square"></span>'
|
|
36
|
-
: '<span class="ch-icon ch-icon-check"></span>';
|
|
37
|
-
return `${pre}${checkHtml}`;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 缩进处理
|
|
42
|
-
function handleIndent(str, node) {
|
|
43
|
-
const indentRegex = /^(\t|[ ])/;
|
|
44
|
-
let $str = str;
|
|
45
|
-
while (indentRegex.test($str)) {
|
|
46
|
-
node.space += $str[0] === '\t' ? TAB_SPACE_NUM : 1;
|
|
47
|
-
$str = $str.replace(indentRegex, '');
|
|
48
|
-
}
|
|
49
|
-
return $str;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 序号样式处理
|
|
53
|
-
function getListStyle(m2) {
|
|
54
|
-
if (/^en-[a-z]/.test(m2)) {
|
|
55
|
-
return 'lower-alpha';
|
|
56
|
-
}
|
|
57
|
-
if (/^[a-z]/.test(m2)) {
|
|
58
|
-
return 'lower-greek';
|
|
59
|
-
}
|
|
60
|
-
if (/^[一二三四五六七八九十]/.test(m2)) {
|
|
61
|
-
return 'cjk-ideographic';
|
|
62
|
-
}
|
|
63
|
-
if (/^I/.test(m2)) {
|
|
64
|
-
return 'upper-roman';
|
|
65
|
-
}
|
|
66
|
-
if (/^\+/.test(m2)) {
|
|
67
|
-
return 'circle';
|
|
68
|
-
}
|
|
69
|
-
if (/^\*/.test(m2)) {
|
|
70
|
-
return 'square';
|
|
71
|
-
}
|
|
72
|
-
return 'default';
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 标识符处理
|
|
76
|
-
function handleMark(str, node) {
|
|
77
|
-
const listRegex =
|
|
78
|
-
/^((([*+-]|\d+[.]|en-[a-z]\.|[a-z]\.|[I一二三四五六七八九十]+\.)[ \t]+)([^\r]*?)($|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.]|en-[a-z]\.|[a-z]\.|[I一二三四五六七八九十]+\.)[ \t]+)))/;
|
|
79
|
-
if (!listRegex.test(str)) {
|
|
80
|
-
node.type = 'blank';
|
|
81
|
-
return str;
|
|
82
|
-
}
|
|
83
|
-
return str.replace(listRegex, (wholeMatch, m1, m2, m3, m4) => {
|
|
84
|
-
node.type = m2.search(/[*+-]/g) > -1 ? 'ul' : 'ol';
|
|
85
|
-
node.listStyle = getListStyle(m2);
|
|
86
|
-
node.start = Number(m2.replace('.', '')) ? Number(m2.replace('.', '')) : 1;
|
|
87
|
-
return m4;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
class Node {
|
|
92
|
-
// 列表树节点
|
|
93
|
-
constructor() {
|
|
94
|
-
this.index = 0;
|
|
95
|
-
this.space = 0;
|
|
96
|
-
this.type = '';
|
|
97
|
-
this.start = 1;
|
|
98
|
-
this.listStyle = '';
|
|
99
|
-
this.strs = [];
|
|
100
|
-
this.children = [];
|
|
101
|
-
this.lines = 0;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export default class List extends ParagraphBase {
|
|
106
|
-
static HOOK_NAME = 'list';
|
|
107
|
-
|
|
108
|
-
constructor({ config }) {
|
|
109
|
-
super({ needCache: true });
|
|
110
|
-
this.config = config || {};
|
|
111
|
-
this.tree = [];
|
|
112
|
-
this.emptyLines = 0;
|
|
113
|
-
this.indentSpace = Math.max(this.config.indentSpace, 2);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
addNode(node, current, parent, last) {
|
|
117
|
-
if (node.type === 'blank') {
|
|
118
|
-
this.tree[last].strs.push(node.strs[0]);
|
|
119
|
-
} else {
|
|
120
|
-
this.tree[parent].children.push(current);
|
|
121
|
-
this.tree[current] = {
|
|
122
|
-
...node,
|
|
123
|
-
parent,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
buildTree(html, sentenceMakeFunc) {
|
|
129
|
-
const items = html.split('\n');
|
|
130
|
-
this.tree = [];
|
|
131
|
-
items.unshift('');
|
|
132
|
-
// 列表结尾换行符个数
|
|
133
|
-
const endLineFlagLength = html.match(/\n*$/g)[0].length;
|
|
134
|
-
for (let i = 0; i < items.length - endLineFlagLength; i++) {
|
|
135
|
-
const node = new Node();
|
|
136
|
-
items[i] = handleIndent(items[i], node);
|
|
137
|
-
items[i] = handleMark(items[i], node);
|
|
138
|
-
node.strs.push(sentenceMakeFunc(items[i]).html);
|
|
139
|
-
node.index = i;
|
|
140
|
-
if (i === 0) {
|
|
141
|
-
// 根节点
|
|
142
|
-
node.space = -2;
|
|
143
|
-
this.tree.push(node);
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
let last = i - 1;
|
|
147
|
-
while (!this.tree[last]) last -= 1;
|
|
148
|
-
if (node.type === 'blank') {
|
|
149
|
-
this.addNode(node, i, this.tree[last].parent, last);
|
|
150
|
-
} else {
|
|
151
|
-
while (!this.tree[last] || this.tree[last].space > node.space) last -= 1;
|
|
152
|
-
const { space } = node;
|
|
153
|
-
const lastSpace = this.tree[last].space;
|
|
154
|
-
if (space < lastSpace + this.indentSpace) {
|
|
155
|
-
// 成为同级节点
|
|
156
|
-
if (this.config.listNested && this.tree[last].type !== node.type) {
|
|
157
|
-
this.addNode(node, i, last);
|
|
158
|
-
} else {
|
|
159
|
-
this.addNode(node, i, this.tree[last].parent);
|
|
160
|
-
}
|
|
161
|
-
} else if (space < lastSpace + this.indentSpace + INDENT_SPACE_NUM) {
|
|
162
|
-
// 成为子节点
|
|
163
|
-
this.addNode(node, i, last);
|
|
164
|
-
} else {
|
|
165
|
-
// 纯文本
|
|
166
|
-
node.type = 'blank';
|
|
167
|
-
this.addNode(node, i, this.tree[last].parent, last);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
renderSubTree(node, children, type) {
|
|
174
|
-
let lines = 0;
|
|
175
|
-
const attr = {};
|
|
176
|
-
const content = children.reduce((html, item) => {
|
|
177
|
-
const child = this.tree[item];
|
|
178
|
-
const itemAttr = {
|
|
179
|
-
class: 'cherry-list-item',
|
|
180
|
-
};
|
|
181
|
-
const str = `<p>${child.strs.join('<br>')}</p>`;
|
|
182
|
-
child.lines += this.getLineCount(child.strs.join('\n'));
|
|
183
|
-
const children = child.children.length ? this.renderTree(item) : '';
|
|
184
|
-
node.lines += child.lines;
|
|
185
|
-
lines += child.lines;
|
|
186
|
-
// checklist 样式适配
|
|
187
|
-
const checklistRegex = /<span class="ch-icon ch-icon-(square|check)"><\/span>/;
|
|
188
|
-
if (checklistRegex.test(str)) {
|
|
189
|
-
itemAttr.class += ' check-list-item';
|
|
190
|
-
}
|
|
191
|
-
return `${html}<li${attrsToAttributeString(itemAttr)}>${str}${children}</li>`;
|
|
192
|
-
}, '');
|
|
193
|
-
if (node.parent === undefined) {
|
|
194
|
-
// 根节点增加属性
|
|
195
|
-
attr['data-lines'] = node.index === 0 ? lines + this.emptyLines : lines;
|
|
196
|
-
attr['data-sign'] = this.sign;
|
|
197
|
-
}
|
|
198
|
-
if (children[0] && type === 'ol') {
|
|
199
|
-
attr.start = this.tree[children[0]].start;
|
|
200
|
-
}
|
|
201
|
-
attr.class = `cherry-list__${this.tree[children[0]].listStyle}`;
|
|
202
|
-
return `<${type}${attrsToAttributeString(attr)}>${content}</${type}>`;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
renderTree(current) {
|
|
206
|
-
let from = 0;
|
|
207
|
-
const node = this.tree[current];
|
|
208
|
-
const { children } = node;
|
|
209
|
-
const html = children.reduce((html, item, index) => {
|
|
210
|
-
if (index === 0) return html;
|
|
211
|
-
if (this.tree[children[index]].type === this.tree[children[index - 1]].type) {
|
|
212
|
-
return html;
|
|
213
|
-
}
|
|
214
|
-
const subTree = this.renderSubTree(node, children.slice(from, index), this.tree[children[index - 1]].type);
|
|
215
|
-
from = index;
|
|
216
|
-
return html + subTree;
|
|
217
|
-
}, '');
|
|
218
|
-
|
|
219
|
-
const childrenHtml = children.length
|
|
220
|
-
? this.renderSubTree(node, children.slice(from, children.length), this.tree[children[children.length - 1]].type)
|
|
221
|
-
: '';
|
|
222
|
-
|
|
223
|
-
return html + childrenHtml;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
toHtml(wholeMatch, sentenceMakeFunc) {
|
|
227
|
-
// 行数计算吸收的空行
|
|
228
|
-
this.emptyLines = wholeMatch.match(/^\n\n/)?.length ?? 0;
|
|
229
|
-
const text = wholeMatch.replace(/~0$/g, '').replace(/^\n+/, '');
|
|
230
|
-
this.buildTree(makeChecklist(text), sentenceMakeFunc);
|
|
231
|
-
const result = this.renderTree(0);
|
|
232
|
-
return this.pushCache(result, this.sign, this.$getLineNum(wholeMatch));
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
$getLineNum(str) {
|
|
236
|
-
const beginLine = str.match(/^\n\n/)?.length ?? 0;
|
|
237
|
-
const $str = str.replace(/^\n+/, '').replace(/\n+$/, '\n');
|
|
238
|
-
return $str.match(/\n/g)?.length ?? 0 + beginLine;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
makeHtml(str, sentenceMakeFunc) {
|
|
242
|
-
let $str = `${str}~0`;
|
|
243
|
-
if (this.test($str)) {
|
|
244
|
-
$str = $str.replace(this.RULE.reg, (wholeMatch) => {
|
|
245
|
-
return this.getCacheWithSpace(
|
|
246
|
-
this.checkCache(wholeMatch, sentenceMakeFunc, this.$getLineNum(wholeMatch)),
|
|
247
|
-
wholeMatch,
|
|
248
|
-
);
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
$str = $str.replace(/~0$/g, '');
|
|
252
|
-
return $str;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
rule() {
|
|
256
|
-
const ret = {
|
|
257
|
-
begin: '(?:^|\n)(\n*)(([ ]{0,3}([*+-]|\\d+[.]|en-[a-z]\\.|[a-z]\\.|[I一二三四五六七八九十]+\\.)[ \\t]+)',
|
|
258
|
-
content: '([^\\r]+?)',
|
|
259
|
-
end: '(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.]|en-[a-z]\\.|[a-z]\\.|[I一二三四五六七八九十]+\\.)[ \\t]+)))',
|
|
260
|
-
};
|
|
261
|
-
ret.reg = new RegExp(ret.begin + ret.content + ret.end, 'gm');
|
|
262
|
-
return ret;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
@@ -1,104 +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 { escapeFormulaPunctuations, LoadMathModule } from '@/utils/mathjax';
|
|
18
|
-
import { getHTML } from '@/utils/dom';
|
|
19
|
-
import { isBrowser } from '@/utils/env';
|
|
20
|
-
import { isLookbehindSupported } from '@/utils/regexp';
|
|
21
|
-
import { replaceLookbehind } from '@/utils/lookbehind-replace';
|
|
22
|
-
|
|
23
|
-
export default class MathBlock extends ParagraphBase {
|
|
24
|
-
static HOOK_NAME = 'mathBlock';
|
|
25
|
-
/**
|
|
26
|
-
* 块级公式语法
|
|
27
|
-
* 该语法具有排他性,并且需要优先其他段落级语法进行渲染
|
|
28
|
-
* @type {'katex' | 'MathJax' | 'node'}
|
|
29
|
-
*/
|
|
30
|
-
engine = 'MathJax'; // 渲染引擎,默认为MathJax,MathJax支持2.x与3.x版本
|
|
31
|
-
katex;
|
|
32
|
-
MathJax;
|
|
33
|
-
|
|
34
|
-
constructor({ config }) {
|
|
35
|
-
super({ needCache: true });
|
|
36
|
-
// 非浏览器环境下配置为 node
|
|
37
|
-
this.engine = isBrowser() ? config.engine ?? 'MathJax' : 'node';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
toHtml(wholeMatch, lineSpace, leadingChar, content) {
|
|
41
|
-
LoadMathModule.bind(this)('engine');
|
|
42
|
-
// 去掉开头的空字符,去掉结尾的换行符
|
|
43
|
-
const wholeMatchWithoutSpace = wholeMatch.replace(/^[ \f\r\t\v]*/, '').replace(/\s*$/, '');
|
|
44
|
-
// 去掉匹配到的第一个换行符
|
|
45
|
-
const lineSpaceWithoutPreSpace = lineSpace.replace(/^[ \f\r\t\v]*\n/, '');
|
|
46
|
-
const sign = this.$engine.hash(wholeMatch);
|
|
47
|
-
let lines = this.getLineCount(wholeMatchWithoutSpace, lineSpaceWithoutPreSpace);
|
|
48
|
-
// 判断公式是不是新行输入,如果不是新行,则行号减1
|
|
49
|
-
if (!/\n/.test(lineSpace)) {
|
|
50
|
-
lines -= 1;
|
|
51
|
-
}
|
|
52
|
-
// 判断公式后面有没有尾接内容,如果尾接了内容,则行号减1
|
|
53
|
-
if (!/\n\s*$/.test(wholeMatch)) {
|
|
54
|
-
lines -= 1;
|
|
55
|
-
}
|
|
56
|
-
// 目前的机制还没有测过lines为负数的情况,先不处理
|
|
57
|
-
lines = lines > 0 ? lines : 0;
|
|
58
|
-
|
|
59
|
-
// 既无MathJax又无katex时,原样输出
|
|
60
|
-
let result = '';
|
|
61
|
-
const $content = content.replace(/\\~D/g, '$').replace(/\\~T/g, '~').replace(/~T/g, '~');
|
|
62
|
-
|
|
63
|
-
if (this.engine === 'katex') {
|
|
64
|
-
// katex渲染
|
|
65
|
-
const html = this.katex.renderToString($content, {
|
|
66
|
-
throwOnError: false,
|
|
67
|
-
displayMode: true,
|
|
68
|
-
});
|
|
69
|
-
result = `<div data-sign="${sign}" class="Cherry-Math" data-type="mathBlock"
|
|
70
|
-
data-lines="${lines}">${html}</div>`;
|
|
71
|
-
} else if (this.MathJax?.tex2svg) {
|
|
72
|
-
// MathJax渲染
|
|
73
|
-
const svg = getHTML(this.MathJax.tex2svg($content), true);
|
|
74
|
-
result = `<div data-sign="${sign}" class="Cherry-Math" data-type="mathBlock"
|
|
75
|
-
data-lines="${lines}">${svg}</div>`;
|
|
76
|
-
} else {
|
|
77
|
-
result = `<div data-sign="${sign}" class="Cherry-Math" data-type="mathBlock"
|
|
78
|
-
data-lines="${lines}">$$${escapeFormulaPunctuations(content)}$$</div>`;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return leadingChar + this.getCacheWithSpace(this.pushCache(result, sign, lines), wholeMatch);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
beforeMakeHtml(str) {
|
|
85
|
-
if (isLookbehindSupported()) {
|
|
86
|
-
return str.replace(this.RULE.reg, this.toHtml.bind(this));
|
|
87
|
-
}
|
|
88
|
-
return replaceLookbehind(str, this.RULE.reg, this.toHtml.bind(this), true, 1);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
makeHtml(str) {
|
|
92
|
-
return str;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
rule() {
|
|
96
|
-
const ret = {
|
|
97
|
-
begin: isLookbehindSupported() ? '(\\s*)((?<!\\\\))~D~D\\s*' : '(\\s*)(^|[^\\\\])~D~D\\s*',
|
|
98
|
-
content: '([\\w\\W]*?)',
|
|
99
|
-
end: '(\\s*)~D~D(?:\\s{0,1})',
|
|
100
|
-
};
|
|
101
|
-
ret.reg = new RegExp(ret.begin + ret.content + ret.end, 'g');
|
|
102
|
-
return ret;
|
|
103
|
-
}
|
|
104
|
-
}
|
package/src/core/hooks/Panel.js
DELETED
|
@@ -1,145 +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 { prependLineFeedForParagraph } from '@/utils/lineFeed';
|
|
18
|
-
import { getPanelRule } from '@/utils/regexp';
|
|
19
|
-
import { blockNames } from '@/utils/sanitize';
|
|
20
|
-
/**
|
|
21
|
-
* 面板语法
|
|
22
|
-
* 例:
|
|
23
|
-
* :::tip
|
|
24
|
-
* 这是一段提示信息
|
|
25
|
-
* :::
|
|
26
|
-
* :::warning
|
|
27
|
-
* 这是一段警告信息
|
|
28
|
-
* :::
|
|
29
|
-
* :::danger
|
|
30
|
-
* 这是一段危险信息
|
|
31
|
-
* :::
|
|
32
|
-
*/
|
|
33
|
-
export default class Panel extends ParagraphBase {
|
|
34
|
-
static HOOK_NAME = 'panel';
|
|
35
|
-
|
|
36
|
-
constructor(options) {
|
|
37
|
-
super({ needCache: true });
|
|
38
|
-
this.initBrReg(options.globalConfig.classicBr);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
makeHtml(str, sentenceMakeFunc) {
|
|
42
|
-
return str.replace(this.RULE.reg, (match, preLines, name, content) => {
|
|
43
|
-
const lineCount = this.getLineCount(match, preLines);
|
|
44
|
-
const sign = this.$engine.hash(match);
|
|
45
|
-
const testHasCache = this.testHasCache(sign);
|
|
46
|
-
if (testHasCache !== false) {
|
|
47
|
-
return prependLineFeedForParagraph(match, testHasCache);
|
|
48
|
-
}
|
|
49
|
-
const { title, body, appendStyle, className } = this.$getPanelInfo(name, content, sentenceMakeFunc);
|
|
50
|
-
const ret = this.pushCache(
|
|
51
|
-
`<div class="${className}" data-sign="${sign}" data-lines="${lineCount}" ${appendStyle}>${title}${body}</div>`,
|
|
52
|
-
sign,
|
|
53
|
-
lineCount,
|
|
54
|
-
);
|
|
55
|
-
return prependLineFeedForParagraph(match, ret);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
$getClassByType(type) {
|
|
60
|
-
if (/(left|right|center)/i.test(type)) {
|
|
61
|
-
return `cherry-text-align cherry-text-align__${type}`;
|
|
62
|
-
}
|
|
63
|
-
return `cherry-panel cherry-panel__${type}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
$getPanelInfo(name, str, sentenceMakeFunc) {
|
|
67
|
-
const ret = {
|
|
68
|
-
type: this.$getTargetType(name),
|
|
69
|
-
title: sentenceMakeFunc(this.$getTitle(name)).html,
|
|
70
|
-
body: str,
|
|
71
|
-
appendStyle: '',
|
|
72
|
-
className: '',
|
|
73
|
-
};
|
|
74
|
-
ret.className = this.$getClassByType(ret.type);
|
|
75
|
-
if (/(left|right|center)/i.test(ret.type)) {
|
|
76
|
-
ret.appendStyle = `style="text-align:${ret.type};"`;
|
|
77
|
-
}
|
|
78
|
-
ret.title = `<div class="cherry-panel--title ${ret.title ? 'cherry-panel--title__not-empty' : ''}">${
|
|
79
|
-
ret.title
|
|
80
|
-
}</div>`;
|
|
81
|
-
const paragraphProcessor = (str) => {
|
|
82
|
-
if (str.trim() === '') {
|
|
83
|
-
return '';
|
|
84
|
-
}
|
|
85
|
-
// 调用行内语法,获得段落的签名和对应html内容
|
|
86
|
-
const { html } = sentenceMakeFunc(str);
|
|
87
|
-
let domName = 'p';
|
|
88
|
-
// 如果包含html块级标签(比如div、blockquote等),则当前段落外层用div包裹,反之用p包裹
|
|
89
|
-
const isContainBlockTest = new RegExp(`<(${blockNames})[^>]*>`, 'i');
|
|
90
|
-
if (isContainBlockTest.test(html)) {
|
|
91
|
-
domName = 'div';
|
|
92
|
-
}
|
|
93
|
-
return `<${domName}>${this.$cleanParagraph(html)}</${domName}>`;
|
|
94
|
-
};
|
|
95
|
-
let $body = '';
|
|
96
|
-
if (this.isContainsCache(ret.body)) {
|
|
97
|
-
$body = this.makeExcludingCached(ret.body, paragraphProcessor);
|
|
98
|
-
} else {
|
|
99
|
-
$body = paragraphProcessor(ret.body);
|
|
100
|
-
}
|
|
101
|
-
ret.body = `<div class="cherry-panel--body">${$body}</div>`;
|
|
102
|
-
return ret;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
$getTitle(name) {
|
|
106
|
-
const $name = name.trim();
|
|
107
|
-
return /\s/.test($name) ? $name.replace(/[^\s]+\s/, '') : '';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
$getTargetType(name) {
|
|
111
|
-
const $name = /\s/.test(name.trim()) ? name.trim().replace(/\s.*$/, '') : name;
|
|
112
|
-
switch ($name.trim().toLowerCase()) {
|
|
113
|
-
case 'primary':
|
|
114
|
-
case 'p':
|
|
115
|
-
return 'primary';
|
|
116
|
-
case 'info':
|
|
117
|
-
case 'i':
|
|
118
|
-
return 'info';
|
|
119
|
-
case 'warning':
|
|
120
|
-
case 'w':
|
|
121
|
-
return 'warning';
|
|
122
|
-
case 'danger':
|
|
123
|
-
case 'd':
|
|
124
|
-
return 'danger';
|
|
125
|
-
case 'success':
|
|
126
|
-
case 's':
|
|
127
|
-
return 'success';
|
|
128
|
-
case 'right':
|
|
129
|
-
case 'r':
|
|
130
|
-
return 'right';
|
|
131
|
-
case 'center':
|
|
132
|
-
case 'c':
|
|
133
|
-
return 'center';
|
|
134
|
-
case 'left':
|
|
135
|
-
case 'l':
|
|
136
|
-
return 'left';
|
|
137
|
-
default:
|
|
138
|
-
return 'primary';
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
rule() {
|
|
143
|
-
return getPanelRule();
|
|
144
|
-
}
|
|
145
|
-
}
|