Open LangLangBart opened 10 months ago
This change correctly displays a codeblock with three backticks in the preview. However, the same issue may arise if a user uses four backticks.
--- a/gui/src/components/markdown/CodeSnippetPreview.tsx
+++ b/gui/src/components/markdown/CodeSnippetPreview.tsx
@@ -138,9 +138,9 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
</PreviewMarkdownHeader>
<pre className="m-0" ref={codeBlockRef}>
<StyledMarkdownPreview
- source={`\`\`\`${getMarkdownLanguageTagForFile(
+ source={`\`\`\`\`${getMarkdownLanguageTagForFile(
props.item.description
- )}\n${props.item.content}\n\`\`\``}
+ )}\n${props.item.content}\n\`\`\`\``}
maxHeight={MAX_PREVIEW_HEIGHT}
showCodeBorder={false}
/>
@sestinj, could the solution be to find the maximum number of consecutive backticks used and then use one more backtick?
Before submitting your bug report
Relevant environment info
Description
When a user writes a code block in a markdown document and later uses the
/edit
slash command on this code block, the code block isn't accurately displayed in the code preview and is entirely eliminated from the resulting diff.Possible solution idea?
The display problem of the code block within your preview might be resolved for most cases by using an increased number of backticks.
In markdown, typically a single backtick starts inline code and three backticks start a code block. However, you can use any number of backticks, just ensure the number of backticks used to start and end a code block is the same.
For example, this code block starts and ends with nine backticks, and everything inside is properly displayed. If I had used only eight backticks, the last code block would not render properly in markdown.
This is a code block with 8 backticks
The idea of using extra backticks in markdown for properly formatting inline code or code blocks was obtained from a video[^1] produced by a VSCode maintainer who also developed numerous VSCode markdown extensions[^2].
[^1]: YouTube: Markdown Tips — Using backticks in inline code [^2]: Publisher Matt Bierner - Visual Studio Marketplace
To reproduce