@udecode/plate-html-serializer
Advanced tools
Comparing version 2.0.0 to 3.1.3
# @udecode/plate-html-serializer | ||
## 3.1.3 | ||
### Patch Changes | ||
- [#998](https://github.com/udecode/plate/pull/998) [`c53532ba`](https://github.com/udecode/plate/commit/c53532baebd83fe79c53b300e97ecf6e713f7754) Thanks [@bensquire](https://github.com/bensquire)! - Adds the ability to not strip whitespace when converting to and from plate/html syntax | ||
- Updated dependencies [[`f6c58134`](https://github.com/udecode/plate/commit/f6c581347cc5877b7afa0774ef1ad78ad227564e)]: | ||
- @udecode/plate-common@3.1.3 | ||
- @udecode/plate-serializer@3.1.3 | ||
## 2.0.0 | ||
@@ -4,0 +14,0 @@ |
@@ -5,6 +5,7 @@ import { PlatePlugin, SPEditor, TDescendant } from '@udecode/plate-core'; | ||
*/ | ||
export declare const deserializeHTMLToDocumentFragment: <T extends SPEditor = SPEditor>(editor: T, { plugins, element, }: { | ||
export declare const deserializeHTMLToDocumentFragment: <T extends SPEditor = SPEditor>(editor: T, { plugins, element, stripWhitespace, }: { | ||
plugins: PlatePlugin<T>[]; | ||
element: HTMLElement | string; | ||
stripWhitespace?: boolean | undefined; | ||
}) => TDescendant[]; | ||
//# sourceMappingURL=deserializeHTMLToDocumentFragment.d.ts.map |
@@ -11,5 +11,10 @@ import { isElement, getPlatePluginWithOverrides } from '@udecode/plate-core'; | ||
*/ | ||
const htmlStringToDOMNode = rawHtml => { | ||
const htmlStringToDOMNode = (rawHtml, stripWhitespace = true) => { | ||
const node = document.createElement('body'); | ||
node.innerHTML = rawHtml.replace(/(\r\n|\n|\r|\t)/gm, ''); | ||
node.innerHTML = rawHtml; | ||
if (stripWhitespace) { | ||
node.innerHTML = node.innerHTML.replace(/(\r\n|\n|\r|\t)/gm, ''); | ||
} | ||
return node; | ||
@@ -197,6 +202,7 @@ }; | ||
plugins, | ||
element | ||
element, | ||
stripWhitespace = true | ||
}) => { | ||
if (typeof element === 'string') { | ||
element = htmlStringToDOMNode(element); | ||
element = htmlStringToDOMNode(element, stripWhitespace); | ||
} | ||
@@ -363,3 +369,4 @@ | ||
stripDataAttributes = true, | ||
preserveClassNames | ||
preserveClassNames, | ||
stripWhitespace = true | ||
}) => { | ||
@@ -390,3 +397,4 @@ let result = nodes.map(node => { | ||
nodes: node.children, | ||
preserveClassNames | ||
preserveClassNames, | ||
stripWhitespace | ||
})), | ||
@@ -402,4 +410,8 @@ attributes: { | ||
}).join(''); | ||
result = trimWhitespace(decodeURIComponent(result)); | ||
result = decodeURIComponent(result); | ||
if (stripWhitespace) { | ||
result = trimWhitespace(result); | ||
} | ||
if (stripDataAttributes) { | ||
@@ -406,0 +418,0 @@ result = stripSlateDataAttributes(result); |
@@ -15,5 +15,10 @@ 'use strict'; | ||
*/ | ||
const htmlStringToDOMNode = rawHtml => { | ||
const htmlStringToDOMNode = (rawHtml, stripWhitespace = true) => { | ||
const node = document.createElement('body'); | ||
node.innerHTML = rawHtml.replace(/(\r\n|\n|\r|\t)/gm, ''); | ||
node.innerHTML = rawHtml; | ||
if (stripWhitespace) { | ||
node.innerHTML = node.innerHTML.replace(/(\r\n|\n|\r|\t)/gm, ''); | ||
} | ||
return node; | ||
@@ -201,6 +206,7 @@ }; | ||
plugins, | ||
element | ||
element, | ||
stripWhitespace = true | ||
}) => { | ||
if (typeof element === 'string') { | ||
element = htmlStringToDOMNode(element); | ||
element = htmlStringToDOMNode(element, stripWhitespace); | ||
} | ||
@@ -367,3 +373,4 @@ | ||
stripDataAttributes = true, | ||
preserveClassNames | ||
preserveClassNames, | ||
stripWhitespace = true | ||
}) => { | ||
@@ -394,3 +401,4 @@ let result = nodes.map(node => { | ||
nodes: node.children, | ||
preserveClassNames | ||
preserveClassNames, | ||
stripWhitespace | ||
})), | ||
@@ -406,4 +414,8 @@ attributes: { | ||
}).join(''); | ||
result = trimWhitespace(decodeURIComponent(result)); | ||
result = decodeURIComponent(result); | ||
if (stripWhitespace) { | ||
result = trimWhitespace(result); | ||
} | ||
if (stripDataAttributes) { | ||
@@ -410,0 +422,0 @@ result = stripSlateDataAttributes(result); |
@@ -5,3 +5,3 @@ import { PlatePlugin, SlateProps, SPEditor, TDescendant } from '@udecode/plate-core'; | ||
*/ | ||
export declare const serializeHTMLFromNodes: (editor: SPEditor, { plugins, nodes, slateProps, stripDataAttributes, preserveClassNames, }: { | ||
export declare const serializeHTMLFromNodes: (editor: SPEditor, { plugins, nodes, slateProps, stripDataAttributes, preserveClassNames, stripWhitespace, }: { | ||
/** | ||
@@ -27,3 +27,8 @@ * Plugins with renderElement or renderLeaf. | ||
slateProps?: Partial<SlateProps> | undefined; | ||
/** | ||
* Whether stripping whitespaces from serialized HTML | ||
* @default true | ||
*/ | ||
stripWhitespace?: boolean | undefined; | ||
}) => string; | ||
//# sourceMappingURL=serializeHTMLFromNodes.d.ts.map |
/** | ||
* Convert HTML string into HTML element. | ||
*/ | ||
export declare const htmlStringToDOMNode: (rawHtml: string) => HTMLBodyElement; | ||
export declare const htmlStringToDOMNode: (rawHtml: string, stripWhitespace?: boolean) => HTMLBodyElement; | ||
//# sourceMappingURL=htmlStringToDOMNode.d.ts.map |
{ | ||
"name": "@udecode/plate-html-serializer", | ||
"version": "2.0.0", | ||
"version": "3.1.3", | ||
"description": "HTML serializer plugin for Plate", | ||
@@ -37,5 +37,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@udecode/plate-common": "2.0.0", | ||
"@udecode/plate-common": "3.1.3", | ||
"@udecode/plate-core": "1.0.0", | ||
"@udecode/plate-serializer": "2.0.0" | ||
"@udecode/plate-serializer": "3.1.3" | ||
}, | ||
@@ -42,0 +42,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
101573
884
+ Added@udecode/plate-common@3.1.3(transitive)
+ Added@udecode/plate-serializer@3.1.3(transitive)
- Removed@udecode/plate-common@2.0.0(transitive)
- Removed@udecode/plate-serializer@2.0.0(transitive)
Updated@udecode/plate-common@3.1.3