2
0

🐛 (whatsapp) Fix inline variable serializing

This commit is contained in:
Baptiste Arnaud
2024-01-11 00:14:55 +01:00
parent 006b9d6658
commit 9b5b277b5b
2 changed files with 22 additions and 2 deletions

View File

@ -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(

View File

@ -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`