Merged in fix/SW-2848-RTE-with-copied-divs (pull request #2173)
fix: handle when content has copied divs from episervers RTE * fix: handle when content has copied divs from episervers RTE Approved-by: Matilda Landström
This commit is contained in:
committed by
Linus Flood
parent
fe71348827
commit
cc34cdcf74
@@ -336,6 +336,28 @@ export const renderOptions: RenderOptions = {
|
|||||||
<span {...props}>{next(node.children, embeds, fullRenderOptions)}</span>
|
<span {...props}>{next(node.children, embeds, fullRenderOptions)}</span>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
[RTETypeEnum.div]: (
|
||||||
|
node: RTEDefaultNode,
|
||||||
|
embeds: EmbedByUid,
|
||||||
|
next: RTENext,
|
||||||
|
fullRenderOptions: RenderOptions
|
||||||
|
) => {
|
||||||
|
let props = extractPossibleAttributes(node.attrs)
|
||||||
|
const className = props.className
|
||||||
|
|
||||||
|
if (className) {
|
||||||
|
if (hasAvailableULFormat(className)) {
|
||||||
|
// @ts-ignore: We want to set css modules classNames even if it does not correspond
|
||||||
|
// to an existing class in the module style sheet. Due to our css modules plugin for
|
||||||
|
// typescript, we cannot do this without the ts-ignore
|
||||||
|
props.className = styles[className]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div {...props}>{next(node.children, embeds, fullRenderOptions)}</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
[RTETypeEnum.reference]: (
|
[RTETypeEnum.reference]: (
|
||||||
node: RTENode,
|
node: RTENode,
|
||||||
|
|||||||
@@ -122,16 +122,13 @@ export function nodeToHtml(
|
|||||||
if ("type" in node === false) {
|
if ("type" in node === false) {
|
||||||
return textNodeToHtml(node, fullRenderOptions)
|
return textNodeToHtml(node, fullRenderOptions)
|
||||||
} else {
|
} else {
|
||||||
if (fullRenderOptions[node.type] !== undefined) {
|
const renderer = fullRenderOptions[node.type] as RTERenderOptionComponent
|
||||||
|
if (renderer) {
|
||||||
if (node.type === RTETypeEnum.doc) {
|
if (node.type === RTETypeEnum.doc) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return (fullRenderOptions[node.type] as RTERenderOptionComponent)(
|
|
||||||
node,
|
return renderer(node, embeds, next, fullRenderOptions)
|
||||||
embeds,
|
|
||||||
next,
|
|
||||||
fullRenderOptions
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
return next(node.children, embeds, fullRenderOptions)
|
return next(node.children, embeds, fullRenderOptions)
|
||||||
}
|
}
|
||||||
@@ -152,11 +149,16 @@ export function nodesToHtml(
|
|||||||
) {
|
) {
|
||||||
const embeds = groupEmbedsByUid(embedsArray)
|
const embeds = groupEmbedsByUid(embedsArray)
|
||||||
const fullRenderOptions = { ...renderOptions, ...overrideRenderOptions }
|
const fullRenderOptions = { ...renderOptions, ...overrideRenderOptions }
|
||||||
return nodes.map((node, index) => (
|
|
||||||
<React.Fragment key={getUniqueId(node) ?? `node-${index}`}>
|
return nodes.map((node, index) => {
|
||||||
{nodeToHtml(node, embeds, fullRenderOptions)}
|
const nodeHtml = nodeToHtml(node, embeds, fullRenderOptions)
|
||||||
</React.Fragment>
|
|
||||||
))
|
return (
|
||||||
|
<React.Fragment key={getUniqueId(node) ?? `node-${index}`}>
|
||||||
|
{nodeHtml}
|
||||||
|
</React.Fragment>
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeCssModuleCompatibleClassName(
|
export function makeCssModuleCompatibleClassName(
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ export enum RTETypeEnum {
|
|||||||
p = "p",
|
p = "p",
|
||||||
reference = "reference",
|
reference = "reference",
|
||||||
span = "span",
|
span = "span",
|
||||||
|
/**
|
||||||
|
* Included for compatibility when copying RTE from other sources e.g. epi
|
||||||
|
*/
|
||||||
|
div = "div",
|
||||||
table = "table",
|
table = "table",
|
||||||
tbody = "tbody",
|
tbody = "tbody",
|
||||||
td = "td",
|
td = "td",
|
||||||
|
|||||||
@@ -9,3 +9,11 @@ export async function safeTry<T>(func: Promise<T>): SafeTryResult<T> {
|
|||||||
return [undefined, err]
|
return [undefined, err]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function safeTrySync<T>(func: () => T): Awaited<SafeTryResult<T>> {
|
||||||
|
try {
|
||||||
|
return [func(), undefined]
|
||||||
|
} catch (err) {
|
||||||
|
return [undefined, err]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user