mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-04-05 17:15:20 +08:00
29 lines
788 B
Go
29 lines
788 B
Go
|
|
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)
|
|
}
|
|
} |