braft-convert
Advanced tools
Comparing version 2.1.12 to 2.1.14
@@ -16,2 +16,4 @@ "use strict"; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
var namedColors = exports.namedColors = { | ||
@@ -171,2 +173,12 @@ "aliceblue": "#f0f8ff", | ||
var ignoredNodeAttributes = ['style']; | ||
var ignoredEntityNodeAttributes = ['style', 'href', 'target', 'alt', 'title', 'id', 'controls', 'autoplay', 'loop', 'poster']; | ||
var spreadNodeAttributes = function spreadNodeAttributes(attributesObject) { | ||
attributesObject = attributesObject || {}; | ||
return Object.keys(attributesObject).reduce(function (attributeString, attributeName) { | ||
return attributeString + " " + attributeName + "=\"" + attributesObject[attributeName] + "\""; | ||
}, ' ').replace(/^\s$/, ''); | ||
}; | ||
var defaultFontFamilies = exports.defaultFontFamilies = [{ | ||
@@ -228,3 +240,3 @@ name: 'Araial', | ||
var convertAtomicBlock = function convertAtomicBlock(block, contentState) { | ||
var convertAtomicBlock = function convertAtomicBlock(block, contentState, blockNodeAttributes) { | ||
@@ -237,2 +249,7 @@ if (!block || !block.key) { | ||
var className = blockNodeAttributes.class, | ||
nodeAttrAsProps = _objectWithoutProperties(blockNodeAttributes, ["class"]); | ||
nodeAttrAsProps.className = className; | ||
if (!contentBlock) { | ||
@@ -283,3 +300,3 @@ return _react2.default.createElement("p", null); | ||
{ style: { display: 'inline-block' }, href: link, target: link_target }, | ||
_react2.default.createElement("img", _extends({}, meta, { src: url, width: width, height: height, style: { width: width, height: height } })) | ||
_react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } })) | ||
) | ||
@@ -291,3 +308,3 @@ ); | ||
{ className: "media-wrap image-wrap" + styledClassName, style: imageWrapStyle }, | ||
_react2.default.createElement("img", _extends({}, meta, { src: url, width: width, height: height, style: { width: width, height: height } })) | ||
_react2.default.createElement("img", _extends({}, nodeAttrAsProps, meta, { src: url, width: width, height: height, style: { width: width, height: height } })) | ||
); | ||
@@ -299,3 +316,3 @@ } | ||
{ className: "media-wrap audio-wrap" }, | ||
_react2.default.createElement("audio", _extends({ controls: true }, meta, { src: url })) | ||
_react2.default.createElement("audio", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url })) | ||
); | ||
@@ -306,3 +323,3 @@ } else if (mediaType === 'video') { | ||
{ className: "media-wrap video-wrap" }, | ||
_react2.default.createElement("video", _extends({ controls: true }, meta, { src: url, width: width, height: height })) | ||
_react2.default.createElement("video", _extends({ controls: true }, nodeAttrAsProps, meta, { src: url, width: width, height: height })) | ||
); | ||
@@ -336,3 +353,8 @@ } else if (mediaType === 'embed') { | ||
if (entityType === 'link') { | ||
return _react2.default.createElement("a", { href: entity.data.href, target: entity.data.target }); | ||
var _entity$data$nodeAttr = entity.data.nodeAttributes, | ||
className = _entity$data$nodeAttr.class, | ||
nodeAttrAsProps = _objectWithoutProperties(_entity$data$nodeAttr, ["class"]); | ||
nodeAttrAsProps.className = className; | ||
return _react2.default.createElement("a", _extends({ href: entity.data.href, target: entity.data.target }, nodeAttrAsProps)); | ||
} | ||
@@ -395,4 +417,3 @@ }; | ||
var blockStyle = '', | ||
blockClass = ''; | ||
var blockStyle = ''; | ||
@@ -403,4 +424,5 @@ var blockType = block.type.toLowerCase(); | ||
textIndent = _block$data2.textIndent, | ||
className = _block$data2.className; | ||
nodeAttributes = _block$data2.nodeAttributes; | ||
var attributeString = spreadNodeAttributes(nodeAttributes); | ||
@@ -422,8 +444,4 @@ if (textAlign || textIndent) { | ||
if (className) { | ||
blockClass = " class=\"" + className + "\""; | ||
} | ||
if (blockType === 'atomic') { | ||
return convertAtomicBlock(block, contentState); | ||
return convertAtomicBlock(block, contentState, nodeAttributes); | ||
} else if (blockType === 'code-block') { | ||
@@ -440,3 +458,3 @@ | ||
if (previousBlockType !== 'code-block') { | ||
start = '<pre><code>'; | ||
start = "<pre " + attributeString + "><code>"; | ||
} else { | ||
@@ -455,3 +473,3 @@ start = ''; | ||
return { | ||
start: "<" + blocks[blockType] + blockStyle + blockClass + ">", | ||
start: "<" + blocks[blockType] + blockStyle + attributeString + ">", | ||
end: "</" + blocks[blockType] + ">" | ||
@@ -461,3 +479,3 @@ }; | ||
return { | ||
start: "<li" + blockStyle + ">", | ||
start: "<li" + blockStyle + attributeString + ">", | ||
end: '</li>', | ||
@@ -468,3 +486,3 @@ nest: _react2.default.createElement("ul", null) | ||
return { | ||
start: "<li" + blockStyle + ">", | ||
start: "<li" + blockStyle + attributeString + ">", | ||
end: '</li>', | ||
@@ -548,2 +566,3 @@ nest: _react2.default.createElement("ol", null) | ||
var meta = {}; | ||
var nodeAttributes = {}; | ||
@@ -558,11 +577,15 @@ id && (meta.id = id); | ||
node.attributes && Object.keys(node.attributes).forEach(function (key) { | ||
var attr = node.attributes[key]; | ||
ignoredEntityNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value); | ||
}); | ||
if (nodeName === 'a' && !node.querySelectorAll('img').length) { | ||
var href = node.href, | ||
target = node.target; | ||
return createEntity('LINK', 'MUTABLE', { href: href, target: target }); | ||
var href = node.getAttribute('href'); | ||
var _target = node.getAttribute('target'); | ||
return createEntity('LINK', 'MUTABLE', { href: href, target: _target, nodeAttributes: nodeAttributes }); | ||
} else if (nodeName === 'audio') { | ||
return createEntity('AUDIO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta }); | ||
return createEntity('AUDIO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes }); | ||
} else if (nodeName === 'video') { | ||
return createEntity('VIDEO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta }); | ||
return createEntity('VIDEO', 'IMMUTABLE', { url: node.getAttribute('src'), meta: meta, nodeAttributes: nodeAttributes }); | ||
} else if (nodeName === 'img') { | ||
@@ -582,4 +605,4 @@ | ||
if (parentNode.nodeName.toLowerCase() === 'a') { | ||
entityData.link = parentNode.href; | ||
entityData.link_target = parentNode.target; | ||
entityData.link = parentNode.getAttribute('href'); | ||
entityData.link_target = parentNode.getAttribute('target'); | ||
} | ||
@@ -613,4 +636,10 @@ | ||
var nodeAttributes = {}; | ||
var nodeStyle = node.style || {}; | ||
node.attributes && Object.keys(node.attributes).forEach(function (key) { | ||
var attr = node.attributes[key]; | ||
ignoredNodeAttributes.indexOf(attr.name) === -1 && (nodeAttributes[attr.name] = attr.value); | ||
}); | ||
if (node.classList && node.classList.contains('media-wrap')) { | ||
@@ -621,2 +650,3 @@ | ||
data: { | ||
nodeAttributes: nodeAttributes, | ||
float: nodeStyle.float, | ||
@@ -631,2 +661,3 @@ alignment: nodeStyle.textAlign | ||
data: { | ||
nodeAttributes: nodeAttributes, | ||
float: nodeStyle.float, | ||
@@ -640,3 +671,3 @@ alignment: nodeStyle.textAlign | ||
type: 'atomic', | ||
data: {} | ||
data: { nodeAttributes: nodeAttributes } | ||
}; | ||
@@ -649,7 +680,7 @@ } else if (nodeName === 'pre') { | ||
type: 'code-block', | ||
data: {} | ||
data: { nodeAttributes: nodeAttributes } | ||
}; | ||
} else if ((nodeStyle.textAlign || nodeStyle.textIndent || node.className) && blockNames.indexOf(nodeName) > -1) { | ||
} else if (blockNames.indexOf(nodeName) !== -1) { | ||
var blockData = {}; | ||
var blockData = { nodeAttributes: nodeAttributes }; | ||
@@ -664,6 +695,2 @@ if (nodeStyle.textAlign) { | ||
if (node.className) { | ||
blockData.className = node.className; | ||
} | ||
return { | ||
@@ -670,0 +697,0 @@ type: blockTypes[blockNames.indexOf(nodeName)], |
{ | ||
"name": "braft-convert", | ||
"version": "2.1.12", | ||
"version": "2.1.14", | ||
"description": "A convert helper for Braft Editor.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72297
660