diff --git a/packages/app-cli/tests/html_to_md/sub_sup_insert_strikethrough.html b/packages/app-cli/tests/html_to_md/sub_sup_insert_strikethrough.html index d1149f97cc..10db976c29 100644 --- a/packages/app-cli/tests/html_to_md/sub_sup_insert_strikethrough.html +++ b/packages/app-cli/tests/html_to_md/sub_sup_insert_strikethrough.html @@ -1 +1 @@ -X1 X1 Insert Strike \ No newline at end of file +X1 X1 Insert Insert alt Strike \ No newline at end of file diff --git a/packages/app-cli/tests/html_to_md/sub_sup_insert_strikethrough.md b/packages/app-cli/tests/html_to_md/sub_sup_insert_strikethrough.md index 2a17e25d65..2f15f103bc 100644 --- a/packages/app-cli/tests/html_to_md/sub_sup_insert_strikethrough.md +++ b/packages/app-cli/tests/html_to_md/sub_sup_insert_strikethrough.md @@ -1 +1 @@ -X1 X1 Insert ~~Strike~~ \ No newline at end of file +X1 X1 Insert Insert alt ~~Strike~~ \ No newline at end of file diff --git a/packages/turndown/src/commonmark-rules.js b/packages/turndown/src/commonmark-rules.js index fda46b78aa..475bf03c8e 100644 --- a/packages/turndown/src/commonmark-rules.js +++ b/packages/turndown/src/commonmark-rules.js @@ -1,4 +1,4 @@ -import { repeat, isCodeBlockSpecialCase1, isCodeBlockSpecialCase2, isCodeBlock } from './utilities' +import { repeat, isCodeBlockSpecialCase1, isCodeBlockSpecialCase2, isCodeBlock, getStyleProp } from './utilities' const Entities = require('html-entities').AllHtmlEntities; const htmlentities = (new Entities()).encode; @@ -73,7 +73,15 @@ rules.highlight = { // HTML to avoid any ambiguity. rules.insert = { - filter: 'ins', + filter: function (node, options) { + // TinyMCE represents this either with an tag (when pressing the + // toolbar button) or using style "text-decoration" (when using shortcut + // Cmd+U) + // + // https://github.com/laurent22/joplin/issues/5480 + if (node.nodeName === 'INS') return true; + return getStyleProp(node, 'text-decoration') === 'underline'; + }, replacement: function (content, node, options) { return '' + content + '' diff --git a/packages/turndown/src/utilities.js b/packages/turndown/src/utilities.js index d3da0dc839..0554f00804 100644 --- a/packages/turndown/src/utilities.js +++ b/packages/turndown/src/utilities.js @@ -78,3 +78,16 @@ export function isCodeBlock(node) { node.firstChild.nodeName === 'CODE' ) } + +export function getStyleProp(node, name) { + const style = node.getAttribute('style'); + if (!style) return null; + + name = name.toLowerCase(); + if (!style.toLowerCase().includes(name)) return null; + + const o = css.parse('div {' + style + '}'); + if (!o.stylesheet.rules.length) return null; + const prop = o.stylesheet.rules[0].declarations.find(d => d.property.toLowerCase() === name); + return prop ? prop.value : null; +}