draft-js-export-html
Advanced tools
Comparing version 0.1.9 to 0.1.10
@@ -11,2 +11,4 @@ 'use strict'; | ||
var _ENTITY_ATTR_MAP, _DATA_TO_ATTR; | ||
exports.default = stateToHTML; | ||
@@ -32,7 +34,7 @@ | ||
// Map entity data to element attributes. | ||
var ENTITY_ATTR_MAP = _defineProperty({}, _draftJsTools.ENTITY_TYPE.LINK, { url: 'href', rel: 'rel', target: 'target', title: 'title' }); | ||
var ENTITY_ATTR_MAP = (_ENTITY_ATTR_MAP = {}, _defineProperty(_ENTITY_ATTR_MAP, _draftJsTools.ENTITY_TYPE.LINK, { url: 'href', rel: 'rel', target: 'target', title: 'title' }), _defineProperty(_ENTITY_ATTR_MAP, _draftJsTools.ENTITY_TYPE.IMAGE, { src: 'src', height: 'height', width: 'width', alt: 'alt' }), _ENTITY_ATTR_MAP); | ||
// Map entity data to element attributes. | ||
var DATA_TO_ATTR = _defineProperty({}, _draftJsTools.ENTITY_TYPE.LINK, function (entityType, entity) { | ||
var attrMap = ENTITY_ATTR_MAP.hasOwnProperty(entityType) ? ENTITY_ATTR_MAP[entityType] : null; | ||
var DATA_TO_ATTR = (_DATA_TO_ATTR = {}, _defineProperty(_DATA_TO_ATTR, _draftJsTools.ENTITY_TYPE.LINK, function (entityType, entity) { | ||
var attrMap = ENTITY_ATTR_MAP.hasOwnProperty(entityType) ? ENTITY_ATTR_MAP[entityType] : {}; | ||
var data = entity.getData(); | ||
@@ -70,4 +72,38 @@ var attrs = {}; | ||
return attrs; | ||
}); | ||
}), _defineProperty(_DATA_TO_ATTR, _draftJsTools.ENTITY_TYPE.IMAGE, function (entityType, entity) { | ||
var attrMap = ENTITY_ATTR_MAP.hasOwnProperty(entityType) ? ENTITY_ATTR_MAP[entityType] : {}; | ||
var data = entity.getData(); | ||
var attrs = {}; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = Object.keys(data)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var dataKey = _step2.value; | ||
var dataValue = data[dataKey]; | ||
if (attrMap.hasOwnProperty(dataKey)) { | ||
var attrKey = attrMap[dataKey]; | ||
attrs[attrKey] = dataValue; | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
return attrs; | ||
}), _DATA_TO_ATTR); | ||
// The reason this returns an array is because a single block might get wrapped | ||
@@ -189,9 +225,9 @@ // in two tags. | ||
var tags = getTags(blockType); | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator2 = tags[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var tag = _step2.value; | ||
for (var _iterator3 = tags[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var tag = _step3.value; | ||
@@ -201,12 +237,12 @@ this.output.push('<' + tag + '>'); | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
@@ -224,9 +260,9 @@ } | ||
var output = []; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
try { | ||
for (var _iterator3 = tags[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var tag = _step3.value; | ||
for (var _iterator4 = tags[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var tag = _step4.value; | ||
@@ -236,12 +272,12 @@ output.unshift('</' + tag + '>'); | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
} | ||
@@ -328,2 +364,6 @@ } | ||
return '<a' + strAttrs + '>' + content + '</a>'; | ||
} else if (entityType != null && entityType === _draftJsTools.ENTITY_TYPE.IMAGE) { | ||
var _attrs = DATA_TO_ATTR.hasOwnProperty(entityType) ? DATA_TO_ATTR[entityType](entityType, entity) : null; | ||
var _strAttrs = stringifyAttrs(_attrs); | ||
return '<img' + _strAttrs + '/>'; | ||
} else { | ||
@@ -359,26 +399,26 @@ return content; | ||
var parts = []; | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
var _iteratorNormalCompletion5 = true; | ||
var _didIteratorError5 = false; | ||
var _iteratorError5 = undefined; | ||
try { | ||
for (var _iterator4 = Object.keys(attrs)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var attrKey = _step4.value; | ||
for (var _iterator5 = Object.keys(attrs)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { | ||
var attrKey = _step5.value; | ||
var attrValue = attrs[attrKey]; | ||
if (attrValue != null) { | ||
parts.push(' ' + attrKey + '="' + encodeAttr(attrValue) + '"'); | ||
parts.push(' ' + attrKey + '="' + encodeAttr(attrValue + '') + '"'); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
_didIteratorError5 = true; | ||
_iteratorError5 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
if (!_iteratorNormalCompletion5 && _iterator5.return) { | ||
_iterator5.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
if (_didIteratorError5) { | ||
throw _iteratorError5; | ||
} | ||
@@ -385,0 +425,0 @@ } |
{ | ||
"name": "draft-js-export-html", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "DraftJS: Export ContentState to HTML", | ||
@@ -14,3 +14,4 @@ "main": "lib/main.js", | ||
"dependencies": { | ||
"draft-js-tools": "^0.1.1" | ||
"draft-js-tools": "^0.1.1", | ||
"immutable": "^3.7.6" | ||
}, | ||
@@ -30,3 +31,2 @@ "devDependencies": { | ||
"expect": "^1.15.1", | ||
"immutable": "^3.7.6", | ||
"mocha": "^2.4.5", | ||
@@ -33,0 +33,0 @@ "react": "^0.14.7", |
@@ -11,2 +11,7 @@ # DraftJS: Export ContentState to HTML | ||
## How to Use | ||
import {stateToHTML} from 'draft-js-export-html'; | ||
let html = stateToHTML(contentState); | ||
This project is still under development. If you want to help out, please open an issue to discuss or join us on [Slack](https://draftjs.slack.com/). | ||
@@ -13,0 +18,0 @@ |
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
37019
15
414
21
2
+ Addedimmutable@^3.7.6
+ Addedimmutable@3.8.2(transitive)