feat: htmlToMarkdown (#968)

This commit is contained in:
zhanzhenping
2024-07-15 16:35:12 +08:00
committed by GitHub
parent d8064f168a
commit 1a98d15212
8 changed files with 1029 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
class HtmlToMarkdownConverter {
handleFileSelect(callback, accept = '.html,.htm') {
let input = document.createElement('input');
input.type = 'file';
input.accept = accept;
input.onchange = (e)=>{
let file = e.target.files[0];
if (!file) {
return;
}
let reader = new FileReader();
reader.onload = (e)=>{
let text = e.target.result;
let markdown = this.convertToMarkdown(text);
callback(markdown);
};
reader.readAsText(file);
};
input.click();
}
convertToMarkdown(html) {
let turndownService = new TurndownService()
return turndownService.turndown(html)
}
}