mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
4.6.5- CoreferenceResolution Module (#631)
This commit is contained in:
35
packages/web/common/string/markdown.ts
Normal file
35
packages/web/common/string/markdown.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import TurndownService from 'turndown';
|
||||
// @ts-ignore
|
||||
import * as turndownPluginGfm from 'joplin-turndown-plugin-gfm';
|
||||
|
||||
const turndownService = new TurndownService({
|
||||
headingStyle: 'atx',
|
||||
bulletListMarker: '-',
|
||||
codeBlockStyle: 'fenced',
|
||||
fence: '```',
|
||||
emDelimiter: '_',
|
||||
strongDelimiter: '**',
|
||||
linkStyle: 'inlined',
|
||||
linkReferenceStyle: 'full'
|
||||
});
|
||||
export const htmlStr2Md = (html: string) => {
|
||||
// 浏览器,html字符串转dom
|
||||
const parser = new DOMParser();
|
||||
const dom = parser.parseFromString(html, 'text/html');
|
||||
|
||||
turndownService.remove(['i', 'script', 'iframe']);
|
||||
turndownService.addRule('codeBlock', {
|
||||
filter: 'pre',
|
||||
replacement(_, node) {
|
||||
const content = node.textContent?.trim() || '';
|
||||
// @ts-ignore
|
||||
const codeName = node?._attrsByQName?.class?.data?.trim() || '';
|
||||
|
||||
return `\n\`\`\`${codeName}\n${content}\n\`\`\`\n`;
|
||||
}
|
||||
});
|
||||
|
||||
turndownService.use(turndownPluginGfm.gfm);
|
||||
|
||||
return turndownService.turndown(dom);
|
||||
};
|
@@ -1,6 +1,11 @@
|
||||
{
|
||||
"name": "@fastgpt/web",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {},
|
||||
"devDependencies": {}
|
||||
"dependencies": {
|
||||
"joplin-turndown-plugin-gfm": "^1.0.12",
|
||||
"turndown": "^7.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/turndown": "^5.0.4"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user