@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.
Files changed (327) hide show
  1. package/README.md +2 -2
  2. package/dist/addons/advance/cherry-table-echarts-plugin.js +1 -1
  3. package/dist/addons/cherry-code-block-mermaid-plugin.js +1 -1
  4. package/dist/cherry-markdown.core.common.js +1 -1
  5. package/dist/cherry-markdown.core.js +1 -1
  6. package/dist/cherry-markdown.engine.core.common.js +1 -1
  7. package/dist/cherry-markdown.engine.core.esm.js +1 -1
  8. package/dist/cherry-markdown.engine.core.js +1 -1
  9. package/dist/cherry-markdown.esm.js +1 -1
  10. package/dist/cherry-markdown.js +1 -1
  11. package/dist/cherry-markdown.min.js +1 -1
  12. package/dist/fonts/ch-icon.eot +0 -0
  13. package/dist/fonts/ch-icon.ttf +0 -0
  14. package/dist/fonts/ch-icon.woff +0 -0
  15. package/dist/fonts/ch-icon.woff2 +0 -0
  16. package/package.json +1 -3
  17. package/src/Cherry.config.js +0 -634
  18. package/src/Cherry.js +0 -1104
  19. package/src/CherryStatic.js +0 -70
  20. package/src/Editor.js +0 -748
  21. package/src/Engine.js +0 -402
  22. package/src/Event.js +0 -140
  23. package/src/Factory.js +0 -180
  24. package/src/Logger.js +0 -31
  25. package/src/Previewer.js +0 -1192
  26. package/src/Sanitizer.js +0 -4
  27. package/src/Sanitizer.node.js +0 -7
  28. package/src/UrlCache.js +0 -98
  29. package/src/addons/advance/cherry-table-echarts-plugin.js +0 -170
  30. package/src/addons/cherry-code-block-mermaid-plugin.js +0 -158
  31. package/src/addons/cherry-code-block-plantuml-plugin.js +0 -106
  32. package/src/core/HookCenter.js +0 -297
  33. package/src/core/HooksConfig.js +0 -105
  34. package/src/core/ParagraphBase.js +0 -332
  35. package/src/core/SentenceBase.js +0 -65
  36. package/src/core/SyntaxBase.js +0 -194
  37. package/src/core/hooks/AutoLink.js +0 -232
  38. package/src/core/hooks/BackgroundColor.js +0 -46
  39. package/src/core/hooks/Blockquote.js +0 -70
  40. package/src/core/hooks/Br.js +0 -85
  41. package/src/core/hooks/CodeBlock.js +0 -456
  42. package/src/core/hooks/Color.js +0 -46
  43. package/src/core/hooks/CommentReference.js +0 -96
  44. package/src/core/hooks/Detail.js +0 -108
  45. package/src/core/hooks/Emoji.config.js +0 -1825
  46. package/src/core/hooks/Emoji.js +0 -119
  47. package/src/core/hooks/Emphasis.js +0 -113
  48. package/src/core/hooks/Footnote.js +0 -125
  49. package/src/core/hooks/FrontMatter.js +0 -51
  50. package/src/core/hooks/Header.js +0 -234
  51. package/src/core/hooks/HighLight.js +0 -37
  52. package/src/core/hooks/Hr.js +0 -52
  53. package/src/core/hooks/HtmlBlock.js +0 -199
  54. package/src/core/hooks/Image.js +0 -174
  55. package/src/core/hooks/InlineCode.js +0 -48
  56. package/src/core/hooks/InlineMath.js +0 -108
  57. package/src/core/hooks/Link.js +0 -160
  58. package/src/core/hooks/List.js +0 -264
  59. package/src/core/hooks/MathBlock.js +0 -104
  60. package/src/core/hooks/Panel.js +0 -145
  61. package/src/core/hooks/Paragraph.js +0 -84
  62. package/src/core/hooks/Ruby.js +0 -34
  63. package/src/core/hooks/Size.js +0 -51
  64. package/src/core/hooks/Strikethrough.js +0 -54
  65. package/src/core/hooks/Sub.js +0 -47
  66. package/src/core/hooks/SuggestList.js +0 -333
  67. package/src/core/hooks/Suggester.js +0 -707
  68. package/src/core/hooks/Sup.js +0 -47
  69. package/src/core/hooks/Table.js +0 -275
  70. package/src/core/hooks/Toc.js +0 -292
  71. package/src/core/hooks/Transfer.js +0 -47
  72. package/src/core/hooks/Underline.js +0 -37
  73. package/src/index.core.js +0 -29
  74. package/src/index.engine.core.js +0 -68
  75. package/src/index.engine.js +0 -28
  76. package/src/index.js +0 -32
  77. package/src/libs/mermaidAPI.8.4.8.js +0 -1
  78. package/src/libs/mermaidAPI.8.5.2.js +0 -42
  79. package/src/libs/rawdeflate.js +0 -1663
  80. package/src/locales/en_US.js +0 -139
  81. package/src/locales/index.js +0 -25
  82. package/src/locales/ru_RU.js +0 -139
  83. package/src/locales/zh_CN.js +0 -142
  84. package/src/sass/base.scss +0 -26
  85. package/src/sass/bubble_formula.scss +0 -166
  86. package/src/sass/ch-icon.scss +0 -118
  87. package/src/sass/cherry.scss +0 -1116
  88. package/src/sass/components/bubble.scss +0 -173
  89. package/src/sass/components/shortcut_key_config.scss +0 -108
  90. package/src/sass/formula_utils_bubble.scss +0 -82
  91. package/src/sass/icon_template.scss +0 -24
  92. package/src/sass/icons/uEA03-list.svg +0 -19
  93. package/src/sass/icons/uEA04-check.svg +0 -14
  94. package/src/sass/icons/uEA09-square.svg +0 -10
  95. package/src/sass/icons/uEA0A-bold.svg +0 -20
  96. package/src/sass/icons/uEA0B-code.svg +0 -18
  97. package/src/sass/icons/uEA0C-color.svg +0 -13
  98. package/src/sass/icons/uEA0D-header.svg +0 -8
  99. package/src/sass/icons/uEA0E-image.svg +0 -15
  100. package/src/sass/icons/uEA0F-italic.svg +0 -8
  101. package/src/sass/icons/uEA10-link.svg +0 -16
  102. package/src/sass/icons/uEA11-ol.svg +0 -21
  103. package/src/sass/icons/uEA12-size.svg +0 -11
  104. package/src/sass/icons/uEA13-strike.svg +0 -16
  105. package/src/sass/icons/uEA14-table.svg +0 -12
  106. package/src/sass/icons/uEA15-ul.svg +0 -17
  107. package/src/sass/icons/uEA16-underline.svg +0 -13
  108. package/src/sass/icons/uEA17-word.svg +0 -16
  109. package/src/sass/icons/uEA18-blockquote.svg +0 -11
  110. package/src/sass/icons/uEA19-font.svg +0 -10
  111. package/src/sass/icons/uEA1F-insertClass.svg +0 -39
  112. package/src/sass/icons/uEA20-insertFlow.svg +0 -8
  113. package/src/sass/icons/uEA21-insertFormula.svg +0 -23
  114. package/src/sass/icons/uEA22-insertGantt.svg +0 -13
  115. package/src/sass/icons/uEA23-insertGraph.svg +0 -13
  116. package/src/sass/icons/uEA24-insertPie.svg +0 -19
  117. package/src/sass/icons/uEA25-insertSeq.svg +0 -20
  118. package/src/sass/icons/uEA26-insertState.svg +0 -35
  119. package/src/sass/icons/uEA27-line.svg +0 -11
  120. package/src/sass/icons/uEA28-preview.svg +0 -18
  121. package/src/sass/icons/uEA29-previewClose.svg +0 -24
  122. package/src/sass/icons/uEA2A-toc.svg +0 -24
  123. package/src/sass/icons/uEA2D-sub.svg +0 -15
  124. package/src/sass/icons/uEA2E-sup.svg +0 -15
  125. package/src/sass/icons/uEA2F-h1.svg +0 -16
  126. package/src/sass/icons/uEA30-h2.svg +0 -20
  127. package/src/sass/icons/uEA31-h3.svg +0 -23
  128. package/src/sass/icons/uEA32-h4.svg +0 -16
  129. package/src/sass/icons/uEA33-h5.svg +0 -20
  130. package/src/sass/icons/uEA34-h6.svg +0 -17
  131. package/src/sass/icons/uEA35-video.svg +0 -20
  132. package/src/sass/icons/uEA36-insert.svg +0 -25
  133. package/src/sass/icons/uEA37-little_table.svg +0 -30
  134. package/src/sass/icons/uEA38-pdf.svg +0 -27
  135. package/src/sass/icons/uEA39-checklist.svg +0 -22
  136. package/src/sass/icons/uEA40-close.svg +0 -12
  137. package/src/sass/icons/uEA41-fullscreen.svg +0 -81
  138. package/src/sass/icons/uEA42-minscreen.svg +0 -77
  139. package/src/sass/icons/uEA43-insertChart.svg +0 -23
  140. package/src/sass/icons/uEA44-question.svg +0 -25
  141. package/src/sass/icons/uEA45-settings.svg +0 -32
  142. package/src/sass/icons/uEA46-ok.svg +0 -7
  143. package/src/sass/icons/uEA47-br.svg +0 -22
  144. package/src/sass/icons/uEA48-normal.svg +0 -15
  145. package/src/sass/icons/uEA49-undo.svg +0 -19
  146. package/src/sass/icons/uEA50-redo.svg +0 -21
  147. package/src/sass/icons/uEA51-copy.svg +0 -6
  148. package/src/sass/icons/uEA52-phone.svg +0 -5
  149. package/src/sass/icons/uEA53-cherry-table-delete.svg +0 -17
  150. package/src/sass/icons/uEA54-cherry-table-insert-bottom.svg +0 -16
  151. package/src/sass/icons/uEA55-cherry-table-insert-left.svg +0 -15
  152. package/src/sass/icons/uEA56-cherry-table-insert-right.svg +0 -16
  153. package/src/sass/icons/uEA57-cherry-table-insert-top.svg +0 -16
  154. package/src/sass/icons/uEA58-sort-s.svg +0 -13
  155. package/src/sass/icons/uEA59-pinyin.svg +0 -1
  156. package/src/sass/icons/uEA5A-create.svg +0 -24
  157. package/src/sass/icons/uEA5B-download.svg +0 -34
  158. package/src/sass/icons/uEA5C-edit.svg +0 -3
  159. package/src/sass/icons/uEA5D-export.svg +0 -53
  160. package/src/sass/icons/uEA5E-folder-open.svg +0 -3
  161. package/src/sass/icons/uEA5F-folder.svg +0 -3
  162. package/src/sass/icons/uEA60-help.svg +0 -5
  163. package/src/sass/icons/uEA61-pen-fill.svg +0 -13
  164. package/src/sass/icons/uEA62-pen.svg +0 -3
  165. package/src/sass/icons/uEA64-tips.svg +0 -5
  166. package/src/sass/icons/uEA65-warn.svg +0 -5
  167. package/src/sass/icons/uEA66-mistake.svg +0 -4
  168. package/src/sass/icons/uEA67-success.svg +0 -4
  169. package/src/sass/icons/uEA68-danger.svg +0 -4
  170. package/src/sass/icons/uEA69-info.svg +0 -5
  171. package/src/sass/icons/uEA6A-primary.svg +0 -5
  172. package/src/sass/icons/uEA6B-warning.svg +0 -5
  173. package/src/sass/icons/uEA6C-justify.svg +0 -19
  174. package/src/sass/icons/uEA6D-justifyCenter.svg +0 -19
  175. package/src/sass/icons/uEA6E-justifyLeft.svg +0 -19
  176. package/src/sass/icons/uEA6F-justifyRight.svg +0 -19
  177. package/src/sass/icons/uEA70-chevronsLeft.svg +0 -1
  178. package/src/sass/icons/uEA71-chevronsRight.svg +0 -1
  179. package/src/sass/icons/uEA72-trendingUp.svg +0 -1
  180. package/src/sass/icons/uEA74-codeBlock.svg +0 -1
  181. package/src/sass/icons/uEA75-expand.svg +0 -3
  182. package/src/sass/icons/uEA76-unExpand.svg +0 -3
  183. package/src/sass/icons/uEA77-swap-vert.svg +0 -1
  184. package/src/sass/icons/uEA78-swap.svg +0 -1
  185. package/src/sass/icons/uEA79-keyboard.svg +0 -1
  186. package/src/sass/icons/uEA7A-command.svg +0 -1
  187. package/src/sass/icons/uEA7B-search.svg +0 -1
  188. package/src/sass/index.scss +0 -3
  189. package/src/sass/markdown.scss +0 -668
  190. package/src/sass/markdown_pure.scss +0 -9
  191. package/src/sass/prettyprint/prettyprint.scss +0 -118
  192. package/src/sass/previewer.scss +0 -179
  193. package/src/sass/print.scss +0 -13
  194. package/src/sass/prism/coy.scss +0 -220
  195. package/src/sass/prism/dark.scss +0 -132
  196. package/src/sass/prism/default.scss +0 -143
  197. package/src/sass/prism/funky.scss +0 -133
  198. package/src/sass/prism/okaidia.scss +0 -126
  199. package/src/sass/prism/one-dark.scss +0 -440
  200. package/src/sass/prism/one-light.scss +0 -428
  201. package/src/sass/prism/solarized-light.scss +0 -153
  202. package/src/sass/prism/tomorrow-night.scss +0 -125
  203. package/src/sass/prism/twilight.scss +0 -202
  204. package/src/sass/prism/vs-dark.scss +0 -275
  205. package/src/sass/prism/vs-light.scss +0 -168
  206. package/src/sass/themes/blue.scss +0 -411
  207. package/src/sass/themes/dark.scss +0 -517
  208. package/src/sass/themes/default.scss +0 -255
  209. package/src/sass/themes/green.scss +0 -395
  210. package/src/sass/themes/light.scss +0 -368
  211. package/src/sass/themes/red.scss +0 -397
  212. package/src/sass/themes/violet.scss +0 -410
  213. package/src/sass/variable.scss +0 -84
  214. package/src/toolbars/Bubble.js +0 -234
  215. package/src/toolbars/BubbleFormula.js +0 -298
  216. package/src/toolbars/BubbleTable.js +0 -147
  217. package/src/toolbars/FloatMenu.js +0 -131
  218. package/src/toolbars/HiddenToolbar.js +0 -36
  219. package/src/toolbars/HookCenter.js +0 -231
  220. package/src/toolbars/MenuBase.js +0 -569
  221. package/src/toolbars/PreviewerBubble.js +0 -608
  222. package/src/toolbars/ShortcutKeyConfigPanel.js +0 -345
  223. package/src/toolbars/Sidebar.js +0 -36
  224. package/src/toolbars/Toc.js +0 -242
  225. package/src/toolbars/Toolbar.js +0 -449
  226. package/src/toolbars/ToolbarRight.js +0 -37
  227. package/src/toolbars/hooks/Audio.js +0 -79
  228. package/src/toolbars/hooks/BarTable.js +0 -41
  229. package/src/toolbars/hooks/Bold.js +0 -73
  230. package/src/toolbars/hooks/Br.js +0 -34
  231. package/src/toolbars/hooks/ChangeLocale.js +0 -62
  232. package/src/toolbars/hooks/ChatGpt.js +0 -182
  233. package/src/toolbars/hooks/CheckList.js +0 -41
  234. package/src/toolbars/hooks/Code.js +0 -49
  235. package/src/toolbars/hooks/CodeTheme.js +0 -66
  236. package/src/toolbars/hooks/Color.js +0 -298
  237. package/src/toolbars/hooks/Copy.js +0 -141
  238. package/src/toolbars/hooks/Detail.js +0 -69
  239. package/src/toolbars/hooks/DrawIo.js +0 -57
  240. package/src/toolbars/hooks/Export.js +0 -49
  241. package/src/toolbars/hooks/File.js +0 -79
  242. package/src/toolbars/hooks/Formula.js +0 -69
  243. package/src/toolbars/hooks/FullScreen.js +0 -50
  244. package/src/toolbars/hooks/Graph.js +0 -263
  245. package/src/toolbars/hooks/H1.js +0 -71
  246. package/src/toolbars/hooks/H2.js +0 -71
  247. package/src/toolbars/hooks/H3.js +0 -71
  248. package/src/toolbars/hooks/Header.js +0 -118
  249. package/src/toolbars/hooks/Hr.js +0 -35
  250. package/src/toolbars/hooks/Image.js +0 -91
  251. package/src/toolbars/hooks/InlineCode.js +0 -53
  252. package/src/toolbars/hooks/Insert.js +0 -193
  253. package/src/toolbars/hooks/Italic.js +0 -72
  254. package/src/toolbars/hooks/Justify.js +0 -49
  255. package/src/toolbars/hooks/LineTable.js +0 -41
  256. package/src/toolbars/hooks/Link.js +0 -49
  257. package/src/toolbars/hooks/List.js +0 -55
  258. package/src/toolbars/hooks/MobilePreview.js +0 -44
  259. package/src/toolbars/hooks/Ol.js +0 -41
  260. package/src/toolbars/hooks/Panel.js +0 -140
  261. package/src/toolbars/hooks/Pdf.js +0 -78
  262. package/src/toolbars/hooks/Publish.js +0 -123
  263. package/src/toolbars/hooks/QuickTable.js +0 -43
  264. package/src/toolbars/hooks/Quote.js +0 -45
  265. package/src/toolbars/hooks/Redo.js +0 -33
  266. package/src/toolbars/hooks/Ruby.js +0 -59
  267. package/src/toolbars/hooks/Search.js +0 -53
  268. package/src/toolbars/hooks/Settings.js +0 -220
  269. package/src/toolbars/hooks/ShortcutKey.js +0 -62
  270. package/src/toolbars/hooks/Size.js +0 -118
  271. package/src/toolbars/hooks/Split.js +0 -37
  272. package/src/toolbars/hooks/Strikethrough.js +0 -71
  273. package/src/toolbars/hooks/Sub.js +0 -58
  274. package/src/toolbars/hooks/Sup.js +0 -58
  275. package/src/toolbars/hooks/SwitchModel.js +0 -56
  276. package/src/toolbars/hooks/Table.js +0 -56
  277. package/src/toolbars/hooks/Theme.js +0 -62
  278. package/src/toolbars/hooks/Toc.js +0 -35
  279. package/src/toolbars/hooks/TogglePreview.js +0 -91
  280. package/src/toolbars/hooks/Ul.js +0 -41
  281. package/src/toolbars/hooks/Underline.js +0 -68
  282. package/src/toolbars/hooks/Undo.js +0 -30
  283. package/src/toolbars/hooks/Video.js +0 -79
  284. package/src/toolbars/hooks/Word.js +0 -78
  285. package/src/toolbars/hooks/WordCount.js +0 -106
  286. package/src/utils/autoindent.js +0 -58
  287. package/src/utils/cm-search-replace.js +0 -794
  288. package/src/utils/code-preview-language-setting.js +0 -180
  289. package/src/utils/codeBlockContentHandler.js +0 -400
  290. package/src/utils/config.js +0 -174
  291. package/src/utils/copy.js +0 -55
  292. package/src/utils/dialog.js +0 -214
  293. package/src/utils/dom.js +0 -163
  294. package/src/utils/downloadUtil.js +0 -23
  295. package/src/utils/env.js +0 -22
  296. package/src/utils/error.js +0 -61
  297. package/src/utils/event.js +0 -38
  298. package/src/utils/export.js +0 -166
  299. package/src/utils/file.js +0 -164
  300. package/src/utils/formulaUtilsHandler.js +0 -232
  301. package/src/utils/htmlparser.js +0 -976
  302. package/src/utils/image.js +0 -99
  303. package/src/utils/imgSizeHandler.js +0 -279
  304. package/src/utils/lazyLoadImg.js +0 -327
  305. package/src/utils/lineFeed.js +0 -49
  306. package/src/utils/listContentHandler.js +0 -227
  307. package/src/utils/lookbehind-replace.js +0 -81
  308. package/src/utils/mathjax.js +0 -89
  309. package/src/utils/myersDiff.js +0 -211
  310. package/src/utils/pasteHelper.js +0 -253
  311. package/src/utils/platformTransform.js +0 -71
  312. package/src/utils/recount-pos.js +0 -59
  313. package/src/utils/regexp.js +0 -295
  314. package/src/utils/sanitize.js +0 -477
  315. package/src/utils/selection.js +0 -50
  316. package/src/utils/shortcutKey.js +0 -291
  317. package/src/utils/svgUtils.js +0 -96
  318. package/src/utils/tableContentHandler.js +0 -876
  319. package/test/core/CommonMark.spec.ts +0 -62
  320. package/test/core/hooks/AutoLink.spec.ts +0 -28
  321. package/test/core/hooks/List.spec.ts +0 -79
  322. package/test/core/hooks/__snapshots__/List.spec.ts.snap +0 -11
  323. package/test/example.md +0 -778
  324. package/test/node.js +0 -10
  325. package/test/suites/commonmark.spec.json +0 -5218
  326. package/test/tsconfig.test.json +0 -6
  327. package/test/utils/regexp.spec.ts +0 -28
@@ -1,118 +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 MenuBase from '@/toolbars/MenuBase';
17
- import { getSelection } from '@/utils/selection';
18
- import { CONTROL_KEY, getKeyCode } from '@/utils/shortcutKey';
19
- /**
20
- * 插入1级~5级标题
21
- */
22
- export default class Header extends MenuBase {
23
- /**
24
- * @param {import('@/toolbars/MenuBase').MenuBaseConstructorParams} $cherry
25
- */
26
- constructor($cherry) {
27
- super($cherry);
28
- this.setName('header', 'header');
29
- this.subMenuConfig = [
30
- { iconName: 'h1', name: 'h1', onclick: this.bindSubClick.bind(this, '1') },
31
- { iconName: 'h2', name: 'h2', onclick: this.bindSubClick.bind(this, '2') },
32
- { iconName: 'h3', name: 'h3', onclick: this.bindSubClick.bind(this, '3') },
33
- { iconName: 'h4', name: 'h4', onclick: this.bindSubClick.bind(this, '4') },
34
- { iconName: 'h5', name: 'h5', onclick: this.bindSubClick.bind(this, '5') },
35
- ];
36
- this.shortcutKeyMap = {
37
- [`${CONTROL_KEY}-${getKeyCode(1)}`]: {
38
- hookName: this.name,
39
- aliasName: this.$cherry.locale.h1,
40
- },
41
- [`${CONTROL_KEY}-${getKeyCode(2)}`]: {
42
- hookName: this.name,
43
- aliasName: this.$cherry.locale.h2,
44
- },
45
- [`${CONTROL_KEY}-${getKeyCode(3)}`]: {
46
- hookName: this.name,
47
- aliasName: this.$cherry.locale.h3,
48
- },
49
- [`${CONTROL_KEY}-${getKeyCode(4)}`]: {
50
- hookName: this.name,
51
- aliasName: this.$cherry.locale.h4,
52
- },
53
- [`${CONTROL_KEY}-${getKeyCode(5)}`]: {
54
- hookName: this.name,
55
- aliasName: this.$cherry.locale.h5,
56
- },
57
- };
58
- }
59
-
60
- getSubMenuConfig() {
61
- return this.subMenuConfig;
62
- }
63
-
64
- /**
65
- * 解析快捷键,判断插入的标题级别
66
- * @param {string} shortKey 快捷键
67
- * @returns
68
- */
69
- $getFlagStr(shortKey) {
70
- const test = +(typeof shortKey === 'string' ? shortKey.replace(/[^0-9]+([0-9])/g, '$1') : shortKey);
71
- return '#'.repeat(test ? test : 1);
72
- }
73
-
74
- $testIsHead(selection) {
75
- return /^\s*(#+)\s*.+/.test(selection);
76
- }
77
-
78
- /**
79
- * 响应点击事件
80
- * @param {string} selection 被用户选中的文本内容
81
- * @param {string} shortKey 快捷键参数
82
- * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
83
- */
84
- onClick(selection, shortKey = '') {
85
- let $selection = getSelection(this.editor.editor, selection, 'line', true) || this.locale.header;
86
- const header = this.$getFlagStr(shortKey);
87
- if (!this.isSelections && !this.$testIsHead($selection)) {
88
- this.getMoreSelection('\n', '', () => {
89
- const newSelection = this.editor.editor.getSelection();
90
- const isHead = this.$testIsHead(newSelection);
91
- if (isHead) {
92
- $selection = newSelection;
93
- }
94
- return isHead;
95
- });
96
- }
97
- if (this.$testIsHead($selection)) {
98
- // 如果选中的内容里有标题语法,并且标记级别与目标一致,则去掉标题语法
99
- // 反之,修改标题级别与目标一致
100
- let needClean = true;
101
- const tmp = $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, (w, m1, m2, m3, m4) => {
102
- needClean = needClean ? m2.length === header.length : false;
103
- return `${m1}${header}${m3}${m4}`;
104
- });
105
- if (needClean) {
106
- return $selection.replace(/(^\s*)(#+)(\s*)(.+$)/gm, '$1$4');
107
- }
108
- this.registerAfterClickCb(() => {
109
- this.setLessSelection(`${header} `, '');
110
- });
111
- return tmp;
112
- }
113
- this.registerAfterClickCb(() => {
114
- this.setLessSelection(`${header} `, '');
115
- });
116
- return $selection.replace(/(^)([\s]*)([^\n]+)($)/gm, `$1${header} $3$4`);
117
- }
118
- }
@@ -1,35 +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 MenuBase from '@/toolbars/MenuBase';
17
- /**
18
- * 插入分割线
19
- */
20
- export default class Hr extends MenuBase {
21
- constructor($cherry) {
22
- super($cherry);
23
- this.setName('hr', 'line');
24
- }
25
-
26
- /**
27
- * 响应点击事件
28
- * @param {string} selection 被用户选中的文本内容
29
- * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
30
- */
31
- onClick(selection, shortKey = '') {
32
- // 插入分割线
33
- return `${selection}\n\n---\n`;
34
- }
35
- }
@@ -1,91 +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 MenuBase from '@/toolbars/MenuBase';
17
- import { handleUpload, handleParams, handleUploadMulti } from '@/utils/file';
18
- import { CONTROL_KEY, getKeyCode } from '@/utils/shortcutKey';
19
- /**
20
- * 插入图片
21
- */
22
- export default class Image extends MenuBase {
23
- /**
24
- * @param {import('@/toolbars/MenuBase').MenuBaseConstructorParams} $cherry
25
- */
26
- constructor($cherry) {
27
- super($cherry);
28
- this.setName('image', 'image');
29
- this.shortcutKeyMap = {
30
- [`${CONTROL_KEY}-${getKeyCode('g')}`]: {
31
- hookName: this.name,
32
- aliasName: this.$cherry.locale[this.name],
33
- },
34
- };
35
- }
36
-
37
- /**
38
- * 响应点击事件
39
- * @param {string} selection 被用户选中的文本内容
40
- * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
41
- */
42
- onClick(selection, shortKey = '') {
43
- const accept = this.$cherry.options?.fileTypeLimitMap?.image ?? '*';
44
- const multiple = this.$cherry?.options.multipleFileSelection?.image ?? false;
45
-
46
- if (multiple) {
47
- if (this.hasCacheOnce()) {
48
- // @ts-ignore
49
- const arr = this.getAndCleanCacheOnce();
50
- let res = '';
51
- // @ts-ignore
52
- for (const { url, params } of arr) {
53
- const begin = '![';
54
- const end = `](${url})`;
55
- this.registerAfterClickCb(() => {
56
- this.setLessSelection(begin, end);
57
- });
58
- const finalName = params.name ? params.name : name;
59
- res += `${begin}${finalName}${handleParams(params)}${end}\n`;
60
- }
61
- return res;
62
- }
63
- // 插入图片,调用上传文件逻辑
64
- handleUploadMulti(this.editor, 'image', accept, (arr) => {
65
- this.setCacheOnce(arr);
66
- this.fire(null);
67
- });
68
- this.updateMarkdown = false;
69
- return selection;
70
- }
71
-
72
- if (this.hasCacheOnce()) {
73
- // @ts-ignore
74
- const { name, url, params } = this.getAndCleanCacheOnce();
75
- const begin = '![';
76
- const end = `](${url})`;
77
- this.registerAfterClickCb(() => {
78
- this.setLessSelection(begin, end);
79
- });
80
- const finalName = params.name ? params.name : name;
81
- return `${begin}${finalName}${handleParams(params)}${end}`;
82
- }
83
- // 插入图片,调用上传文件逻辑
84
- handleUpload(this.editor, 'image', accept, (name, url, params) => {
85
- this.setCacheOnce({ name, url, params });
86
- this.fire(null);
87
- });
88
- this.updateMarkdown = false;
89
- return selection;
90
- }
91
- }
@@ -1,53 +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 MenuBase from '@/toolbars/MenuBase';
17
- import { CONTROL_KEY } from '@/utils/shortcutKey';
18
- /**
19
- * 插入行内代码的按钮
20
- */
21
- export default class InlineCode extends MenuBase {
22
- constructor($cherry) {
23
- super($cherry);
24
- this.setName('inlineCode', 'code');
25
- this.shortcutKeyMap = {
26
- [`${CONTROL_KEY}-Backquote`]: {
27
- hookName: this.name,
28
- aliasName: this.$cherry.locale[this.name],
29
- },
30
- };
31
- }
32
-
33
- /**
34
- * 响应点击事件
35
- * @param {string} selection 被用户选中的文本内容
36
- * @param {string} shortKey 快捷键参数,本函数不处理这个参数
37
- * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
38
- */
39
- onClick(selection, shortKey = '') {
40
- if (!selection) {
41
- this.registerAfterClickCb(() => this.setLessSelection('`', '`'));
42
- return '``';
43
- }
44
-
45
- if (!selection.includes('\n')) {
46
- this.registerAfterClickCb(() => this.setLessSelection('`', '`'));
47
- return `\`${selection}\``;
48
- }
49
-
50
- const arr = selection.split('\n').map((item) => `\`${item}\``);
51
- return arr.join('\n');
52
- }
53
- }
@@ -1,193 +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 MenuBase from '@/toolbars/MenuBase';
17
- import BubbleTableMenu from '@/toolbars/BubbleTable';
18
- import { getSelection } from '@/utils/selection';
19
- /**
20
- * "插入"按钮
21
- */
22
- export default class Insert extends MenuBase {
23
- // TODO: 需要优化参数传入方式
24
- constructor($cherry) {
25
- super($cherry);
26
- this.setName('insert', 'insert');
27
- this.noIcon = true;
28
-
29
- this.subBubbleTableMenu = new BubbleTableMenu({ row: 9, col: 9 });
30
- $cherry.editor.options.wrapperDom.appendChild(this.subBubbleTableMenu.dom);
31
- }
32
-
33
- /**
34
- * 上传文件的逻辑
35
- * @param {string} type 上传文件的类型
36
- */
37
- handleUpload(type = 'image') {
38
- // type为上传文件类型 image|video|audio|pdf|word
39
- const input = document.createElement('input');
40
- input.type = 'file';
41
- input.id = 'fileUpload';
42
- input.value = '';
43
- input.style.display = 'none';
44
- // document.body.appendChild(input);
45
- input.addEventListener('change', (event) => {
46
- // @ts-ignore
47
- const [file] = event.target.files;
48
- // 文件上传后的回调函数可以由调用方自己实现
49
- this.$cherry.options.callback.fileUpload(file, (url) => {
50
- // 文件上传的默认回调行数,调用方可以完全不使用该函数
51
- if (typeof url !== 'string' || !url) {
52
- return;
53
- }
54
- let code = '';
55
- if (type === 'image') {
56
- // 如果是图片,则返回固定的图片markdown源码
57
- code = `![${file.name}](${url})`;
58
- } else if (type === 'video') {
59
- // 如果是视频,则返回固定的视频markdown源码
60
- code = `!video[${file.name}](${url})`;
61
- } else if (type === 'audio') {
62
- // 如果是音频,则返回固定的音频markdown源码
63
- code = `!audio[${file.name}](${url})`;
64
- } else {
65
- // 默认返回超链接
66
- code = `[${file.name}](${url})`;
67
- }
68
- // 替换选中区域
69
- // @ts-ignore
70
- this.$cherry.$cherry.doc.replaceSelection(code);
71
- });
72
- });
73
- input.click();
74
- }
75
- /**
76
- * 响应点击事件
77
- * @param {string} selection 被用户选中的文本内容
78
- * @param {string} shortKey 快捷键参数
79
- * @param {Function} [callback] 回调函数
80
- * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
81
- */
82
- onClick(selection, shortKey = '', callback) {
83
- if (/normal-table/.test(shortKey)) {
84
- // 如果是插入markdown标准表格
85
- // 根据shortKey获取想插入表格的行号和列号
86
- // shortKey形如:`normal-table-2*4`,表示插入2行(包含表头是3行)4列的表格
87
- const rowAndCol = shortKey.match(/([0-9]+)[^0-9]([0-9]+)/);
88
- const row = rowAndCol ? +rowAndCol[1] : 3;
89
- const col = rowAndCol ? +rowAndCol[2] : 5;
90
- const headerText = ' Header |'.repeat(col);
91
- const controlText = ' ------ |'.repeat(col);
92
- const rowText = `\n|${' Sample |'.repeat(col)}`;
93
- const text = `${selection}\n\n|${headerText}\n|${controlText}${rowText.repeat(row)}\n\n`;
94
- return text;
95
- }
96
- const $selection = getSelection(this.editor.editor, selection);
97
- switch (shortKey) {
98
- case 'hr':
99
- // 插入分割线
100
- return `${selection}\n\n---\n`;
101
- case 'br':
102
- // 插入换行,在cherry里约定一个回车是一个换行,两个连续回车是一个空行,三个及以上连续回车是两个空行
103
- return `${selection}<br>`;
104
- case 'code':
105
- // 插入代码块
106
- return `\n\`\`\` \n${selection ? selection : 'code...'}\n\`\`\`\n`;
107
- case 'formula':
108
- // 插入行内公式
109
- return `${selection}\n\n$ e=mc^2 $\n\n`;
110
- case 'checklist':
111
- // 插入检查项
112
- return `${selection}\n\n- [x] Item 1\n- [ ] Item 2\n- [ ] Item 3\n`;
113
- case 'toc':
114
- // 插入目录
115
- return `${selection}\n\n[[toc]]\n`;
116
- case 'link':
117
- // 插入超链接
118
- return `${selection}[${this.locale.link}](http://url.com) `;
119
- case 'image':
120
- // 插入图片,调用上传文件逻辑
121
- this.handleUpload('image');
122
- return selection;
123
- case 'video':
124
- // 插入视频,调用上传文件逻辑
125
- this.handleUpload('video');
126
- return selection;
127
- case 'audio':
128
- // 插入音频,调用上传文件逻辑
129
- this.handleUpload('audio');
130
- return selection;
131
- case 'table':
132
- // 插入表格,会出现一个二维面板,用户可以通过点击决定插入表格的行号和列号
133
- // TODO: 菜单定位方式调整,空行判断
134
- this.subBubbleTableMenu.dom.style.left = this.subMenu.dom.style.left;
135
- this.subBubbleTableMenu.dom.style.top = this.subMenu.dom.style.top;
136
- this.subBubbleTableMenu.show((row, col) => {
137
- const headerText = ' Header |'.repeat(col);
138
- const controlText = ' ------ |'.repeat(col);
139
- const rowText = `\n|${' Sample |'.repeat(col)}`;
140
- const text = `${selection}\n\n|${headerText}\n|${controlText}${rowText.repeat(row)}\n\n`;
141
- callback(text);
142
- });
143
- return;
144
- case 'line-table':
145
- // 插入带折线图的表格
146
- return `${selection}\n\n${[
147
- '| :line: {x,y} | a | b | c |',
148
- '| :-: | :-: | :-: | :-: |',
149
- '| x | 1 | 2 | 3 |',
150
- '| y | 2 | 4 | 6 |',
151
- '| z | 7 | 5 | 3 |',
152
- ].join('\n')}\n\n`;
153
- case 'bar-table':
154
- // 插入带柱状图的表格
155
- return `${selection}\n\n${[
156
- '| :bar: {x,y} | a | b | c |',
157
- '| :-: | :-: | :-: | :-: |',
158
- '| x | 1 | 2 | 3 |',
159
- '| y | 2 | 4 | 6 |',
160
- '| z | 7 | 5 | 3 |',
161
- ].join('\n')}\n\n`;
162
- case 'headlessTable':
163
- // 插入没有表头的表格
164
- // 该表格语法是源于[TAPD](https://tapd.cn) wiki应用里的一种表格语法
165
- // 该表格语法不是markdown通用语法,请慎用
166
- // TODO: 菜单定位方式调整, 空行判断
167
- this.subBubbleTableMenu.dom.style.left = this.subMenu.dom.style.left;
168
- this.subBubbleTableMenu.dom.style.top = this.subMenu.dom.style.top;
169
- this.subBubbleTableMenu.show((row, col) => {
170
- const text = `${selection}\n\n||${' ~Header ||'.repeat(col)}${`\n||${' SampleT ||'.repeat(col)}`.repeat(
171
- row - 1,
172
- )}\n\n`;
173
- callback(text);
174
- });
175
- return;
176
- case 'pdf':
177
- // 插入pdf文件,调用上传文件逻辑
178
- this.handleUpload('pdf');
179
- return selection;
180
- case 'word':
181
- // 插入word,调用上传文件逻辑
182
- // 可以在文件上传逻辑里做处理,word上传后通过后台服务转成html再返回,前端接受后进行处理并回填
183
- this.handleUpload('word');
184
- return selection;
185
- case 'ruby':
186
- // 如果选中的文本中已经有ruby语法了,则去掉该语法
187
- if (/^\s*\{[\s\S]+\|[\s\S]+\}/.test($selection)) {
188
- return $selection.replace(/^\s*\{\s*([\s\S]+?)\s*\|[\s\S]+\}\s*/gm, '$1');
189
- }
190
- return ` { ${$selection} | ${this.editor.$cherry.options.callback.changeString2Pinyin($selection).trim()} } `;
191
- }
192
- }
193
- }
@@ -1,72 +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 MenuBase from '@/toolbars/MenuBase';
17
- import { CONTROL_KEY, getKeyCode } from '@/utils/shortcutKey';
18
- /**
19
- * 插入斜体的按钮
20
- */
21
- export default class Italic extends MenuBase {
22
- /**
23
- * @param {import('@/toolbars/MenuBase').MenuBaseConstructorParams} $cherry
24
- */
25
- constructor($cherry) {
26
- super($cherry);
27
- this.setName('italic', 'italic');
28
- this.shortcutKeyMap = {
29
- [`${CONTROL_KEY}-${getKeyCode('i')}`]: {
30
- hookName: this.name,
31
- aliasName: this.$cherry.locale[this.name],
32
- },
33
- };
34
- }
35
-
36
- /**
37
- * 是不是包含加粗语法
38
- * @param {String} selection
39
- * @returns {Boolean}
40
- */
41
- $testIsItalic(selection) {
42
- return /^\s*(\*|_)[\s\S]+(\1)/.test(selection);
43
- }
44
-
45
- /**
46
- * 响应点击事件
47
- * @param {string} selection 被用户选中的文本内容
48
- * @param {string} shortKey 快捷键参数,本函数不处理这个参数
49
- * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
50
- */
51
- onClick(selection, shortKey = '') {
52
- let $selection = this.getSelection(selection) || this.locale.italic;
53
- // 如果是单选,并且选中内容的开始结束内没有加粗语法,则扩大选中范围
54
- if (!this.isSelections && !this.$testIsItalic($selection)) {
55
- this.getMoreSelection('*', '*', () => {
56
- const newSelection = this.editor.editor.getSelection();
57
- const isItalic = this.$testIsItalic(newSelection);
58
- if (isItalic) {
59
- $selection = newSelection;
60
- }
61
- return isItalic;
62
- });
63
- }
64
- if (this.$testIsItalic($selection)) {
65
- return $selection.replace(/(^)(\s*)(\*|_)([^\n]+)(\3)(\s*)($)/gm, '$1$4$7');
66
- }
67
- this.registerAfterClickCb(() => {
68
- this.setLessSelection('*', '*');
69
- });
70
- return $selection.replace(/(^)([^\n]+)($)/gm, '$1*$2*$3');
71
- }
72
- }
@@ -1,49 +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 Panel from './Panel';
17
- import { getPanelRule } from '@/utils/regexp';
18
- /**
19
- * 插入对齐方式
20
- */
21
- export default class Justify extends Panel {
22
- constructor($cherry) {
23
- super($cherry);
24
- this.setName('justify', 'justify');
25
- this.panelRule = getPanelRule().reg;
26
- const { locale } = this.$cherry;
27
- this.subMenuConfig = [
28
- {
29
- iconName: 'justifyLeft',
30
- name: locale?.justifyLeft ?? '左对齐',
31
- onclick: this.bindSubClick.bind(this, 'left'),
32
- },
33
- {
34
- iconName: 'justifyCenter',
35
- name: locale?.justifyCenter ?? '居中',
36
- onclick: this.bindSubClick.bind(this, 'center'),
37
- },
38
- {
39
- iconName: 'justifyRight',
40
- name: locale?.justifyRight ?? '右对齐',
41
- onclick: this.bindSubClick.bind(this, 'right'),
42
- },
43
- ];
44
- }
45
-
46
- $getTitle() {
47
- return ' ';
48
- }
49
- }
@@ -1,41 +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 MenuBase from '@/toolbars/MenuBase';
17
- /**
18
- * 插入折线图+表格
19
- */
20
- export default class LineTable extends MenuBase {
21
- constructor($cherry) {
22
- super($cherry);
23
- this.setName('lineTable', 'table');
24
- }
25
-
26
- /**
27
- * 响应点击事件
28
- * @param {string} selection 被用户选中的文本内容
29
- * @returns {string} 回填到编辑器光标位置/选中文本区域的内容
30
- */
31
- onClick(selection, shortKey = '') {
32
- // 插入带折线图的表格
33
- return `${selection}\n\n${[
34
- '| :line: {x,y} | a | b | c |',
35
- '| :-: | :-: | :-: | :-: |',
36
- '| x | 1 | 2 | 3 |',
37
- '| y | 2 | 4 | 6 |',
38
- '| z | 7 | 5 | 3 |',
39
- ].join('\n')}\n\n`;
40
- }
41
- }