@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,253 +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
-
17
- import { createElement } from '@/utils/dom';
18
-
19
- const SAFE_AREA_MARGIN = 15;
20
-
21
- /**
22
- * Cherry实现了将粘贴的html内容转成对应的markdown源码的功能
23
- * 本工具主要实现将粘贴html转成的markdown源码在编辑器中选中,并给出切换按钮
24
- * 可以切换为纯文本内容,或者markdown内容
25
- */
26
- const pasteHelper = {
27
- /**
28
- * 核心方法,粘贴后展示切换按钮
29
- * 只有粘贴html时才会出现切换按钮
30
- * @param {Object} currentCursor 当前的光标位置
31
- * @param {Object} editor 编辑器对象
32
- * @param {string} html html里的纯文本内容
33
- * @param {string} md html对应的markdown源码
34
- * @returns
35
- */
36
- showSwitchBtnAfterPasteHtml($cherry, currentCursor, editor, html, md) {
37
- if (html.trim() === md.trim()) {
38
- return;
39
- }
40
- this.init($cherry, currentCursor, editor, html, md);
41
- this.setSelection();
42
- this.bindListener();
43
- this.initBubble();
44
- this.showBubble();
45
- // 默认粘贴成markdown格式,如果用户上次选择粘贴为纯文本,则需要切换为text
46
- if (this.getTypeFromLocalStorage() === 'text') {
47
- this.switchTextClick();
48
- }
49
- },
50
-
51
- init($cherry, currentCursor, editor, html, md) {
52
- this.$cherry = $cherry;
53
- this.html = html;
54
- this.md = md;
55
- this.codemirror = editor;
56
- this.currentCursor = currentCursor;
57
- this.locale = $cherry.locale;
58
- },
59
-
60
- /**
61
- * 获取缓存中的复制粘贴类型
62
- */
63
- getTypeFromLocalStorage() {
64
- if (typeof localStorage === 'undefined') {
65
- return 'md';
66
- }
67
- return localStorage.getItem('cherry-paste-type') || 'md';
68
- },
69
-
70
- /**
71
- * 记忆最近一次用户选择的粘贴类型
72
- */
73
- setTypeToLocalStorage(type) {
74
- if (typeof localStorage === 'undefined') {
75
- return;
76
- }
77
- localStorage.setItem('cherry-paste-type', type);
78
- },
79
-
80
- /**
81
- * 在编辑器中自动选中刚刚粘贴的内容
82
- */
83
- setSelection() {
84
- const { /* sticky, xRel, */ ...end } = this.codemirror.getCursor();
85
- const begin = this.currentCursor;
86
- this.codemirror.setSelection(begin, end);
87
- },
88
- /**
89
- * 绑定事件
90
- * 当编辑器选中区域改变、内容改变时,隐藏切换按钮
91
- * 当编辑器滚动时,实时更新切换按钮的位置
92
- * @returns null
93
- */
94
- bindListener() {
95
- if (!this.hasBindListener) {
96
- this.hasBindListener = true;
97
- } else {
98
- return true;
99
- }
100
- this.codemirror.on('beforeSelectionChange', (codemirror, info) => {
101
- this.hideBubble();
102
- });
103
- this.codemirror.on('beforeChange', (codemirror, info) => {
104
- this.hideBubble();
105
- });
106
- this.codemirror.on('scroll', (codemirror) => {
107
- this.updatePositionWhenScroll();
108
- });
109
- },
110
-
111
- isHidden() {
112
- return this.bubbleDom.style.display === 'none';
113
- },
114
-
115
- toggleBubbleDisplay() {
116
- if (this.isHidden()) {
117
- this.bubbleDom.style.display = '';
118
- return;
119
- }
120
- this.bubbleDom.style.display = 'none';
121
- return;
122
- },
123
-
124
- hideBubble() {
125
- if (this.noHide) {
126
- return true;
127
- }
128
- if (this.isHidden()) {
129
- return;
130
- }
131
- this.toggleBubbleDisplay();
132
- },
133
-
134
- updatePositionWhenScroll() {
135
- if (this.isHidden()) {
136
- return;
137
- }
138
- // FIXME: update position when stick to the bottom
139
- // const isStickToBottom = !this.bubbleDom.style.top;
140
- const offset = this.bubbleDom.dataset.scrollTop - this.getScrollTop();
141
- this.bubbleDom.style.marginTop = `${offset}px`;
142
- },
143
-
144
- getScrollTop() {
145
- return this.codemirror.getScrollInfo().top;
146
- },
147
-
148
- showBubble() {
149
- const { top } = this.getLastSelectedPosition();
150
- if (this.isHidden()) {
151
- this.toggleBubbleDisplay();
152
- this.bubbleDom.style.marginTop = '0';
153
- this.bubbleDom.dataset.scrollTop = this.getScrollTop();
154
- }
155
- /**
156
- * @type {HTMLDivElement}
157
- */
158
- const codemirrorWrapper = this.codemirror.getWrapperElement();
159
- const maxTop = codemirrorWrapper.clientHeight - this.bubbleDom.getBoundingClientRect().height - SAFE_AREA_MARGIN;
160
-
161
- if (top > maxTop) {
162
- this.bubbleDom.style.top = '';
163
- this.bubbleDom.style.bottom = `${SAFE_AREA_MARGIN}px`;
164
- } else {
165
- this.bubbleDom.style.top = `${top}px`;
166
- this.bubbleDom.style.bottom = '';
167
- }
168
- },
169
-
170
- initBubble() {
171
- if (this.bubbleDom) {
172
- this.bubbleDom.setAttribute('data-type', 'md');
173
- return true;
174
- }
175
- const dom = createElement('div', 'cherry-bubble cherry-bubble--centered cherry-switch-paste');
176
- dom.style.display = 'none';
177
-
178
- const switchText = createElement('span', 'cherry-toolbar-button cherry-text-btn', {
179
- title: this.locale.pastePlain,
180
- });
181
- switchText.innerText = 'TEXT';
182
-
183
- const switchMd = createElement('span', 'cherry-toolbar-button cherry-md-btn', {
184
- title: this.locale.pasteMarkdown,
185
- });
186
- switchMd.innerText = 'Markdown';
187
-
188
- const switchBG = createElement('span', 'switch-btn--bg');
189
-
190
- this.bubbleDom = dom;
191
- this.switchText = switchText;
192
- this.switchMd = switchMd;
193
- this.switchBG = switchBG;
194
- this.bubbleDom.appendChild(switchText);
195
- this.bubbleDom.appendChild(switchMd);
196
- this.bubbleDom.appendChild(switchBG);
197
- this.bubbleDom.setAttribute('data-type', 'md');
198
- this.codemirror.getWrapperElement().appendChild(this.bubbleDom);
199
- this.switchMd.addEventListener('click', this.switchMDClick.bind(this));
200
- this.switchText.addEventListener('click', this.switchTextClick.bind(this));
201
- },
202
-
203
- switchMDClick(event) {
204
- this.setTypeToLocalStorage('md');
205
- if (this.bubbleDom.getAttribute('data-type') === 'md') {
206
- return;
207
- }
208
- this.noHide = true;
209
- this.bubbleDom.setAttribute('data-type', 'md');
210
- this.codemirror.doc.replaceSelection(this.md);
211
- this.setSelection();
212
- this.showBubble();
213
- this.noHide = false;
214
- },
215
- switchTextClick(event) {
216
- this.setTypeToLocalStorage('text');
217
- if (this.bubbleDom.getAttribute('data-type') === 'text') {
218
- return;
219
- }
220
- this.noHide = true;
221
- this.bubbleDom.setAttribute('data-type', 'text');
222
- this.codemirror.doc.replaceSelection(this.html);
223
- this.setSelection();
224
- this.showBubble();
225
- this.noHide = false;
226
- },
227
-
228
- getLastSelectedPosition() {
229
- const selectedObjs = Array.from(this.codemirror.getWrapperElement().getElementsByClassName('CodeMirror-selected'));
230
- let width = 0;
231
- let top = 0;
232
- if (selectedObjs.length <= 0) {
233
- this.hideBubble();
234
- return {};
235
- }
236
- // FIXME: remove redundant width calculation
237
- for (let key = 0; key < selectedObjs.length; key++) {
238
- const item = selectedObjs[key];
239
- const position = item.getBoundingClientRect();
240
- const tmpWidth = position.left + position.width / 2;
241
- const tmpTop = position.top + position.height;
242
- if (tmpTop > top && tmpWidth >= width) {
243
- top = tmpTop;
244
- }
245
- if (tmpWidth > width) {
246
- width = tmpWidth;
247
- }
248
- }
249
- return { top };
250
- },
251
- };
252
-
253
- export default pasteHelper;
@@ -1,71 +0,0 @@
1
- /**
2
- * 将图片转成base64,防止出现由于图片防盗链功能导致图裂的情况
3
- * @param {string} url 图片的地址
4
- * @param {Function} [callback] 回调函数,本函数不处理该参数
5
- * @param {string} [outputFormat]
6
- * @returns {Promise<string>} img node
7
- */
8
- function convertImgToBase64(url, callback, outputFormat) {
9
- return new Promise((resolve) => {
10
- let canvas = /** @type {HTMLCanvasElement}*/ (document.createElement('CANVAS'));
11
- const ctx = canvas.getContext('2d');
12
- const img = new Image();
13
- img.crossOrigin = 'Anonymous';
14
- img.onload = function () {
15
- canvas.height = img.height;
16
- canvas.width = img.width;
17
- ctx.drawImage(img, 0, 0);
18
- const dataURL = canvas.toDataURL(outputFormat || 'image/png');
19
- resolve(dataURL);
20
- canvas = null;
21
- };
22
- img.src = url;
23
- });
24
- }
25
-
26
- /**
27
- * 将cherry-markdown渲染的html转换为微信公众号支持的格式
28
- * @param {string} rawHtml 原始html
29
- * @returns {Promise<string>} 转换完成的html
30
- */
31
- export const transformWechat = async (rawHtml) => {
32
- // 防止echarts标签被转成p时丢失样式
33
- const figureRegex = /(<figure data-lines=.+?<)div(.+?<\/)div(>.*?<\/figure>)/g;
34
- let html = rawHtml.replace(figureRegex, (match, prefix, content, suffix) => {
35
- return `${prefix}p${content}p${suffix}`;
36
- });
37
- // 图片转base64,防止无法自动上传
38
- const imgRegex = /(<img.+?src=")(.+?)(".*?>)/g;
39
- /** @type {(Promise<string>)[]} */
40
- const promises = [];
41
- html.replace(imgRegex, (match, prefix, src) => {
42
- promises.push(convertImgToBase64(src));
43
- // 这一步并不需要替换
44
- return match;
45
- });
46
- const urls = await Promise.all(promises);
47
- // 去掉a标签的href属性,微信公众号不支持
48
- html = html.replace(/(<a[^>]+)href="[^"]*"/g, '$1');
49
- // 将预览区域宽度设置为100%
50
- html = html.replace(/(<div[^>]+style="[^">]*width:\s*)[^";]+(;[^>]*>)/g, '$1100%$2');
51
- return html.replace(imgRegex, (match, prefix, src, suffix) => prefix + urls.shift() + suffix);
52
- };
53
-
54
- /**
55
- * 将 cherry-markdown 渲染的 html 转换为对应平台支持的格式
56
- * @param {string} htmlStr html 字符串
57
- * @param {import('../../types/cherry').SupportPlatform} platform 平台
58
- */
59
- export const platformTransform = async (htmlStr, platform) => {
60
- if (typeof htmlStr !== 'string' || !htmlStr) {
61
- return '';
62
- }
63
- switch (platform) {
64
- case 'wechat':
65
- return transformWechat(htmlStr);
66
- default:
67
- throw new Error('platform not support');
68
- }
69
- };
70
-
71
- export default platformTransform;
@@ -1,59 +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
-
17
- import diff from 'fast-diff';
18
- /**
19
- * 更新内容时保持光标不变
20
- * @param {Number} pos 光标相对文档开头的偏移量
21
- * @param {String} oldContent 变更前的内容
22
- * @param {String} newContent 变更后的内容
23
- * @returns {Number} newPos 新的光标偏移量
24
- */
25
- export default function getPosBydiffs(pos, oldContent, newContent) {
26
- const diffs = diff(oldContent, newContent);
27
- let newPos = pos;
28
- let tmpPos = pos;
29
- for (let i = 0; i < diffs.length; i++) {
30
- const val = diffs[i];
31
- if (tmpPos <= 0) {
32
- return newPos;
33
- }
34
- const opType = val[0];
35
- const opLength = val[1].length;
36
- switch (opType) {
37
- // 没有改变的内容
38
- case diff.EQUAL:
39
- if (tmpPos <= opLength) {
40
- return newPos;
41
- }
42
- tmpPos -= opLength;
43
- break;
44
- // 删除的内容
45
- case diff.DELETE:
46
- if (tmpPos <= opLength) {
47
- return newPos - opLength + tmpPos;
48
- }
49
- tmpPos -= opLength;
50
- newPos -= opLength;
51
- break;
52
- // 新增的内容
53
- case diff.INSERT:
54
- newPos += opLength;
55
- break;
56
- }
57
- }
58
- return newPos;
59
- }
@@ -1,295 +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
- export function compileRegExp(obj, flags, allowExtendedFlags) {
17
- let source = obj.begin + obj.content + obj.end;
18
- if (allowExtendedFlags) {
19
- // Extend \h for horizontal whitespace
20
- source = source.replace(/\[\\h\]/g, HORIZONTAL_WHITESPACE).replace(/\\h/g, HORIZONTAL_WHITESPACE);
21
- }
22
- return new RegExp(source, flags || 'g');
23
- }
24
-
25
- export function isLookbehindSupported() {
26
- try {
27
- new RegExp('(?<=.)');
28
- return true;
29
- } catch (ignore) {}
30
- return false;
31
- }
32
-
33
- export const HORIZONTAL_WHITESPACE = '[ \\t\\u00a0]';
34
-
35
- // 仅适用非多行模式的正则
36
- export const ALLOW_WHITESPACE_MULTILINE = '(?:.*?)(?:(?:\\n.*?)*?)';
37
- export const DO_NOT_STARTS_AND_END_WITH_SPACES = '(?:\\S|(?:\\S.*?\\S))';
38
- export const DO_NOT_STARTS_AND_END_WITH_SPACES_MULTILINE =
39
- '(?:(?:\\S|(?:\\S[^\\n]*?\\S))(?:\\n(?:\\S|(?:\\S[^\\n]*?\\S)))*?)';
40
-
41
- /**
42
- * @deprecated
43
- *
44
- * 存在严重性能问题,应弃用
45
- */
46
- export const DO_NOT_STARTS_AND_END_WITH_SPACES_MULTILINE_ALLOW_EMPTY = '(?:(?:\\S|(?:\\S.*?\\S))(?:[ \\t]*\\n.*?)*?)';
47
-
48
- export const NOT_ALL_WHITE_SPACES_INLINE = '(?:[^\\n]*?\\S[^\\n]*?)';
49
-
50
- export const NORMAL_INDENT = '[ ]{0, 3}|\\t';
51
- export const NO_BACKSLASH_BEFORE_CAPTURE = '[^\\\\]';
52
-
53
- // https://spec.commonmark.org/0.29/#ascii-punctuation-character
54
- // !, ", #, $, %, &, ', (, ), *, +, ,, -, ., / (U+0021–2F),
55
- // :, ;, <, =, >, ?, @ (U+003A–0040),
56
- // [, \, ], ^, _, ` (U+005B–0060),
57
- // {, |, }, or ~ (U+007B–007E).
58
- export const PUNCTUATION = '[\\u0021-\\u002F\\u003a-\\u0040\\u005b-\\u0060\\u007b-\\u007e]';
59
-
60
- // extra punctuations
61
- export const CHINESE_PUNCTUATION = '[!“”¥‘’(),。—:;《》?【】「」·~|]';
62
-
63
- // 下划线强调语法允许的边界符号
64
- export const UNDERSCORE_EMPHASIS_BOUNDARY =
65
- '[' +
66
- '\\u0021-\\u002F\\u003a-\\u0040\\u005b\\u005d\\u005e\\u0060\\u007b-\\u007e' + // punctuations defined in commonmark
67
- ' ' +
68
- '\\t\\n' +
69
- '!“”¥‘’(),。—:;《》?【】「」·~|' + // chinese punctuations
70
- ']';
71
-
72
- // https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type%3Demail)
73
- export const EMAIL_INLINE = new RegExp(
74
- [
75
- /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+/.source,
76
- '@',
77
- /[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/.source,
78
- ].join(''),
79
- );
80
- export const EMAIL = new RegExp(`^${EMAIL_INLINE.source}$`);
81
-
82
- // https://gist.github.com/dperini/729294
83
- // [USERNAME[:PASSWORD]@](IP|HOST)[:PORT][/SOURCE_PATH?QUERY_PARAMS#HASH]
84
- export const URL_INLINE_NO_SLASH = new RegExp(
85
- '' + // 针对eslint的特殊处理
86
- '(?:\\S+(?::\\S*)?@)?' +
87
- '(?:' +
88
- // IP address exclusion
89
- // IP address dotted notation octets
90
- // excludes loopback network 0.0.0.0
91
- // excludes reserved space >= 224.0.0.0
92
- // excludes network & broadcast addresses
93
- // (first & last IP address of each class)
94
- '(?:1\\d\\d|2[01]\\d|22[0-3]|[1-9]\\d?)' +
95
- '(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' +
96
- '(?:\\.(?:1\\d\\d|2[0-4]\\d|25[0-4]|[1-9]\\d?))' +
97
- '|' +
98
- // host & domain names, may end with dot
99
- '(?![-_])(?:[-\\w\\xa1-\\xff]{0,63}[^-_]\\.)+' +
100
- // TLD identifier name, may end with dot
101
- '(?:[a-zA-Z\\xa1-\\xff]{2,}\\.?)' +
102
- ')' +
103
- // port number (optional)
104
- '(?::\\d{2,5})?' +
105
- // resource path (optional)
106
- '(?:[/?#][^\\s<>\\x00-\\x1f"\\(\\)]*)?',
107
- );
108
- export const URL_INLINE = new RegExp(
109
- // eslint特殊处理
110
- // protocol identifier (optional)
111
- // short syntax // still required
112
- // '(?:(?:(?:https?|ftp):)?\\/\\/)' +
113
- `(?:\\/\\/)${URL_INLINE_NO_SLASH.source}`,
114
- );
115
-
116
- export const URL_NO_SLASH = new RegExp(`^${URL_INLINE_NO_SLASH.source}$`);
117
-
118
- export const URL = new RegExp(`^${URL_INLINE.source}$`);
119
-
120
- // 正则结果[全部, 判定符之前的空格或者tab, 判定符, checkbox内容(没有就是undefined), 列表内容]
121
- export const LIST_CONTENT =
122
- /^([ \t]*)([*+-][ ](\[[ x]\])?|[0-9一二三四五六七八九十零]+\.|[a-z]\.|\b(?:M{0,3}(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|V?I{0,3}))\b\.)([^\r\n]*)/;
123
-
124
- export function getTableRule(merge = false) {
125
- // ^(\|[^\n]+\|\r?\n)((?:\|:?[-]+:?)+\|)(\n(?:\|[^\n]+\|\r?\n?)*)?$
126
- // (\\|?[^\\n|]+\\|?\\n)(?:\\|?[\\s]*:?[-]{2,}:?[\\s]*
127
- // (?:\\|[\\s]*:?[-]{2,}:?[\\s]*)+\\|?)(\\n\\|?(\\|[^\\n|]+)*\\|?)?
128
- /**
129
- * (\|[^\n]+\|\n) Headers
130
- * ((\|[\s]*:?[-]{2,}:?[\s]*)+\|) Column Options
131
- * ((?:\n\|[^\n]+\|)*) Rows
132
- */
133
- const strict = {
134
- begin: '(?:^|\\n)(\\n*)',
135
- content: [
136
- '(\\h*\\|[^\\n]+\\|?\\h*)', // Header
137
- '\\n',
138
- '(?:(?:\\h*\\|\\h*:?[-]{1,}:?\\h*)+\\|?\\h*)', // Column Options
139
- '((\\n\\h*\\|[^\\n]+\\|?\\h*)*)', // Rows
140
- ].join(''),
141
- end: '(?=$|\\n)',
142
- };
143
-
144
- strict.reg = compileRegExp(strict, 'g', true);
145
-
146
- const loose = {
147
- begin: '(?:^|\\n)(\\n*)',
148
- content: [
149
- '(\\|?[^\\n|]+(\\|[^\\n|]+)+\\|?)', // Header
150
- '\\n',
151
- '(?:\\|?\\h*:?[-]{1,}:?[\\h]*(?:\\|[\\h]*:?[-]{1,}:?\\h*)+\\|?)', // Column Options
152
- '((\\n\\|?([^\\n|]+(\\|[^\\n|]*)+)\\|?)*)', // Rows
153
- ].join(''),
154
- end: '(?=$|\\n)',
155
- };
156
-
157
- loose.reg = compileRegExp(loose, 'g', true);
158
-
159
- if (merge === false) {
160
- return { strict, loose };
161
- }
162
- const regStr = `(?:${strict.begin + strict.content + strict.end}|${loose.begin + loose.content + loose.end})`;
163
- return compileRegExp({ begin: '', content: regStr, end: '' }, 'g', true);
164
- }
165
-
166
- export function getCodeBlockRule() {
167
- const codeBlock = {
168
- /**
169
- * (?:^|\n)是区块的通用开头
170
- * (\n*)捕获区块前的所有换行
171
- * ((?:>\s*)*) 捕获代码块前面的引用("> > > " 这种东西)
172
- * (?:[^\S\n]*)捕获```前置的空格字符
173
- * 只要有连续3个及以上`并且前后`的数量相等,则认为是代码快语法
174
- */
175
- begin: /(?:^|\n)(\n*((?:>[\t ]*)*)(?:[^\S\n]*))(`{3,})([^`]*?)\n/,
176
- content: /([\w\W]*?)/, // '([\\w\\W]*?)',
177
- end: /[^\S\n]*\3[ \t]*(?=$|\n+)/, // '\\s*```[ \\t]*(?=$|\\n+)',
178
- reg: new RegExp(''),
179
- };
180
- codeBlock.reg = new RegExp(codeBlock.begin.source + codeBlock.content.source + codeBlock.end.source, 'g');
181
- return {
182
- ...codeBlock,
183
- begin: codeBlock.begin.source,
184
- content: codeBlock.content.source,
185
- end: codeBlock.end.source,
186
- };
187
- }
188
-
189
- /**
190
- * 从selection里获取列表语法
191
- * @param {*} selection
192
- * @param {('ol'|'ul'|'checklist')} type 列表类型
193
- * @returns {String}
194
- */
195
- export function getListFromStr(selection, type) {
196
- let $selection = selection ? selection : 'Item 1\n Item 1.1\nItem 2';
197
- $selection = $selection.replace(/^\n+/, '').replace(/\n+$/, '');
198
- let pre = '1.';
199
- switch (type) {
200
- case 'ol':
201
- pre = '1.';
202
- break;
203
- case 'ul':
204
- pre = '-';
205
- break;
206
- case 'checklist':
207
- pre = '- [x]';
208
- break;
209
- }
210
- $selection = $selection.replace(/^(\s*)([0-9a-zA-Z]+\.|- \[x\]|- \[ \]|-) /gm, '$1');
211
- // 对有序列表进行序号自增处理
212
- if (pre === '1.') {
213
- const listNum = {};
214
- $selection = $selection.replace(/^(\s*)(\S[\s\S]*?)$/gm, (match, p1, p2) => {
215
- const space = p1.match(/[ \t]/g)?.length || 0;
216
- listNum[space] = listNum[space] ? listNum[space] + 1 : 1;
217
- return `${p1}${listNum[space]}. ${p2}`;
218
- });
219
- } else {
220
- $selection = $selection.replace(/^(\s*)(\S[\s\S]*?)$/gm, `$1${pre} $2`);
221
- }
222
- return $selection;
223
- }
224
-
225
- /**
226
- * 信息面板的识别正则
227
- * @returns {object}
228
- */
229
- export function getPanelRule() {
230
- const ret = {
231
- begin: /(?:^|\n)(\n*(?:[^\S\n]*)):::([^:][^\n]+?)\s*\n/,
232
- content: /([\w\W]*?)/,
233
- end: /\n[ \t]*:::[ \t]*(?=$|\n+)/,
234
- };
235
- ret.reg = new RegExp(ret.begin.source + ret.content.source + ret.end.source, 'g');
236
- return ret;
237
- }
238
-
239
- /**
240
- * 手风琴/detail语法的识别正则
241
- * 例:
242
- * +++(-) 点击查看详情
243
- * body
244
- * body
245
- * ++ 标题(默认收起内容)
246
- * 内容
247
- * ++- 标题(默认展开内容)
248
- * 内容2
249
- * +++
250
- * @returns {object}
251
- */
252
- export function getDetailRule() {
253
- const ret = {
254
- begin: /(?:^|\n)(\n*(?:[^\S\n]*))\+\+\+([-]{0,1})\s+([^\n]+)\n/,
255
- content: /([\w\W]+?)/,
256
- end: /\n[ \t]*\+\+\+[ \t]*(?=$|\n+)/,
257
- };
258
- ret.reg = new RegExp(ret.begin.source + ret.content.source + ret.end.source, 'g');
259
- return ret;
260
- }
261
-
262
- // 匹配图片URL里的base64,[name](data:image/png;base64,xxx) 和 ![alt](data:image/png;base64,xxx) 这两种形式的都处理
263
- export const imgBase64Reg = /(\[[^\n]*?\]\(data:image\/[a-z]{1,10};base64,)([^)]+)\)/g;
264
-
265
- // 匹配base64数据
266
- export const base64Reg = /(data:image\/[a-z]{1,10};base64,)([0-9a-zA-Z+/]+)/g;
267
-
268
- // 匹配内容非常多的单行文本,为了避免表格的场景,所以特意避免表格的识别
269
- export const longTextReg = /([^\n]{100})([^\n|`\s]{5900,})/g;
270
-
271
- // 匹配图片{}里的data-xml属性
272
- export const imgDrawioXmlReg = /(!\[[^\n]*?\]\([^)]+\)\{[^}]* data-xml=)([^}]+)\}/g;
273
-
274
- /**
275
- * 匹配draw.io的图片语法
276
- * 图片的语法为 ![alt](${base64}){data-type=drawio data-xml=${xml}}
277
- */
278
- export const imgDrawioReg =
279
- /(!\[[^\n]*?\]\(data:image\/[a-z]{1,10};base64,[^)]+\)\{data-type=drawio data-xml=[^}]+\})/g;
280
-
281
- /**
282
- * 从编辑器里的内容中获取没有代码块的内容
283
- * @param {string} value
284
- * @returns {string}
285
- */
286
- export const getValueWithoutCode = (value = '') =>
287
- value
288
- .replace(getCodeBlockRule().reg, (whole) => {
289
- // 把代码块里的内容干掉
290
- return whole.replace(/^.*$/gm, '/n');
291
- })
292
- .replace(/(`+)(.+?(?:\n.+?)*?)\1/g, (whole) => {
293
- // 把行内代码的符号去掉
294
- return whole.replace(/[![\]()]/g, '.');
295
- });