From 2565fa4f41d874ba723bb0bd4432d476f4728334 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH] Ensure adjacent codeblocks separated by newline --- core/commands/slash/share.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index d9ed1ae95..55f4eef9c 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -23,14 +23,15 @@ function asBasicISOString(date: Date): string { } function reformatCodeBlocks(msgText: string): string { - const codeBlockRegex = /```((.*?\.(\w+))\s*.*)\n/g; - - return msgText.replace(codeBlockRegex, + const codeBlockFenceRegex = /```((.*?\.(\w+))\s*.*)\n/g; + msgText = msgText.replace(codeBlockFenceRegex, (match, metadata, filename, extension) => { const lang = languageForFilepath(filename); return `\`\`\`${extension}\n${lang.comment} ${metadata}\n`; }, ); + // Appease the markdown linter + return msgText.replace(/```\n```/g, '```\n\n```'); } const ShareSlashCommand: SlashCommand = {