cherry-markdown
cherry-markdown copied to clipboard
CherryEngine传入 customSyntax 无效?
Prerequisites
- [ ] There isn't an existing issue that reports the same bug to avoid duplicates.
- [ ] The provided information offers a minimal reproducible example of the bug.
- [ ] For Q&A, please open a GitHub Discussion instead.
Describe the Bug
const myBlockHook = Cherry.createSyntaxHook('myBlock', Cherry.constants.HOOKS_TYPE_LIST.PAR, {
needCache: true, // 表明要使用缓存,也是实现排他的必要操作
makeHtml(str) {
const that = this;
return str.replace(this.RULE.reg, function (whole, m1) {
const result = `\n<div style="border: 1px solid;border-radius: 15px;background: gold;">${m1}</div>\n`;
return that.pushCache(result); // 将结果转成占位符
});
},
rule(str) {
return { reg: /\n\+\+(\n[\s\S]+?\n)\+\+\n/g };
},
});
const cherryEngineInstance = new CherryEngine({
engine: {
customSyntax: {
// importHook: {
// syntaxClass: imgHook, // 将自定义语法对象挂载到 importHook.syntaxClass上
// force: true, // true: 当cherry自带的语法中也有一个“importHook”时,用自定义的语法覆盖默认语法; false:不覆盖
// before: 'fontEmphasis', // 定义该自定义语法的执行顺序,当前例子表明在加粗/斜体语法前执行该自定义语法
// },
importHook: {
syntaxClass: myBlockHook, // 将自定义语法对象挂载到 importHook.syntaxClass上
// force: true, // true: 当cherry自带的语法中也有一个“importHook”时,用自定义的语法覆盖默认语法; false:不覆盖
before: 'blockquote', // 定义该自定义语法的执行顺序,当前例子表明在加粗/斜体语法前执行该自定义语法
},
},
},
})
cherryEngineInstance.makeHtml(`\n++\n XXX \n++\n`);
Reproduction Steps
No response
System Information
No response
Contributing
None
CherryEngine 似乎并没有支持,可以考虑 const cherry = new Cherry(),然后用 cherry.engine.makeHtml(md) 实现把md转成html的功能