var CustomHookA = Cherry.createSyntaxHook('codeBlock', Cherry.constants.HOOKS_TYPE_LIST.PAR, { makeHtml(str) { console.warn('custom hook', 'hello'); return str; }, rule(str) { const regex = { begin: '', content: '', end: '', }; regex.reg = new RegExp(regex.begin + regex.content + regex.end, 'g'); return regex; }, }); var cherryConfig1 = { id: 'markdown1', externals: { echarts: window.echarts, katex: window.katex, MathJax: window.MathJax, }, engine: { syntax: { fontEmphasis: { allowWhitespace: true, // 是否允许首尾空格 }, mathBlock: { engine: 'MathJax', // katex或MathJax src: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js', // 如果使用MathJax将js在此处引入,katex则需要将js提前引入 }, inlineMath: { engine: 'MathJax', // katex或MathJax }, emoji: { useUnicode: false, customResourceURL: 'https://github.githubassets.com/images/icons/emoji/unicode/${code}.png?v8', upperCase: true, }, // toc: { // tocStyle: 'nested' // } // 'header': { // strict: false // } }, customSyntax: { // SyntaxHookClass CustomHook: { syntaxClass: CustomHookA, force: false, after: 'br', }, }, }, toolbars: { toolbar: [ 'bold', 'italic', 'strikethrough', '|', 'color', 'header', '|', 'list', 'image', 'audio', 'video', 'link', 'hr', 'br', 'code', 'formula', 'toc', 'table', 'pdf', 'word', 'graph', ], toolbarRight: ['fullScreen'], sidebar: ['mobilePreview', 'copy', 'theme'], // 配置目录 toc: { updateLocationHash: false, // 要不要更新URL的hash defaultModel: 'full', // pure: 精简模式/缩略模式,只有一排小点; full: 完整模式,会展示所有标题 }, }, editor: { height: '600px', }, previewer: { // 自定义markdown预览区域class // className: 'markdown' }, keydown: [], //extensions: [], }; var cherryConfig2 = { id: 'markdown2', externals: { echarts: window.echarts, katex: window.katex, MathJax: window.MathJax, }, engine: { syntax: { fontEmphasis: { allowWhitespace: true, // 是否允许首尾空格 }, mathBlock: { engine: 'MathJax', // katex或MathJax src: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js', // 如果使用MathJax将js在此处引入,katex则需要将js提前引入 }, inlineMath: { engine: 'MathJax', // katex或MathJax }, emoji: { useUnicode: false, customResourceURL: 'https://github.githubassets.com/images/icons/emoji/unicode/${code}.png?v8', upperCase: true, }, // toc: { // tocStyle: 'nested' // } // 'header': { // strict: false // } }, customSyntax: { // SyntaxHookClass CustomHook: { syntaxClass: CustomHookA, force: false, after: 'br', }, }, }, toolbars: { toolbar: [ 'bold', 'italic', 'strikethrough', 'color', '|', 'list', { insert: ['image', 'audio', 'video', 'link', 'hr', 'br', 'code', 'formula', 'toc', 'table', 'pdf', 'word'] }, 'graph', 'fullScreen', 'settings', 'export' ], toolbarRight: ['fullScreen'], sidebar: ['copy', 'mobilePreview', 'theme'], // 配置目录 toc: { updateLocationHash: false, // 要不要更新URL的hash defaultModel: 'full', // pure: 精简模式/缩略模式,只有一排小点; full: 完整模式,会展示所有标题 }, }, editor: { height: '600px', }, previewer: { // 自定义markdown预览区域class // className: 'markdown' }, keydown: [], //extensions: [], }; fetch('./markdown/basic.md').then((response) => response.text()).then((value) => { var config1 = Object.assign({}, cherryConfig1, { value: value }); window.cherry1 = new Cherry(config1); // init with empty string for height test var config2 = Object.assign({}, cherryConfig2, { value: '' }); window.cherry2 = new Cherry(config2); });