Looking for a solution to migrate long Markdown articles into a Rich Text field? While the documentation suggests linking the content to a Markdown field in an existing entry, I'm struggling with tables. The problem arises when trying to create a new entry type for tables on the fly and reference it within the Rich Text content. The deriveLinkedEntries() method seems restricted to placing references in specific fields, but inline references can exist multiple times.
Manually creating tables in the Rich Text field works, but I need a way to automate this process using a migration script.
My current struggle is reflected in the console output for a table:
{
type: 'table',
align: [ null, 'center', 'right' ],
children: [
{ type: 'tableRow', children: [Array], position: [Position] },
{ type: 'tableRow', children: [Array], position: [Position] }
],
position: Position {
start: { line: 14, column: 1, offset: 970 },
end: { line: 25, column: 58, offset: 1660 },
indent: [
1, 1
]
}
}
Here's an excerpt of my code (simplified for clarity):
const {richTextFromMarkdown} = require('@contentful/rich-text-from-markdown')
module.exports = function(migration) {
migration.transformEntries({
contentType: 'article',
from: ['content'],
to: ['contentV2'],
transformEntryForLocale: async function(fromFields, currentLocale)
{
let copy = fromFields.content[currentLocale]
const content = await richTextFromMarkdown(copy,
(node) => {
let ret = null
let didSomething = true
node.deriveLinkedEntries()
switch (node.type) {
case 'image':
// ...
break;
case 'html':
// ...
break;
default:
didSomething = false
}
if (false === didSomething) {
console.log(node)
}
return ret
}
)
return {
contentV2: {
nodeType: 'document',
content: content.content,
data: {}
},
}
}
})
}