Skip to content

Commit

Permalink
Fix bug with code tags matching block styles.
Browse files Browse the repository at this point in the history
Make code tags skip block styles. Fixes #869
  • Loading branch information
samclarke committed Dec 22, 2021
1 parent 97fb4be commit 634bb93
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/formats/bbcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,11 @@
var name = attribute[0];
var value = attribute[1];

// code tags should skip most styles
if (name === 'style' && element.nodeName === 'CODE') {
return false;
}

if (name === 'style' && value) {
return value[isStrict ? 'every' : 'some'](isStyleMatch);
} else {
Expand Down Expand Up @@ -2435,7 +2440,7 @@
var ret = '';

dom.traverse(node, function (node) {
var curTag = '',
var content = '',
nodeType = node.nodeType,
tag = node.nodeName.toLowerCase(),
vChild = validChildren[tag],
Expand Down Expand Up @@ -2472,7 +2477,7 @@

// don't convert iframe contents
if (tag !== 'iframe') {
curTag = toBBCode(node, vChild);
content = toBBCode(node, vChild);
}

// TODO: isValidChild is no longer needed. Should use
Expand All @@ -2482,13 +2487,13 @@
// code tags should skip most styles
if (tag !== 'code') {
// First parse inline codes
curTag = handleTags(node, curTag, false);
content = handleTags(node, content, false);
}

curTag = handleTags(node, curTag, true);
ret += handleBlockNewlines(node, curTag);
content = handleTags(node, content, true);
ret += handleBlockNewlines(node, content);
} else {
ret += curTag;
ret += content;
}
} else {
ret += node.nodeValue;
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/lib/SCEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,23 @@ QUnit.test('Insert HTML filter JS', function (assert) {
});



QUnit.test('Code tags should ignore block styling', function (assert) {
var done = assert.async();

reloadEditor({
format: 'bbcode'
});
sceditor.css('code {text-align: left}');
sceditor.val('[code]test[/code]');

setTimeout(() => {
assert.equal(sceditor.val(), '[code]test[/code]\n');
done();
}, 100);
});


QUnit.test('Allow target=blank links', function (assert) {
reloadEditor({
format: 'xhtml'
Expand Down

0 comments on commit 634bb93

Please sign in to comment.