mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 22:47:03 +03:00
Added option to convert HTML to Markdown instead of plain, using Turndown #1604
This commit is contained in:
parent
d3b0d6ca57
commit
8fb7067531
45 changed files with 201 additions and 135 deletions
|
|
@ -4,6 +4,9 @@ import { SettingsUserStore } from 'Stores/User/Settings';
|
|||
|
||||
const
|
||||
tmpl = createElement('template'),
|
||||
|
||||
turndown = new TurndownService(),
|
||||
|
||||
htmlre = /[&<>"']/g,
|
||||
httpre = /^(https?:)?\/\//i,
|
||||
htmlmap = {
|
||||
|
|
@ -604,6 +607,9 @@ export const
|
|||
* @returns {string}
|
||||
*/
|
||||
htmlToPlain = html => {
|
||||
if (SettingsUserStore.markdown()) {
|
||||
return htmlToMarkdown(html);
|
||||
}
|
||||
const
|
||||
hr = '⎯'.repeat(64),
|
||||
forEach = (selector, fn) => tmpl.content.querySelectorAll(selector).forEach(fn),
|
||||
|
|
@ -640,6 +646,8 @@ export const
|
|||
.replace(/<t[dh](\s[\s\S]*?)?>/gi, '\t')
|
||||
.replace(/<\/tr(\s[\s\S]*?)?>/gi, '\n');
|
||||
|
||||
forEach('style', node => node.remove());
|
||||
|
||||
// lines
|
||||
forEach('hr', node => node.replaceWith(`\n\n${hr}\n\n`));
|
||||
|
||||
|
|
@ -700,6 +708,11 @@ export const
|
|||
return (tmpl.content.textContent || '').trim();
|
||||
},
|
||||
|
||||
htmlToMarkdown = html => {
|
||||
tmpl.innerHTML = html;
|
||||
return turndown.turndown(tmpl.content);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string} plain
|
||||
* @param {boolean} findEmailAndLinksInText = false
|
||||
|
|
@ -771,5 +784,7 @@ export const
|
|||
|
||||
rl.Utils = {
|
||||
htmlToPlain: htmlToPlain,
|
||||
plainToHtml: plainToHtml
|
||||
plainToHtml: plainToHtml,
|
||||
htmlToMarkdown: htmlToMarkdown
|
||||
// markdownToHtml: md => marked.parse(md)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ export const
|
|||
|
||||
proxy = url =>
|
||||
BASE + '?/ProxyExternal/'
|
||||
// + btoa(JSON.stringify([token,url]).replace(/ /g, '%20')).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
|
||||
+ btoa(url.replace(/ /g, '%20')).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
|
||||
// + b64EncodeJSONSafe(url.replace(/ /g, '%20')),
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue