@cloudbeds/slate-serializers
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -49,4 +49,5 @@ "use strict"; | ||
encodeEntities: true, | ||
alwaysEncodeBreakingEntities: false, | ||
alwaysEncodeCodeEntities: false, | ||
convertLineBreakToBr: false, | ||
}; |
@@ -24,2 +24,3 @@ import { ChildNode, Element } from 'domhandler'; | ||
encodeEntities?: boolean; | ||
alwaysEncodeBreakingEntities?: boolean; | ||
alwaysEncodeCodeEntities?: boolean; | ||
@@ -26,0 +27,0 @@ convertLineBreakToBr?: boolean; |
@@ -23,4 +23,3 @@ "use strict"; | ||
const isLastChild = index === childrenLength - 1; | ||
const isWithinTextNodes = (((_a = currentEl.prev) === null || _a === void 0 ? void 0 : _a.type) === htmlparser2_1.ElementType.Text | ||
&& ((_b = currentEl.next) === null || _b === void 0 ? void 0 : _b.type) === htmlparser2_1.ElementType.Text); | ||
const isWithinTextNodes = ((_a = currentEl.prev) === null || _a === void 0 ? void 0 : _a.type) === htmlparser2_1.ElementType.Text && ((_b = currentEl.next) === null || _b === void 0 ? void 0 : _b.type) === htmlparser2_1.ElementType.Text; | ||
if (nodeName === 'br' && config.convertBrToLineBreak && context !== 'preserve') { | ||
@@ -94,2 +93,3 @@ return [(0, slate_hyperscript_1.jsx)('text', { text: context ? '\n' : '' }, [])]; | ||
if (children.length) { | ||
; | ||
[el, ...children.flat()].forEach((child) => { | ||
@@ -96,0 +96,0 @@ const name = (0, domutils_1.getName)(child); |
@@ -29,3 +29,5 @@ "use strict"; | ||
if (slate_1.Text.isText(node)) { | ||
const str = node.text; | ||
const str = config.alwaysEncodeBreakingEntities && config.encodeEntities === false | ||
? (0, utilities_1.encodeBreakingEntities)(node.text) | ||
: node.text; | ||
// convert line breaks to br tags | ||
@@ -32,0 +34,0 @@ const strLines = config.convertLineBreakToBr ? str.split('\n') : [str]; |
@@ -18,1 +18,2 @@ export declare const hasLineBreak: (str: string) => boolean; | ||
export declare const getNested: (obj: any, ...args: string[]) => any; | ||
export declare const encodeBreakingEntities: (str: string) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getNested = exports.removeEmpty = exports.isEmptyObject = exports.styleToString = exports.parseStyleCssText = exports.prependSpace = exports.hasLineBreak = void 0; | ||
exports.encodeBreakingEntities = exports.getNested = exports.removeEmpty = exports.isEmptyObject = exports.styleToString = exports.parseStyleCssText = exports.prependSpace = exports.hasLineBreak = void 0; | ||
const hasLineBreak = (str) => str.match(/[\r\n]+/) !== null; | ||
@@ -58,1 +58,21 @@ exports.hasLineBreak = hasLineBreak; | ||
exports.getNested = getNested; | ||
const encodeBreakingEntities = (str) => { | ||
const swapChar = (charToSwap) => { | ||
// that swaps characters to HTML entities | ||
switch (charToSwap) { | ||
case '&': | ||
return '&'; | ||
case '<': | ||
return '<'; | ||
case '>': | ||
return '>'; | ||
default: | ||
return charToSwap; | ||
} | ||
}; | ||
str = str.replace(/[&<>]/g, (match) => { | ||
return swapChar(match); | ||
}); | ||
return str; | ||
}; | ||
exports.encodeBreakingEntities = encodeBreakingEntities; |
{ | ||
"name": "@cloudbeds/slate-serializers", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Serialize Slate JSON objects to HTML and vice versa. Define rules to modify the end result.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
40025
938