Tencent / Tencent/cherry-markdown

CherryEngine传入 customSyntax 无效?

Open
#905 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐞bug
Dominant language
JavaScript
Stars
4.9k
Forks
572
Avg merge
17h 5m
Merged PRs (30d)
14

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied CherryEngine construction and makeHtml call, then trace how engine.customSyntax.importHook registers myBlockHook and applies its before ordering. Done means determining why the custom syntax is ineffective and confirming that the sample ++...++ input renders the intended custom block.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.