Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Support excluded html tag attributes in bbcode formats with false #808

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 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
brunoais marked this conversation as resolved.
Show resolved Hide resolved
}
},
allowedChildren: ['#'],
quoteType: QuoteType.never,
format: function (element, content) {
var width, height,
format: function (element) {
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