【问题标题】:How to particular text replace in md files using ngx-markdown如何使用 ngx-markdown 替换 md 文件中的特定文本
【发布时间】:2023-01-24 15:36:32
【问题描述】:
在 md 文件中 +++label+++ 文本是可用的。所以我需要用其他文本替换此文本。
我尝试使用 markdownService.renderer.text 但文本不正确所以我无法替换文本。
如何替换此文本?
this.markdownService.renderer.text = (text: string) => { console.log('text',text); }
【问题讨论】:
标签:
angular
typescript
markdown
【解决方案1】:
您可以使用 ngx-markdown 库提供的 MarkedOptions 对象来自定义渲染器并替换您想要的文本。
您可以使用 MarkedOptions 对象的渲染器属性来设置自定义渲染器函数,该函数将为降价中的每个文本块调用。
下面是一个示例,说明如何使用渲染器属性将“+++label+++”文本替换为不同的字符串:
import { MarkedOptions } from 'ngx-markdown';
const markedOptions: MarkedOptions = {
renderer: new marked.Renderer(),
gfm: true,
breaks: false,
pedantic: false,
smartLists: true,
smartypants: false,
};
markedOptions.renderer.text = (text: string) => {
return text.replace(/+++label+++/g, 'REPLACED TEXT');
};
this.markdownService.setOptions(markedOptions);