mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 22:03:54 +00:00

* fix: icon * fix: web selector * fix: web selector * perf: link sync * dev doc * chomd doc * perf: git intro * 466 intro * intro img * add json editor (#5) * team limit * websync limit * json editor * text editor * perf: search test * change cq value type * doc * intro img --------- Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
30 lines
758 B
TypeScript
30 lines
758 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) => {
|
|
worker.terminate();
|
|
|
|
resolve(simpleMarkdownText(md));
|
|
});
|
|
worker.on('error', (err) => {
|
|
worker.terminate();
|
|
reject(err);
|
|
});
|
|
worker.on('exit', (code) => {
|
|
console.log('html 2 md finish', code);
|
|
});
|
|
|
|
worker.postMessage(html);
|
|
});
|