@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,52 +0,0 @@
1
- /**
2
- * Copyright (C) 2021 THL A29 Limited, a Tencent company.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import ParagraphBase from '@/core/ParagraphBase';
17
- import { prependLineFeedForParagraph } from '@/utils/lineFeed';
18
- /**
19
- * 分割线语法
20
- */
21
- export default class Hr extends ParagraphBase {
22
- static HOOK_NAME = 'hr';
23
-
24
- constructor() {
25
- super({ needCache: true });
26
- }
27
-
28
- beforeMakeHtml(str) {
29
- return str.replace(this.RULE.reg, (match, preLines) => {
30
- const lineCount = (preLines.match(/\n/g) || []).length + 1;
31
- // 计算签名,签名可能会重复,符合预期
32
- const sign = `hr${lineCount}`;
33
- const placeHolder = this.pushCache(`<hr data-sign="${sign}" data-lines="${lineCount}" />`, sign);
34
- return prependLineFeedForParagraph(match, placeHolder);
35
- });
36
- }
37
-
38
- makeHtml(str, sentenceMakeFunc) {
39
- return str;
40
- }
41
-
42
- rule() {
43
- // 分割线必须有从新行开始,比如以换行结束
44
- const ret = {
45
- begin: '(?:^|\\n)(\\n*)[ ]*',
46
- end: '(?=$|\\n)',
47
- content: '((?:-[ \\t]*){3,}|(?:\\*[ \\t]*){3,}|(?:_[ \\t]*){3,})',
48
- };
49
- ret.reg = new RegExp(ret.begin + ret.content + ret.end, 'g');
50
- return ret;
51
- }
52
- }
@@ -1,199 +0,0 @@
1
- /**
2
- * Copyright (C) 2021 THL A29 Limited, a Tencent company.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import ParagraphBase from '@/core/ParagraphBase';
17
- import {
18
- whiteList,
19
- convertHTMLNumberToName,
20
- // isValidScheme, encodeURIOnce,
21
- escapeHTMLEntitiesWithoutSemicolon,
22
- } from '@/utils/sanitize';
23
- import { sanitizer } from '@/Sanitizer';
24
- import { isBrowser } from '@/utils/env';
25
-
26
- /**
27
- * encode unsafe link-related attributes
28
- */
29
- const unsafeAttributes = ['href', 'src'];
30
-
31
- sanitizer.addHook('afterSanitizeAttributes', (node) => {
32
- unsafeAttributes.forEach((attr) => {
33
- if (!node.hasAttribute(attr)) {
34
- return;
35
- }
36
- const value = node.getAttribute(attr);
37
- // encode unsafe backslash in link attributes
38
- node.setAttribute(attr, value.replace(/\\/g, '%5c'));
39
- });
40
- });
41
-
42
- export default class HtmlBlock extends ParagraphBase {
43
- static HOOK_NAME = 'htmlBlock';
44
- constructor({ config }) {
45
- super({ needCache: true });
46
- this.filterStyle = config.filterStyle || false;
47
- }
48
-
49
- // ref: http://www.vfmd.org/vfmd-spec/specification/#procedure-for-detecting-automatic-links
50
- isAutoLinkTag(tagMatch) {
51
- const REGEX_GROUP = [
52
- /^<([a-z][a-z0-9+.-]{1,31}:\/\/[^<> `]+)>$/i,
53
- /^<(mailto:[^<> `]+)>$/i,
54
- /^<([^()<>[\]:'@\\,"\s`]+@[^()<>[\]:'@\\,"\s`.]+\.[^()<>[\]:'@\\,"\s`]+)>$/i,
55
- ];
56
- return REGEX_GROUP.some((regex) => regex.test(tagMatch));
57
- }
58
-
59
- isHtmlComment(match) {
60
- const htmlComment = /^<!--.*?-->$/;
61
- return htmlComment.test(match);
62
- }
63
-
64
- beforeMakeHtml(str, sentenceMakeFunc) {
65
- if (this.$engine.htmlWhiteListAppend) {
66
- /**
67
- * @property
68
- * @type {false | RegExp}
69
- */
70
- this.htmlWhiteListAppend = new RegExp(`^(${this.$engine.htmlWhiteListAppend})( |$|/)`, 'i');
71
- /**
72
- * @property
73
- * @type {string[]}
74
- */
75
- this.htmlWhiteList = this.$engine.htmlWhiteListAppend.split('|');
76
- } else {
77
- this.htmlWhiteListAppend = false;
78
- this.htmlWhiteList = [];
79
- }
80
- let htmlBlackList = /^[ ]+/i;
81
- if (this.$engine.htmlBlackList) {
82
- htmlBlackList = /\*/.test(this.$engine.htmlBlackList)
83
- ? /^[^ ]+( |$|\/)/i
84
- : new RegExp(`^(${this.$engine.htmlBlackList})( |$|/)`, 'i');
85
- }
86
-
87
- let $str = str;
88
- $str = convertHTMLNumberToName($str);
89
- $str = escapeHTMLEntitiesWithoutSemicolon($str);
90
- $str = $str.replace(/<[/]?([^<]*?)>/g, (whole, m1) => {
91
- if (htmlBlackList && htmlBlackList.test(m1) && !this.isAutoLinkTag(whole) && !this.isHtmlComment(whole)) {
92
- return whole.replace(/</g, '&#60;').replace(/>/g, '&#62;');
93
- }
94
- // 匹配到非白名单且非AutoLink语法的尖括号会被转义
95
- // 如果是HTML注释,放行
96
- if (!whiteList.test(m1) && !this.isAutoLinkTag(whole) && !this.isHtmlComment(whole)) {
97
- if (this.htmlWhiteListAppend === false || !this.htmlWhiteListAppend.test(m1)) {
98
- return whole.replace(/</g, '&#60;').replace(/>/g, '&#62;');
99
- }
100
- }
101
- let wholeStr = whole;
102
- // 识别<a>和<img>标签的href和src属性,并触发urlProcessor回调
103
- m1.replace(/^a .*? href="([^"]+)"/, (all, href) => {
104
- const processedURL = this.$engine.urlProcessor(href, 'link');
105
- wholeStr = wholeStr.replace(/ href="[^"]+"/, ` href="${processedURL}"`);
106
- });
107
- m1.replace(/^a href="([^"]+)"/, (all, href) => {
108
- const processedURL = this.$engine.urlProcessor(href, 'link');
109
- wholeStr = wholeStr.replace(/ href="[^"]+"/, ` href="${processedURL}"`);
110
- });
111
- m1.replace(/^img .*? src="([^"]+)"/, (all, src) => {
112
- const processedURL = this.$engine.urlProcessor(src, 'image');
113
- wholeStr = wholeStr.replace(/ src="[^"]+"/, ` src="${processedURL}"`);
114
- });
115
- m1.replace(/^img src="([^"]+)"/, (all, src) => {
116
- const processedURL = this.$engine.urlProcessor(src, 'image');
117
- wholeStr = wholeStr.replace(/ src="[^"]+"/, ` src="${processedURL}"`);
118
- });
119
-
120
- // 到达此分支的包含被尖括号包裹的AutoLink语法以及在白名单内的HTML标签
121
- // 没有被AutoLink解析并渲染的标签会被DOMPurify过滤掉,正常情况下不会出现遗漏
122
- // 临时替换完整的HTML标签首尾为$#60;和$#62;,供下一步剔除损坏的HTML标签
123
- return wholeStr.replace(/</g, '$#60;').replace(/>/g, '$#62;');
124
- });
125
- // 替换所有形如「<abcd」和「</abcd」的左尖括号
126
- $str = $str.replace(/<(?=\/?(\w|\n|$))/g, '&#60;');
127
- // 还原被替换的尖括号
128
- $str = $str.replace(/\$#60;/g, '<').replace(/\$#62;/g, '>');
129
- // 针对 \< 和 \> 进行转义
130
- $str = $str
131
- .replace(/\\&#60;/g, '&lt;')
132
- .replace(/\\&#62;/g, '&gt;')
133
- .replace(/\\</g, '&lt;')
134
- .replace(/\\>/g, '&gt;');
135
- // 过滤HTML标签的style属性
136
- if (this.filterStyle) {
137
- $str = $str.replace(/<([^/][^>]+?) style="[^>\n]+?"([^>\n]*)>/gi, '<$1$2>');
138
- $str = $str.replace(/<([^/][^>]+?) style='[^>\n]+?'([^>\n]*)>/gi, '<$1$2>');
139
- }
140
- return $str;
141
- }
142
-
143
- // beforeMakeHtml(str) {
144
- // return str;
145
- // }
146
-
147
- makeHtml(str, sentenceMakeFunc) {
148
- return str;
149
- }
150
-
151
- afterMakeHtml(str) {
152
- let $str = str;
153
- const config = {
154
- ALLOW_UNKNOWN_PROTOCOLS: true,
155
- ADD_ATTR: ['target'],
156
- };
157
- if (this.htmlWhiteListAppend !== false) {
158
- config.ADD_TAGS = this.htmlWhiteList;
159
- if (this.htmlWhiteListAppend.test('style') || this.htmlWhiteListAppend.test('ALL')) {
160
- $str = $str.replace(/<style(>| [^>]*>).*?<\/style>/gi, (match) => {
161
- return match.replace(/<br>/gi, '');
162
- });
163
- }
164
- if (this.htmlWhiteListAppend.test('iframe') || this.htmlWhiteListAppend.test('ALL')) {
165
- config.ADD_ATTR = config.ADD_ATTR.concat([
166
- 'align',
167
- 'frameborder',
168
- 'height',
169
- 'longdesc',
170
- 'marginheight',
171
- 'marginwidth',
172
- 'name',
173
- 'sandbox',
174
- 'scrolling',
175
- 'seamless',
176
- 'src',
177
- 'srcdoc',
178
- 'width',
179
- ]);
180
- config.SANITIZE_DOM = false;
181
- $str = $str.replace(/<iframe(>| [^>]*>).*?<\/iframe>/gi, (match) => {
182
- return match.replace(/<br>/gi, '').replace(/\n/g, '');
183
- });
184
- }
185
- if (this.htmlWhiteListAppend.test('script') || this.htmlWhiteListAppend.test('ALL')) {
186
- // 如果允许script或者输入了ALL,则不做任何过滤了
187
- $str = $str.replace(/<script(>| [^>]*>).*?<\/script>/gi, (match) => {
188
- return match.replace(/<br>/gi, '');
189
- });
190
- return $str;
191
- }
192
- }
193
- // node 环境下不输出sign和lines
194
- if (!isBrowser()) {
195
- config.FORBID_ATTR = ['data-sign', 'data-lines'];
196
- }
197
- return sanitizer.sanitize($str, config);
198
- }
199
- }
@@ -1,174 +0,0 @@
1
- /**
2
- * Copyright (C) 2021 THL A29 Limited, a Tencent company.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import SyntaxBase from '@/core/SyntaxBase';
17
- import { escapeHTMLSpecialCharOnce as $e, encodeURIOnce } from '@/utils/sanitize';
18
- import imgAltHelper from '@/utils/image';
19
- import { compileRegExp, isLookbehindSupported, NOT_ALL_WHITE_SPACES_INLINE } from '@/utils/regexp';
20
- import { replaceLookbehind } from '@/utils/lookbehind-replace';
21
- import UrlCache from '@/UrlCache';
22
-
23
- export default class Image extends SyntaxBase {
24
- static HOOK_NAME = 'image';
25
-
26
- constructor({ config, globalConfig }) {
27
- super(null);
28
- this.config = config;
29
- // TODO: URL Validator
30
- this.extendMedia = { tag: ['video', 'audio'] };
31
- this.RULE = this.rule(this.extendMedia);
32
- }
33
-
34
- replaceToHtml(type, match, leadingChar, alt, link, title, poster) {
35
- const refType = typeof link === 'undefined' ? 'ref' : 'url';
36
- let attrs = '';
37
- if (refType === 'ref') {
38
- // TODO: 全局引用
39
- return match;
40
- }
41
-
42
- if (refType === 'url') {
43
- const extent = imgAltHelper.processExtendAttributesInAlt(alt);
44
- let { extendStyles: style, extendClasses: classes } = imgAltHelper.processExtendStyleInAlt(alt);
45
- if (style) {
46
- style = ` style="${style}" `;
47
- }
48
- if (classes) {
49
- classes = ` class="${classes}" `;
50
- }
51
- attrs = title && title.trim() !== '' ? ` title="${$e(title)}"` : '';
52
- if (poster) {
53
- attrs += ` poster="${encodeURIOnce(poster)}"`;
54
- }
55
-
56
- const processedURL = this.$engine.urlProcessor(link, type);
57
- const defaultWrapper = `<${type} src="${UrlCache.set(
58
- encodeURIOnce(processedURL),
59
- )}"${attrs} ${extent} ${style} ${classes} controls="controls">${$e(alt || '')}</${type}>`;
60
- return `${leadingChar}${
61
- this.config.videoWrapper ? this.config.videoWrapper(link, type, defaultWrapper) : defaultWrapper
62
- }`;
63
- }
64
- // should never happen
65
- return match;
66
- }
67
-
68
- toHtml(match, leadingChar, alt, link, title, ref, extendAttrs) {
69
- // console.log(match, alt, link, ref, title);
70
- const refType = typeof link === 'undefined' ? 'ref' : 'url';
71
- let attrs = '';
72
- if (refType === 'ref') {
73
- // 全局引用,理应在CommentReference中被替换,没有被替换说明没有定义引用项
74
- return match;
75
- }
76
- if (refType === 'url') {
77
- const extent = imgAltHelper.processExtendAttributesInAlt(alt);
78
- let { extendStyles: style, extendClasses: classes } = imgAltHelper.processExtendStyleInAlt(alt);
79
- if (style) {
80
- style = ` style="${style}" `;
81
- }
82
- if (classes) {
83
- classes = ` class="${classes}" `;
84
- }
85
- attrs = title && title.trim() !== '' ? ` title="${$e(title.replace(/["']/g, ''))}"` : '';
86
- let srcProp = 'src';
87
- let srcValue;
88
- const cherryOptions = this.$engine.$cherry.options;
89
- if (cherryOptions.callback && cherryOptions.callback.beforeImageMounted) {
90
- const imgAttrs = cherryOptions.callback.beforeImageMounted(srcProp, link);
91
- srcProp = imgAttrs.srcProp || srcProp;
92
- srcValue = imgAttrs.src || link;
93
- }
94
- const extendAttrStr = extendAttrs
95
- ? extendAttrs
96
- .replace(/[{}]/g, '')
97
- .replace(/([^=\s]+)=([^\s]+)/g, '$1="$2"')
98
- .replace(/&/g, '&amp;') // 对&多做一次转义,cherry现有的机制会自动把&amp;转成&,只有多做一次转义才能抵消cherry的机制
99
- : '';
100
- return `${leadingChar}<img ${srcProp}="${UrlCache.set(
101
- encodeURIOnce(this.$engine.urlProcessor(srcValue, 'image')),
102
- )}" ${extent} ${style} ${classes} alt="${$e(alt || '')}"${attrs} ${extendAttrStr}/>`;
103
- }
104
- // should never happen
105
- return match;
106
- }
107
-
108
- toMediaHtml(match, leadingChar, mediaType, alt, link, title, ref, posterWrap, poster, ...args) {
109
- if (!/(video|audio)/.test(mediaType)) {
110
- return match;
111
- }
112
- return this.replaceToHtml(mediaType, match, leadingChar, alt, link, title, poster);
113
- }
114
-
115
- makeHtml(str) {
116
- let $str = str;
117
- if (this.test($str)) {
118
- if (isLookbehindSupported()) {
119
- $str = $str.replace(this.RULE.reg, this.toHtml.bind(this));
120
- } else {
121
- $str = replaceLookbehind($str, this.RULE.reg, this.toHtml.bind(this), true, 1);
122
- }
123
- }
124
- if (this.testMedia($str)) {
125
- if (isLookbehindSupported()) {
126
- $str = $str.replace(this.RULE.regExtend, this.toMediaHtml.bind(this));
127
- } else {
128
- $str = replaceLookbehind($str, this.RULE.regExtend, this.toMediaHtml.bind(this), true, 1);
129
- }
130
- }
131
- return $str;
132
- }
133
-
134
- // afterMakeHtml(str) {
135
- // return UrlCache.restoreAll(str);
136
- // }
137
-
138
- testMedia(str) {
139
- return this.RULE.regExtend && this.RULE.regExtend.test(str);
140
- }
141
-
142
- rule(extendMedia) {
143
- const ret = {
144
- // lookbehind启用分组是为了和不兼容lookbehind的场景共用一个回调
145
- begin: isLookbehindSupported() ? '((?<!\\\\))!' : '(^|[^\\\\])!',
146
- content: [
147
- '\\[([^\\n]*?)\\]', // ?<alt>
148
- '[ \\t]*', // any spaces
149
- `${
150
- '(?:' +
151
- '\\(' +
152
- '((?:[^\\s()]*\\([^\\s()]*\\)[^\\s()]*)+|(?:[^"][^\\s]+?))' + // ?<link> url
153
- '(?:[ \\t]((?:".*?")|(?:\'.*?\')))?' + // ?<title> optional
154
- '\\)' +
155
- '|' + // or
156
- '\\[('
157
- }${NOT_ALL_WHITE_SPACES_INLINE})\\]` + // ?<ref> global ref
158
- ')',
159
- ].join(''),
160
- end: '({[^{}]+?})?', // extend attrs e.g. {width=50 height=60}
161
- };
162
- if (extendMedia) {
163
- const extend = { ...ret };
164
- // TODO: 支持Lookbehind
165
- extend.begin = isLookbehindSupported()
166
- ? `((?<!\\\\))!(${extendMedia.tag.join('|')})`
167
- : `(^|[^\\\\])!(${extendMedia.tag.join('|')})`;
168
- extend.end = '({poster=(.*)})?';
169
- ret.regExtend = compileRegExp(extend, 'g');
170
- }
171
- ret.reg = compileRegExp(ret, 'g');
172
- return ret;
173
- }
174
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Copyright (C) 2021 THL A29 Limited, a Tencent company.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import ParagraphBase from '@/core/ParagraphBase';
17
- import CodeBlock from './CodeBlock';
18
- import { compileRegExp } from '@/utils/regexp';
19
-
20
- export default class InlineCode extends ParagraphBase {
21
- static HOOK_NAME = 'inlineCode';
22
-
23
- // constructor() {
24
- // super();
25
- // }
26
-
27
- makeHtml(str) {
28
- return str;
29
- }
30
-
31
- afterMakeHtml(str) {
32
- let $str = str;
33
- if (Object.keys(CodeBlock.inlineCodeCache).length > 0) {
34
- $str = $str.replace(/~~CODE([0-9a-zA-Z]+)\$/g, (match, sign) => CodeBlock.inlineCodeCache[sign]);
35
- }
36
- return $str;
37
- }
38
-
39
- $cleanCache() {
40
- CodeBlock.inlineCodeCache = {};
41
- }
42
-
43
- rule() {
44
- const ret = { begin: '(`+)[ ]*', end: '[ ]*\\1', content: '(.+?(?:\\n.+?)*?)' };
45
- ret.reg = compileRegExp(ret, 'g');
46
- return ret;
47
- }
48
- }
@@ -1,108 +0,0 @@
1
- /**
2
- * Copyright (C) 2021 THL A29 Limited, a Tencent company.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import ParagraphBase from '@/core/ParagraphBase';
17
- import { escapeFormulaPunctuations, LoadMathModule } from '@/utils/mathjax';
18
- import { getHTML } from '@/utils/dom';
19
- import { isBrowser } from '@/utils/env';
20
- import { getTableRule, isLookbehindSupported } from '@/utils/regexp';
21
- import { replaceLookbehind } from '@/utils/lookbehind-replace';
22
-
23
- /**
24
- * 行内公式的语法
25
- * 虽然叫做行内公式,Cherry依然将其视为“段落级语法”,因为其具备排他性并且需要优先渲染
26
- */
27
- export default class InlineMath extends ParagraphBase {
28
- static HOOK_NAME = 'inlineMath';
29
- /** @type {'katex' | 'MathJax' | 'node'} */
30
- engine = 'MathJax'; // 渲染引擎,默认为MathJax,MathJax支持2.x与3.x版本
31
- katex;
32
- MathJax;
33
-
34
- constructor({ config }) {
35
- super({ needCache: true });
36
- // 非浏览器环境下配置为 node
37
- this.engine = isBrowser() ? config.engine ?? 'MathJax' : 'node';
38
- }
39
-
40
- toHtml(wholeMatch, leadingChar, m1) {
41
- if (!m1) {
42
- return wholeMatch;
43
- }
44
- LoadMathModule.bind(this)('engine');
45
- const linesArr = m1.match(/\n/g);
46
- const lines = linesArr ? linesArr.length + 2 : 2;
47
- const sign = this.$engine.hash(wholeMatch);
48
- const $m1 = m1.replace(/\\~D/g, '$').replace(/\\~T/g, '~').replace(/~T/g, '~');
49
- // 既无MathJax又无katex时,原样输出
50
- let result = '';
51
- if (this.engine === 'katex' && this.katex?.renderToString) {
52
- // katex渲染
53
- const html = this.katex.renderToString($m1, {
54
- throwOnError: false,
55
- });
56
- result = `${leadingChar}<span class="Cherry-InlineMath" data-type="mathBlock" data-lines="${lines}">${html}</span>`;
57
- } else if (this.MathJax?.tex2svg) {
58
- // MathJax渲染
59
- const svg = getHTML(this.MathJax.tex2svg($m1, { em: 12, ex: 6, display: false }), true);
60
- result = `${leadingChar}<span class="Cherry-InlineMath" data-type="mathBlock" data-lines="${lines}">${svg}</span>`;
61
- } else {
62
- result = `${leadingChar}<span class="Cherry-InlineMath" data-type="mathBlock"
63
- data-lines="${lines}">$${escapeFormulaPunctuations(m1)}$</span>`;
64
- }
65
-
66
- return this.pushCache(result, ParagraphBase.IN_PARAGRAPH_CACHE_KEY_PREFIX + sign);
67
- }
68
-
69
- beforeMakeHtml(str) {
70
- let $str = str;
71
- // 格里处理行内公式,让一个td里的行内公式语法生效,让跨td的行内公式语法失效
72
- $str = $str.replace(getTableRule(true), (whole, ...args) => {
73
- return whole
74
- .split('|')
75
- .map((oneTd) => {
76
- return this.makeInlineMath(oneTd);
77
- })
78
- .join('|')
79
- .replace(/\\~D/g, '~D') // 出现反斜杠的情况(如/$e=m^2$)会导致多一个反斜杠,这里替换掉
80
- .replace(/~D/g, '\\~D');
81
- });
82
- return this.makeInlineMath($str);
83
- }
84
-
85
- makeInlineMath(str) {
86
- if (!this.test(str)) {
87
- return str;
88
- }
89
- if (isLookbehindSupported()) {
90
- return str.replace(this.RULE.reg, this.toHtml.bind(this));
91
- }
92
- return replaceLookbehind(str, this.RULE.reg, this.toHtml.bind(this), true, 1);
93
- }
94
-
95
- makeHtml(str) {
96
- return str;
97
- }
98
-
99
- rule() {
100
- const ret = {
101
- begin: isLookbehindSupported() ? '((?<!\\\\))~D\\n?' : '(^|[^\\\\])~D\\n?',
102
- content: '(.*?)\\n?',
103
- end: isLookbehindSupported() ? '((?<!\\\\))~D' : '[^\\\\]~D',
104
- };
105
- ret.reg = new RegExp(ret.begin + ret.content + ret.end, 'g');
106
- return ret;
107
- }
108
- }