mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-28 17:29:44 +00:00
v4.6.5 (#620)
This commit is contained in:
23
packages/service/common/string/markdown.ts
Normal file
23
packages/service/common/string/markdown.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { simpleMarkdownText } from '@fastgpt/global/common/string/markdown';
|
||||
import { Worker } from 'worker_threads';
|
||||
import { getWorkerPath } from './utils';
|
||||
|
||||
/* html string to markdown */
|
||||
export const htmlToMarkdown = (html?: string | null) =>
|
||||
new Promise<string>((resolve, reject) => {
|
||||
if (!html) return resolve('');
|
||||
|
||||
const start = Date.now();
|
||||
|
||||
// worker
|
||||
const worker = new Worker(getWorkerPath('html2md'));
|
||||
|
||||
worker.on('message', (md: string) => {
|
||||
resolve(simpleMarkdownText(md));
|
||||
});
|
||||
worker.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
worker.postMessage(html);
|
||||
});
|
Reference in New Issue
Block a user