mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-12-20 04:00:05 +08:00
feat: htmlToMarkdown (#968)
This commit is contained in:
29
static/js/html-to-markdown.js
Normal file
29
static/js/html-to-markdown.js
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user