可以通过头部匹配
<!doctype html> <html> <head> <meta charset="utf-8"/> <title>Marked in the browser</title> </head> <body> <div id="content"></div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/marked.umd.min.js"></script> <script> // 创建自定义渲染器 const renderer = new marked.Renderer(); // 重写 paragraph 方法来处理自定义段落 renderer.paragraph = function(text) { if (text.startsWith(':customparagraph:')) { return `<p class="custom-paragraph">${text.replace(':customparagraph:', '')}</p>\n`; } return `<p>${text}</p>\n`; }; // 使用自定义渲染器 marked.setOptions({ renderer: renderer }); const markdown = ` :customparagraph: This is a custom paragraph content. :aet: This is a custom paragraph content. `; document.getElementById('content').innerHTML = marked.parse(markdown); </script> </body> </html>
网友回复