mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 11:43:56 +00:00
24 lines
618 B
TypeScript
24 lines
618 B
TypeScript
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);
|
|
});
|