🐛 (whatsapp) Fix inline variable serializing
This commit is contained in:
@ -9,7 +9,7 @@ export const convertRichTextToMarkdown = (
|
|||||||
let extraNewLinesCount = 0
|
let extraNewLinesCount = 0
|
||||||
const test = richText
|
const test = richText
|
||||||
.reduce<string[]>((acc, node) => {
|
.reduce<string[]>((acc, node) => {
|
||||||
if (node.type === 'variable' || node.type === 'inline-variable') {
|
if (node.type === 'variable') {
|
||||||
return [
|
return [
|
||||||
...acc,
|
...acc,
|
||||||
...node.children.map(
|
...node.children.map(
|
||||||
|
@ -21,7 +21,7 @@ export default function serialize(
|
|||||||
opts: Options = {
|
opts: Options = {
|
||||||
nodeTypes: defaultNodeTypes,
|
nodeTypes: defaultNodeTypes,
|
||||||
}
|
}
|
||||||
) {
|
): string | undefined {
|
||||||
const {
|
const {
|
||||||
nodeTypes: userNodeTypes = defaultNodeTypes,
|
nodeTypes: userNodeTypes = defaultNodeTypes,
|
||||||
ignoreParagraphNewline = false,
|
ignoreParagraphNewline = false,
|
||||||
@ -40,6 +40,19 @@ export default function serialize(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('type' in chunk && chunk.type === nodeTypes['inline-variable'])
|
||||||
|
return chunk.children
|
||||||
|
.map((child) =>
|
||||||
|
serialize(
|
||||||
|
{
|
||||||
|
...child,
|
||||||
|
parentType: nodeTypes['inline-variable'],
|
||||||
|
},
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.join('')
|
||||||
|
|
||||||
const LIST_TYPES = [nodeTypes.ul_list, nodeTypes.ol_list]
|
const LIST_TYPES = [nodeTypes.ul_list, nodeTypes.ol_list]
|
||||||
|
|
||||||
let children = text
|
let children = text
|
||||||
@ -169,6 +182,13 @@ export default function serialize(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chunk.parentType === nodeTypes['inline-variable']) {
|
||||||
|
if (opts.flavour === 'whatsapp') {
|
||||||
|
return children
|
||||||
|
}
|
||||||
|
return escapeHtml(children)
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case nodeTypes.heading[1]:
|
case nodeTypes.heading[1]:
|
||||||
return `# ${children}\n`
|
return `# ${children}\n`
|
||||||
|
Reference in New Issue
Block a user