1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-09-25 00:21:28 +02:00

Handle the wrapping of tag in codeblocks

This commit is contained in:
Kamran Ahmed
2025-05-23 11:35:44 +01:00
parent 0d1f19f0a3
commit d64303bd69

View File

@@ -30,7 +30,26 @@ export async function parseMessageParts(
) {
const parts: MessagePart[] = [];
const tagNames = Object.keys(renderer);
// Remove codeblocks around custom tags
if (tagNames.length > 0) {
const tagPattern = tagNames.join('|');
// Remove opening codeblock before tags: ```lang\n<tag> -> <tag>
// It sometimes puts codeblocks around our tags (despite us asking it not to)
// so we manually remove them here
content = content.replace(
new RegExp(`\`\`\`\\w*?\\n+?<(${tagPattern})>`, 'g'),
'<$1>',
);
// Remove closing codeblock after tags: </tag>\n``` -> </tag>
content = content.replace(
new RegExp(`<\\/(${tagPattern})>\\n+?\`\`\``, 'g'),
'</$1>',
);
}
// If no renderers, just return the content as markdown
if (tagNames.length === 0) {
const html = await markdownToHtmlWithHighlighting(content);