Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CherryEngine传入 customSyntax 无效? #905

Open
3 tasks
PDieE opened this issue Sep 12, 2024 · 1 comment
Open
3 tasks

CherryEngine传入 customSyntax 无效? #905

PDieE opened this issue Sep 12, 2024 · 1 comment
Labels
🐞bug Something isn't working

Comments

@PDieE
Copy link

PDieE commented Sep 12, 2024

Prerequisites

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

@PDieE PDieE added the 🐞bug Something isn't working label Sep 12, 2024
@sunsonliu
Copy link
Collaborator

CherryEngine 似乎并没有支持,可以考虑 const cherry = new Cherry(),然后用 cherry.engine.makeHtml(md) 实现把md转成html的功能

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants