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/README.md +7 -0
- package/dist/cherry-markdown.core.common.js +1 -1
- package/dist/cherry-markdown.core.js +1 -1
- package/dist/cherry-markdown.engine.core.common.js +1 -1
- package/dist/cherry-markdown.engine.core.esm.js +1 -1
- package/dist/cherry-markdown.engine.core.js +1 -1
- package/dist/cherry-markdown.esm.js +1 -1
- package/dist/cherry-markdown.js +37 -42
- package/dist/cherry-markdown.js.map +1 -1
- package/dist/cherry-markdown.min.js +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
- package/src/Cherry.config.js +0 -1
- package/src/Stats.js +0 -2
- package/src/core/hooks/CodeBlock.js +11 -14
package/package.json
CHANGED
package/src/Cherry.config.js
CHANGED
package/src/Stats.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import ParagraphBase from '@/core/ParagraphBase';
|
|
17
17
|
import Prism from 'prismjs';
|
|
18
|
-
import { escapeHTMLSpecialChar
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
642
|
+
console.warn(`${clazz} not found after ${times} retries`);
|
|
647
643
|
return;
|
|
648
644
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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(
|
|
651
|
+
cb(elements);
|
|
655
652
|
}
|
|
656
653
|
}
|
|
657
654
|
|