This Twitter thread was a life saver! For others reference, here is a working implementation (working for me) in JavaScript.
I used the showdown
library to convert Markdown to HTML, though any tool should work.
const showdown = require('showdown');
/**
* Converts the markdown to html. Webflow has known issue with parsing lists
* based on the markdown library they use. This is a workaround to convert
* the markdown to html, thing stringify it in a JSON object, the parse it,
* before sending it to the Webflow API.
*/
function convertMarkdownToRtf(markdown) {
const converter = new showdown.Converter();
/**
* Make object to stringify with rtf as the value. Replace
* new lines with empty string to circumvent parsing issues.
*/
const htmlString = JSON.stringify({
text: converter.makeHtml(markdown).replace(/\n/g, ''),
})
/* Parse the stringified object to get the string value. */
return JSON.parse(htmlString).text;
}
The returned text, when submitted to the Webflow CMS API for an Item’s RTF field, will render out lists properly.