mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
Desktop: Fixes #5480: Underline was not applied when using Cmd+U in Rich Text editor
This commit is contained in:
parent
6d981864ef
commit
87f83236cf
@ -1 +1 @@
|
||||
X<sub>1</sub> X<sup>1</sup> <ins>Insert</ins> <s>Strike</s>
|
||||
X<sub>1</sub> X<sup>1</sup> <ins>Insert</ins> <span style="text-decoration: underline;">Insert alt</span> <s>Strike</s>
|
@ -1 +1 @@
|
||||
X<sub>1</sub> X<sup>1</sup> <ins>Insert</ins> ~~Strike~~
|
||||
X<sub>1</sub> X<sup>1</sup> <ins>Insert</ins> <ins>Insert alt</ins> ~~Strike~~
|
@ -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 <INS> 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 '<ins>' + content + '</ins>'
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user