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,100 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
import { getSelection } from '@/utils/selection';
|
|
18
|
+
|
|
19
|
+
export default class Size extends MenuBase {
|
|
20
|
+
constructor($cherry) {
|
|
21
|
+
super($cherry);
|
|
22
|
+
this.setName('size', 'format_size');
|
|
23
|
+
this.subMenuConfig = [
|
|
24
|
+
{ name: 'size-1', iconName: 'highlighter_size_1', onclick: this.bindSubClick.bind(this, '12') },
|
|
25
|
+
{ name: 'size-2', iconName: 'highlighter_size_2', onclick: this.bindSubClick.bind(this, '17') },
|
|
26
|
+
{ name: 'size-3', iconName: 'highlighter_size_3', onclick: this.bindSubClick.bind(this, '24') },
|
|
27
|
+
{ name: 'size-4', iconName: 'highlighter_size_4', onclick: this.bindSubClick.bind(this, '32') },
|
|
28
|
+
];
|
|
29
|
+
this.shortKeyMap = {
|
|
30
|
+
'Alt-1': '12',
|
|
31
|
+
'Alt-2': '17',
|
|
32
|
+
'Alt-3': '24',
|
|
33
|
+
'Alt-4': '32',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getSubMenuConfig() {
|
|
38
|
+
return this.subMenuConfig;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_getFlagStr(shortKey) {
|
|
42
|
+
const test = shortKey.replace(/[^0-9]+([0-9])/g, '$1');
|
|
43
|
+
let header = '#';
|
|
44
|
+
for (let i = 1; i < test; i++) {
|
|
45
|
+
header += '#';
|
|
46
|
+
}
|
|
47
|
+
return header;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
$testIsSize(selection) {
|
|
51
|
+
return /^\s*(![0-9]+) [\s\S]+!/.test(selection);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
$getSizeByShortKey(shortKey) {
|
|
55
|
+
if (/^[0-9]+$/.test(shortKey)) {
|
|
56
|
+
return shortKey;
|
|
57
|
+
}
|
|
58
|
+
return this.shortKeyMap[shortKey] || '17';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
onClick(selection, shortKey = '17') {
|
|
62
|
+
const size = this.$getSizeByShortKey(shortKey);
|
|
63
|
+
let $selection = getSelection(this.editor.editor, selection) || '字号';
|
|
64
|
+
// 如果选中的内容里有字号语法,则直接去掉该语法
|
|
65
|
+
if (!this.isSelections && !this.$testIsSize($selection)) {
|
|
66
|
+
this.getMoreSelection('!32 ', '!', () => {
|
|
67
|
+
const newSelection = this.editor.editor.getSelection();
|
|
68
|
+
if (this.$testIsSize(newSelection)) {
|
|
69
|
+
$selection = newSelection;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (this.$testIsSize($selection)) {
|
|
76
|
+
// 如果选中的内容里有字号语法,并且字号与目标一致,则去掉字号语法
|
|
77
|
+
// 反之,修改字号与目标一致
|
|
78
|
+
let needClean = true;
|
|
79
|
+
const tmp = $selection.replace(/(^)(\s*)(![0-9]+)([^\n]+)(!)(\s*)($)/gm, (w, m1, m2, m3, m4, m5, m6, m7) => {
|
|
80
|
+
needClean = needClean ? m3 === `!${size}` : false;
|
|
81
|
+
return `${m1}${m2}!${size}${m4}${m5}${m6}${m7}`;
|
|
82
|
+
});
|
|
83
|
+
if (needClean) {
|
|
84
|
+
return $selection.replace(/(^)(\s*)(![0-9]+\s*)([^\n]+)(!)(\s*)($)/gm, '$1$4$7');
|
|
85
|
+
}
|
|
86
|
+
this.registerAfterClickCb(() => {
|
|
87
|
+
this.setLessSelection(`!${size} `, '!');
|
|
88
|
+
});
|
|
89
|
+
return tmp;
|
|
90
|
+
}
|
|
91
|
+
this.registerAfterClickCb(() => {
|
|
92
|
+
this.setLessSelection(`!${size} `, '!');
|
|
93
|
+
});
|
|
94
|
+
return $selection.replace(/(^)([^\n]+)($)/gm, `$1!${size} $2!$3`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get shortcutKeys() {
|
|
98
|
+
return ['Alt-1', 'Alt-2', 'Alt-3', 'Alt-4'];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
/**
|
|
18
|
+
* 工具栏里的分割线,用来切分不同类型按钮的区域
|
|
19
|
+
* 一个实例中可以配置多个分割线
|
|
20
|
+
*/
|
|
21
|
+
export default class Split extends MenuBase {
|
|
22
|
+
constructor($cherry) {
|
|
23
|
+
super($cherry);
|
|
24
|
+
this.setName('split', '|');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 重载创建按钮逻辑
|
|
29
|
+
* @returns {HTMLElement} 分割线标签
|
|
30
|
+
*/
|
|
31
|
+
createBtn() {
|
|
32
|
+
const className = 'cherry-toolbar-button cherry-toolbar-split';
|
|
33
|
+
const i = document.createElement('i');
|
|
34
|
+
i.className = className;
|
|
35
|
+
return i;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
import { getSelection } from '@/utils/selection';
|
|
18
|
+
/**
|
|
19
|
+
* 删除线的按钮
|
|
20
|
+
*/
|
|
21
|
+
export default class Strikethrough extends MenuBase {
|
|
22
|
+
constructor($cherry) {
|
|
23
|
+
super($cherry);
|
|
24
|
+
this.setName('strikethrough', 'format_strikethrough');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$testIsStrike(selection) {
|
|
28
|
+
return /(~~)[\s\S]+(\1)/.test(selection);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param {string} selection 被用户选中的文本内容
|
|
34
|
+
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
35
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
36
|
+
*/
|
|
37
|
+
onClick(selection, shortKey = '') {
|
|
38
|
+
let $selection = getSelection(this.editor.editor, selection) || this.locale.strikethrough;
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
const needWhitespace = this.$cherry?.options?.engine?.syntax?.strikethrough?.needWhitespace;
|
|
41
|
+
const space = needWhitespace ? ' ' : '';
|
|
42
|
+
// 如果被选中的文本中包含删除线语法,则去掉删除线语法
|
|
43
|
+
if (!this.isSelections && !this.$testIsStrike($selection)) {
|
|
44
|
+
this.getMoreSelection(`${space}~~`, `~~${space}`, () => {
|
|
45
|
+
const newSelection = this.editor.editor.getSelection();
|
|
46
|
+
const isStrike = this.$testIsStrike(newSelection);
|
|
47
|
+
if (isStrike) {
|
|
48
|
+
$selection = newSelection;
|
|
49
|
+
}
|
|
50
|
+
return isStrike;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (this.$testIsStrike($selection)) {
|
|
54
|
+
return selection.replace(/[\s]*(~~)([\s\S]+)(\1)[\s]*/g, '$2');
|
|
55
|
+
}
|
|
56
|
+
this.registerAfterClickCb(() => {
|
|
57
|
+
this.setLessSelection(`${space}~~`, `~~${space}`);
|
|
58
|
+
});
|
|
59
|
+
return $selection.replace(/(^)[\s]*([\s\S]+?)[\s]*($)/g, `$1${space}~~$2~~${space}$3`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get shortcutKeys() {
|
|
63
|
+
return ['Ctrl-d'];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
import { getSelection } from '@/utils/selection';
|
|
18
|
+
/**
|
|
19
|
+
* 下标的按钮
|
|
20
|
+
**/
|
|
21
|
+
export default class Sub extends MenuBase {
|
|
22
|
+
constructor($cherry) {
|
|
23
|
+
super($cherry);
|
|
24
|
+
this.setName('sub', 'subscript');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$testIsSub(selection) {
|
|
28
|
+
return /^\s*(\^\^)[\s\S]+(\1)/.test(selection);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param {string} selection 被用户选中的文本内容
|
|
34
|
+
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
35
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
36
|
+
*/
|
|
37
|
+
onClick(selection, shortKey = '') {
|
|
38
|
+
let $selection = getSelection(this.editor.editor, selection) || this.locale.sub;
|
|
39
|
+
// 如果选中的内容里有下标的语法,则认为是要去掉下标语法
|
|
40
|
+
if (!this.isSelections && !this.$testIsSub($selection)) {
|
|
41
|
+
this.getMoreSelection('^^', '^^', () => {
|
|
42
|
+
const newSelection = this.editor.editor.getSelection();
|
|
43
|
+
const isSub = this.$testIsSub(newSelection);
|
|
44
|
+
if (isSub) {
|
|
45
|
+
$selection = newSelection;
|
|
46
|
+
}
|
|
47
|
+
return isSub;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (this.$testIsSub($selection)) {
|
|
51
|
+
return $selection.replace(/(^)(\s*)(\^\^)([^\n]+)(\3)(\s*)($)/gm, '$1$4$7');
|
|
52
|
+
}
|
|
53
|
+
this.registerAfterClickCb(() => {
|
|
54
|
+
this.setLessSelection('^^', '^^');
|
|
55
|
+
});
|
|
56
|
+
return $selection.replace(/(^)([^\n]+)($)/gm, '$1^^$2^^$3');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
import { getSelection } from '@/utils/selection';
|
|
18
|
+
/**
|
|
19
|
+
* 上标的按钮
|
|
20
|
+
**/
|
|
21
|
+
export default class Sup extends MenuBase {
|
|
22
|
+
constructor($cherry) {
|
|
23
|
+
super($cherry);
|
|
24
|
+
this.setName('sup', 'superscript');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$testIsSup(selection) {
|
|
28
|
+
return /^\s*(\^)[\s\S]+(\1)/.test(selection);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param {string} selection 被用户选中的文本内容
|
|
34
|
+
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
35
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
36
|
+
*/
|
|
37
|
+
onClick(selection, shortKey = '') {
|
|
38
|
+
let $selection = getSelection(this.editor.editor, selection) || this.locale.sup;
|
|
39
|
+
// 如果选中的内容里有上标的语法,则认为是要去掉上标语法
|
|
40
|
+
if (!this.isSelections && !this.$testIsSup($selection)) {
|
|
41
|
+
this.getMoreSelection('^', '^', () => {
|
|
42
|
+
const newSelection = this.editor.editor.getSelection();
|
|
43
|
+
const isSup = this.$testIsSup(newSelection);
|
|
44
|
+
if (isSup) {
|
|
45
|
+
$selection = newSelection;
|
|
46
|
+
}
|
|
47
|
+
return isSup;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (this.$testIsSup($selection)) {
|
|
51
|
+
return selection.replace(/(^)(\s*)(\^)([^\n]+)(\3)(\s*)($)/gm, '$1$4$7');
|
|
52
|
+
}
|
|
53
|
+
this.registerAfterClickCb(() => {
|
|
54
|
+
this.setLessSelection('^', '^');
|
|
55
|
+
});
|
|
56
|
+
return $selection.replace(/(^)([^\n]+)($)/gm, '$1^$2^$3');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
import Event from '@/Event';
|
|
18
|
+
/**
|
|
19
|
+
* 切换预览/编辑模式的按钮
|
|
20
|
+
* 该按钮不支持切换到双栏编辑模式
|
|
21
|
+
* 只能切换成纯编辑模式和纯预览模式
|
|
22
|
+
**/
|
|
23
|
+
export default class SwitchModel extends MenuBase {
|
|
24
|
+
constructor($cherry) {
|
|
25
|
+
super($cherry);
|
|
26
|
+
this.setName('switchPreview', 'preview');
|
|
27
|
+
this.instanceId = $cherry.instanceId;
|
|
28
|
+
this.attachEventListeners();
|
|
29
|
+
this.model = $cherry.model;
|
|
30
|
+
this.prevModel = this.model;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get isHidden() {
|
|
34
|
+
return this.$previewerHidden;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
set isHidden(state) {
|
|
38
|
+
// 节流
|
|
39
|
+
if (state === this.$previewerHidden) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const icon = this.dom.querySelector('i');
|
|
43
|
+
// 隐藏预览,按钮状态为打开预览
|
|
44
|
+
if (state) {
|
|
45
|
+
icon.innerText = 'preview';
|
|
46
|
+
icon.title = this.locale.switchPreview;
|
|
47
|
+
} else {
|
|
48
|
+
icon.innerText = 'preview_off';
|
|
49
|
+
icon.title = this.locale.switchEdit;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.$previewerHidden = state;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
attachEventListeners() {
|
|
56
|
+
Event.on(this.instanceId, Event.Events.modelChange, ([model]) => {
|
|
57
|
+
this.prevModel = this.model;
|
|
58
|
+
this.model = model;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
onClick() {
|
|
63
|
+
// const toolbar = this.dom.parentElement.parentElement;
|
|
64
|
+
if (this.model !== 'previewOnly') {
|
|
65
|
+
this.$cherry.switchModel('previewOnly', true);
|
|
66
|
+
// toolbar.classList.add('preview-only');
|
|
67
|
+
this.isHidden = false;
|
|
68
|
+
} else {
|
|
69
|
+
// toolbar.classList.remove('preview-only');
|
|
70
|
+
if (this.prevModel === 'edit&preview') {
|
|
71
|
+
this.$cherry.switchModel('edit&preview', true);
|
|
72
|
+
} else if (this.prevModel === 'editOnly') {
|
|
73
|
+
this.$cherry.switchModel('editOnly', true);
|
|
74
|
+
}
|
|
75
|
+
this.isHidden = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
import BubbleTableMenu from '@/toolbars/BubbleTable';
|
|
18
|
+
/**
|
|
19
|
+
* 插入普通表格
|
|
20
|
+
*/
|
|
21
|
+
export default class Table extends MenuBase {
|
|
22
|
+
constructor($cherry) {
|
|
23
|
+
super($cherry);
|
|
24
|
+
this.setName('table', 'table');
|
|
25
|
+
|
|
26
|
+
this.subBubbleTableMenu = new BubbleTableMenu({ row: 9, col: 9 });
|
|
27
|
+
$cherry.editor.options.wrapperDom.appendChild(this.subBubbleTableMenu.dom);
|
|
28
|
+
this.catchOnce = '';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 响应点击事件
|
|
33
|
+
* @param {string} selection 被用户选中的文本内容
|
|
34
|
+
* @returns {*} 回填到编辑器光标位置/选中文本区域的内容
|
|
35
|
+
*/
|
|
36
|
+
onClick(selection, shortKey = '') {
|
|
37
|
+
// 如果二维面板处于隐藏状态,说明是第一次点击
|
|
38
|
+
if (this.subBubbleTableMenu.dom.style.display === 'none' || !this.hasCacheOnce()) {
|
|
39
|
+
// 插入表格,会出现一个二维面板,用户可以通过点击决定插入表格的行号和列号
|
|
40
|
+
const pos = this.dom.getBoundingClientRect();
|
|
41
|
+
this.subBubbleTableMenu.dom.style.left = `${pos.left + pos.width}px`;
|
|
42
|
+
this.subBubbleTableMenu.dom.style.top = `${pos.top + pos.height}px`;
|
|
43
|
+
this.subBubbleTableMenu.show((row, col) => {
|
|
44
|
+
const headerText = ' Header |'.repeat(col);
|
|
45
|
+
const controlText = ' ------ |'.repeat(col);
|
|
46
|
+
const rowText = `\n|${' Sample |'.repeat(col)}`;
|
|
47
|
+
const final = `${selection}\n\n|${headerText}\n|${controlText}${rowText.repeat(row)}\n\n`;
|
|
48
|
+
this.setCacheOnce(final);
|
|
49
|
+
this.fire(null);
|
|
50
|
+
});
|
|
51
|
+
this.updateMarkdown = false;
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return this.getAndCleanCacheOnce();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
/**
|
|
18
|
+
* 插入目录
|
|
19
|
+
*/
|
|
20
|
+
export default class Toc extends MenuBase {
|
|
21
|
+
constructor($cherry) {
|
|
22
|
+
super($cherry);
|
|
23
|
+
this.setName('toc', 'toc');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 响应点击事件
|
|
28
|
+
* @param {string} selection 被用户选中的文本内容
|
|
29
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
30
|
+
*/
|
|
31
|
+
onClick(selection, shortKey = '') {
|
|
32
|
+
// 插入目录
|
|
33
|
+
return `${selection}\n\n[[toc]]\n`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
import Event from '@/Event';
|
|
18
|
+
/**
|
|
19
|
+
* 关闭/展示预览区域的按钮
|
|
20
|
+
*/
|
|
21
|
+
export default class TogglePreview extends MenuBase {
|
|
22
|
+
/** @type {boolean} 当前预览状态 */
|
|
23
|
+
$previewerHidden = false;
|
|
24
|
+
|
|
25
|
+
constructor($cherry) {
|
|
26
|
+
super($cherry);
|
|
27
|
+
this.setName('previewClose', 'splitscreen_right');
|
|
28
|
+
this.instanceId = $cherry.instanceId;
|
|
29
|
+
this.updateMarkdown = false;
|
|
30
|
+
this.attachEventListeners();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 绑定预览事件
|
|
35
|
+
*/
|
|
36
|
+
attachEventListeners() {
|
|
37
|
+
Event.on(this.instanceId, Event.Events.previewerClose, () => {
|
|
38
|
+
this.isHidden = true;
|
|
39
|
+
});
|
|
40
|
+
Event.on(this.instanceId, Event.Events.previewerOpen, () => {
|
|
41
|
+
this.isHidden = false;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get isHidden() {
|
|
46
|
+
return this.$previewerHidden;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
set isHidden(state) {
|
|
50
|
+
// 节流
|
|
51
|
+
if (state === this.$previewerHidden) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const icon = this.dom.querySelector('i');
|
|
55
|
+
// 隐藏预览,按钮状态为打开预览
|
|
56
|
+
if (state) {
|
|
57
|
+
icon.innerText = 'splitscreen_right';
|
|
58
|
+
icon.title = this.locale.togglePreview;
|
|
59
|
+
} else {
|
|
60
|
+
icon.innerText = 'web_asset';
|
|
61
|
+
icon.title = this.locale.previewClose;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.$previewerHidden = state;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 响应点击事件
|
|
69
|
+
*/
|
|
70
|
+
onClick() {
|
|
71
|
+
if (this.editor.previewer.isPreviewerHidden()) {
|
|
72
|
+
this.$cherry.switchModel('edit&preview');
|
|
73
|
+
this.isHidden = false;
|
|
74
|
+
} else {
|
|
75
|
+
this.$cherry.switchModel('editOnly');
|
|
76
|
+
this.isHidden = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
import { getSelection } from '@/utils/selection';
|
|
18
|
+
import { getListFromStr } from '@/utils/regexp';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 下标的按钮
|
|
22
|
+
**/
|
|
23
|
+
export default class Ul extends MenuBase {
|
|
24
|
+
constructor($cherry) {
|
|
25
|
+
super($cherry);
|
|
26
|
+
this.setName('ul', 'list');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {string} selection 被用户选中的文本内容
|
|
32
|
+
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
33
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
34
|
+
*/
|
|
35
|
+
onClick(selection, shortKey = '') {
|
|
36
|
+
const $selection = getSelection(this.editor.editor, selection, 'line', true) || 'Item 1\n Item 1.1\nItem 2';
|
|
37
|
+
const [before] = $selection.match(/^\n*/);
|
|
38
|
+
const [after] = $selection.match(/\n*$/);
|
|
39
|
+
return `${before}${getListFromStr($selection, 'ul')}${after}`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 MenuBase from '@/toolbars/MenuBase';
|
|
17
|
+
/**
|
|
18
|
+
* 下划线按钮
|
|
19
|
+
**/
|
|
20
|
+
export default class Underline extends MenuBase {
|
|
21
|
+
constructor($cherry) {
|
|
22
|
+
super($cherry);
|
|
23
|
+
this.setName('underline', 'format_underlined');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
$testIsUnderline(selection) {
|
|
27
|
+
return /^\s*(\/)[\s\S]+(\1)/.test(selection);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {string} selection 被用户选中的文本内容
|
|
33
|
+
* @param {string} shortKey 快捷键参数,本函数不处理这个参数
|
|
34
|
+
* @returns {string} 回填到编辑器光标位置/选中文本区域的内容
|
|
35
|
+
*/
|
|
36
|
+
onClick(selection, shortKey = '') {
|
|
37
|
+
let $selection = selection ? selection : this.locale.underline;
|
|
38
|
+
// 如果选中的内容里有下划线语法,则认为是要去掉下划线语法
|
|
39
|
+
if (!this.isSelections && !this.$testIsUnderline($selection)) {
|
|
40
|
+
this.getMoreSelection(' /', '/ ', () => {
|
|
41
|
+
const newSelection = this.editor.editor.getSelection();
|
|
42
|
+
const isUnderline = this.$testIsUnderline(newSelection);
|
|
43
|
+
if (isUnderline) {
|
|
44
|
+
$selection = newSelection;
|
|
45
|
+
}
|
|
46
|
+
return isUnderline;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (this.$testIsUnderline($selection)) {
|
|
50
|
+
return $selection.replace(/(^)(\s*)(\/)([^\n]+)(\3)(\s*)($)/gm, '$1$4$7');
|
|
51
|
+
}
|
|
52
|
+
this.registerAfterClickCb(() => {
|
|
53
|
+
this.setLessSelection(' /', '/ ');
|
|
54
|
+
});
|
|
55
|
+
// 如果选中的内容里没有下划线语法,则加上下划线
|
|
56
|
+
return $selection.replace(/(^)([^\n]+)($)/gm, '$1 /$2/ $3');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 声明绑定的快捷键,快捷键触发onClick
|
|
61
|
+
*/
|
|
62
|
+
get shortcutKeys() {
|
|
63
|
+
return ['Ctrl-u'];
|
|
64
|
+
}
|
|
65
|
+
}
|