Skip to content

Commit

Permalink
feat:Support excluded html tag attributes in bbcode formats with false
Browse files Browse the repository at this point in the history
  • Loading branch information
live627 committed Mar 6, 2021
1 parent 0573162 commit 7904cb0
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/formats/bbcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,10 @@
tags: {
img: {
src: null,
'data-sceditor-emoticon': null
[EMOTICON_DATA_ATTR]: null
}
},
format: function (element, content) {
return attr(element, EMOTICON_DATA_ATTR) + content;
},
format: element => attr(element, EMOTICON_DATA_ATTR),
html: '{0}'
},
// END_COMMAND
Expand All @@ -539,23 +537,20 @@
allowsEmpty: true,
tags: {
img: {
src: null
src: null,
[EMOTICON_DATA_ATTR]: false
}
},
allowedChildren: ['#'],
quoteType: QuoteType.never,
format: function (element, content) {
var width, height,
var
width, height,
attribs = '',
style = function (name) {
return element.style ? element.style[name] : null;
};

// check if this is an emoticon image
if (attr(element, EMOTICON_DATA_ATTR)) {
return content;
}

width = attr(element, 'width') || style('width');
height = attr(element, 'height') || style('height');

Expand All @@ -570,7 +565,8 @@
return '[img' + attribs + ']' + attr(element, 'src') + '[/img]';
},
html: function (token, attrs, content) {
var undef, width, height, match,
var
undef, width, height, match,
attribs = '';

// handle [img width=340 height=240]url[/img]
Expand Down Expand Up @@ -2397,31 +2393,35 @@
* @private
*/
function handleTags(element, content, blockLevel) {
var convertBBCode, format,
tag = element.nodeName.toLowerCase();

// convert blockLevel to boolean
blockLevel = !!blockLevel;
var
convertBBCode, format,
tag = element.nodeName.toLowerCase(),
thisTag = tagsToBBCodes[tag];

if (tagsToBBCodes[tag] && tagsToBBCodes[tag][blockLevel]) {
if (thisTag && thisTag[blockLevel]) {
// loop all bbcodes for this tag
each(tagsToBBCodes[tag][blockLevel], function (
bbcode, bbcodeAttribs) {
each(thisTag[blockLevel], function (bbcode, bbcodeAttribs) {
// if the bbcode requires any attributes then check this has
// all needed
if (bbcodeAttribs) {
convertBBCode = false;

// loop all the bbcode attribs
each(bbcodeAttribs, function (attrib, values) {
// Skip if the element doesn't have the attibue or
// the attribute doesn't match one of the require
// Skip if the element doesn't have the attribute or
// the attribute doesn't match one of the required
// values
if (!attr(element, attrib) || (values &&
values.indexOf(attr(element, attrib)) < 0)) {
return;
}

if (attr(element, attrib) && values === false) {
convertBBCode = false;
return;
}

// break this loop as we have matched this bbcode
convertBBCode = true;
return false;
Expand Down

0 comments on commit 7904cb0

Please sign in to comment.