cherry-muse 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cherry-muse",
3
3
  "license": "Apache-2.0",
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "description": "Lightweight Cherry Markdown fork with 83% smaller bundle size (800KB vs 4.8MB)",
6
6
  "repository": {
7
7
  "type": "git",
@@ -403,7 +403,6 @@ const defaultConfig = {
403
403
  locale: 'zh_CN',
404
404
  // cherry初始化后是否检查 location.hash 尝试滚动到对应位置
405
405
  autoScrollByHashAfterInit: true,
406
- stats: true,
407
406
  };
408
407
  if (window.outerWidth <= 600) {
409
408
  defaultConfig.toolbars.toolbar = ['switchModel'];
package/src/Stats.js CHANGED
@@ -3,8 +3,6 @@ import Event from '@/Event';
3
3
  export default class Stats {
4
4
  constructor(options) {
5
5
  this.$cherry = options.$cherry;
6
- console.log(options);
7
- if (!this.$cherry.options.stats) return;
8
6
  this.container = null;
9
7
  this.stats = {
10
8
  characters: 0,
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import ParagraphBase from '@/core/ParagraphBase';
17
17
  import Prism from 'prismjs';
18
- import { escapeHTMLSpecialChar, unescapeHTMLSpecialChar } from '@/utils/sanitize';
18
+ import { escapeHTMLSpecialChar } from '@/utils/sanitize';
19
19
  import { getTableRule, getCodeBlockRule } from '@/utils/regexp';
20
20
  import { prependLineFeedForParagraph } from '@/utils/lineFeed';
21
21
 
@@ -625,33 +625,30 @@ export default class CodeBlock extends ParagraphBase {
625
625
 
626
626
  $highlightCodeBlock(code, lang, clazz) {
627
627
  const language = lang;
628
- let cacheCode = Prism.highlight(unescapeHTMLSpecialChar(code), Prism.languages[language], language);
628
+ // 直接使用原始代码,不做 unescapeHTMLSpecialChar,避免破坏代码完整性
629
+ let cacheCode = Prism.highlight(code, Prism.languages[language], language);
629
630
  cacheCode = this.renderLineNumber(cacheCode);
630
631
  cacheCode = this.wrapCode(cacheCode, language);
631
632
  const cherry = this.$engine.$cherry;
632
- // 查找指定id
633
- setTimeout(function () {
634
- console.log(clazz, cherry.wrapperDom.querySelectorAll(clazz), document.querySelectorAll(clazz));
635
- }, 20000);
636
- this.$waitElement(clazz, 0, function (elements) {
633
+ this.$waitElement(cherry.wrapperDom, clazz, 0, (elements) => {
637
634
  elements.forEach((codeBlock) => {
638
635
  codeBlock.innerHTML = cacheCode;
639
636
  });
640
637
  });
641
638
  }
642
639
 
643
- $waitElement(clazz, times, cb) {
644
- const that = this;
640
+ $waitElement(container, clazz, times, cb) {
645
641
  if (times > 100) {
646
- console.warn(`times ${times} milliseconds, clazz ${clazz} not found`);
642
+ console.warn(`${clazz} not found after ${times} retries`);
647
643
  return;
648
644
  }
649
- if (document.querySelectorAll(clazz).length === 0) {
650
- setTimeout(function () {
651
- that.$waitElement(clazz, times + 1, cb);
645
+ const elements = container.querySelectorAll(clazz);
646
+ if (elements.length === 0) {
647
+ setTimeout(() => {
648
+ this.$waitElement(container, clazz, times + 1, cb);
652
649
  }, 500);
653
650
  } else {
654
- cb(document.querySelectorAll(clazz));
651
+ cb(elements);
655
652
  }
656
653
  }
657
654