mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
37 lines
1.0 KiB
JavaScript
Vendored
37 lines
1.0 KiB
JavaScript
Vendored
var ExportMD = (function () {
|
|
if (!TurndownService || !turndownPluginGfm) return;
|
|
const hljsREG = /^.*(hljs).*(language-[a-z0-9]+).*$/i;
|
|
const gfm = turndownPluginGfm.gfm
|
|
const turndownService = new TurndownService()
|
|
.use(gfm)
|
|
.addRule('code', {
|
|
filter: (node) => {
|
|
if (node.nodeName === 'CODE' && hljsREG.test(node.classList.value)) {
|
|
return 'code';
|
|
}
|
|
},
|
|
replacement: (content, node) => {
|
|
const classStr = node.getAttribute('class');
|
|
if (hljsREG.test(classStr)) {
|
|
const lang = classStr.match(/.*language-(\w+)/)[1];
|
|
if (lang) {
|
|
return `\`\`\`${lang}\n${content}\n\`\`\``;
|
|
}
|
|
return `\`\`\`\n${content}\n\`\`\``;
|
|
}
|
|
}
|
|
})
|
|
.addRule('ignore', {
|
|
filter: ['button', 'img'],
|
|
replacement: () => '',
|
|
})
|
|
.addRule('table', {
|
|
filter: 'table',
|
|
replacement: function(content, node) {
|
|
return `\`\`\`${content}\n\`\`\``;
|
|
},
|
|
});
|
|
|
|
return turndownService;
|
|
}({}));
|