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>
|
||||
)
|
||||
},
|
||||
[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]: (
|
||||
node: RTENode,
|
||||
|
||||
@@ -122,16 +122,13 @@ export function nodeToHtml(
|
||||
if ("type" in node === false) {
|
||||
return textNodeToHtml(node, fullRenderOptions)
|
||||
} else {
|
||||
if (fullRenderOptions[node.type] !== undefined) {
|
||||
const renderer = fullRenderOptions[node.type] as RTERenderOptionComponent
|
||||
if (renderer) {
|
||||
if (node.type === RTETypeEnum.doc) {
|
||||
return null
|
||||
}
|
||||
return (fullRenderOptions[node.type] as RTERenderOptionComponent)(
|
||||
node,
|
||||
embeds,
|
||||
next,
|
||||
fullRenderOptions
|
||||
)
|
||||
|
||||
return renderer(node, embeds, next, fullRenderOptions)
|
||||
} else {
|
||||
return next(node.children, embeds, fullRenderOptions)
|
||||
}
|
||||
@@ -152,11 +149,16 @@ export function nodesToHtml(
|
||||
) {
|
||||
const embeds = groupEmbedsByUid(embedsArray)
|
||||
const fullRenderOptions = { ...renderOptions, ...overrideRenderOptions }
|
||||
return nodes.map((node, index) => (
|
||||
<React.Fragment key={getUniqueId(node) ?? `node-${index}`}>
|
||||
{nodeToHtml(node, embeds, fullRenderOptions)}
|
||||
</React.Fragment>
|
||||
))
|
||||
|
||||
return nodes.map((node, index) => {
|
||||
const nodeHtml = nodeToHtml(node, embeds, fullRenderOptions)
|
||||
|
||||
return (
|
||||
<React.Fragment key={getUniqueId(node) ?? `node-${index}`}>
|
||||
{nodeHtml}
|
||||
</React.Fragment>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export function makeCssModuleCompatibleClassName(
|
||||
|
||||
@@ -28,6 +28,10 @@ export enum RTETypeEnum {
|
||||
p = "p",
|
||||
reference = "reference",
|
||||
span = "span",
|
||||
/**
|
||||
* Included for compatibility when copying RTE from other sources e.g. epi
|
||||
*/
|
||||
div = "div",
|
||||
table = "table",
|
||||
tbody = "tbody",
|
||||
td = "td",
|
||||
|
||||
@@ -9,3 +9,11 @@ export async function safeTry<T>(func: Promise<T>): SafeTryResult<T> {
|
||||
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