1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-02 22:49:09 +02:00

Desktop: WYSIWYG: Preserve HTML code in Markdown when editing from wysiwyg editor

This commit is contained in:
Laurent Cozic
2020-04-10 17:12:41 +00:00
parent 12a7b3c73c
commit bd99b25848
21 changed files with 139 additions and 71 deletions

View File

@@ -70,7 +70,13 @@ class HtmlUtils {
return selfClosingElements.includes(tagName.toLowerCase());
}
sanitizeHtml(html) {
sanitizeHtml(html, options = null) {
options = Object.assign({}, {
// If true, adds a "jop-noMdConv" class to all the tags.
// It can be used afterwards to restore HTML tags in Markdown.
addNoMdConvClass: false,
}, options);
const htmlparser2 = require('htmlparser2');
const output = [];
@@ -95,6 +101,15 @@ class HtmlUtils {
for (const eventName of JS_EVENT_NAMES) {
delete attrs[eventName];
}
if (options.addNoMdConvClass) {
let classAttr = attrs['class'] || '';
if (!classAttr.includes('jop-noMdConv')) {
classAttr += ' jop-noMdConv';
attrs['class'] = classAttr.trim();
}
}
let attrHtml = this.attributesHtml(attrs);
if (attrHtml) attrHtml = ` ${attrHtml}`;
const closingSign = this.isSelfClosingTag(name) ? '/>' : '>';