Some content inside fenced codeblocks is being transformed #762

Closed
opened 2026-01-29 14:44:58 +00:00 by claunia · 5 comments
Owner

Originally created by @mavnn on GitHub (Nov 13, 2025).

In the following markdown, the bullet points of the fenced codeblock are being transformed into html unordered list elements rather than preserved as plain text. Each <li> element within the list is then also being wrapped in it's own <code> element for extra formatting strangeness.

Input

## Choices

There are two main types of choice:

```
Some story

+ This choice will be shown every time the story gets here
* This choice will only be shown until it has been picked, then it will disappear
```

Output:

<h2>Choices</h2>
<p>There are two main types of choice:</p>
<pre><code>Some story
<ul>
<li>This choice will be shown every time the story gets here</li>
</ul>
</code><ul><code>
</code><li><code>This choice will only be shown until it has been picked, then it will disappear
</code></li></ul></pre>

Strangely, it is possible to work around this issue by putting inline code markers around the punctuation within the code block, although this then creates nested html <code> elements. This suggests that there is a further bug there (the inline markers should not be being processed within the fenced block either):

Input 2:

## Choices

There are two main types of choice:

```
Some story

`+` This choice will be shown every time the story gets here
`*` This choice will only be shown until it has been picked, then it will disappear
```

Output 2:

<h2>Choices</h2>
<p>There are two main types of choice:</p>
<pre><code>Some story
</code><p><code><code>+</code> This choice will be shown every time the story gets here
<code>*</code> This choice will only be shown until it has been picked, then it will disappear
</code></p></pre><p></p>
Originally created by @mavnn on GitHub (Nov 13, 2025). In the following markdown, the bullet points of the fenced codeblock are being transformed into html unordered list elements rather than preserved as plain text. Each `<li>` element within the list is then also being wrapped in it's own `<code>` element for extra formatting strangeness. Input ~~~ ## Choices There are two main types of choice: ``` Some story + This choice will be shown every time the story gets here * This choice will only be shown until it has been picked, then it will disappear ``` ~~~ Output: ``` <h2>Choices</h2> <p>There are two main types of choice:</p> <pre><code>Some story <ul> <li>This choice will be shown every time the story gets here</li> </ul> </code><ul><code> </code><li><code>This choice will only be shown until it has been picked, then it will disappear </code></li></ul></pre> ``` Strangely, it is possible to work around this issue by putting inline code markers around the punctuation within the code block, although this then creates nested html `<code>` elements. This suggests that there is a further bug there (the inline markers should not be being processed within the fenced block either): Input 2: ~~~ ## Choices There are two main types of choice: ``` Some story `+` This choice will be shown every time the story gets here `*` This choice will only be shown until it has been picked, then it will disappear ``` ~~~ Output 2: ``` <h2>Choices</h2> <p>There are two main types of choice:</p> <pre><code>Some story </code><p><code><code>+</code> This choice will be shown every time the story gets here <code>*</code> This choice will only be shown until it has been picked, then it will disappear </code></p></pre><p></p> ```
claunia added the question label 2026-01-29 14:44:58 +00:00
Author
Owner

@xoofx commented on GitHub (Nov 13, 2025):

Hm, are you sure that this is the exact setup you have? Cannot reproduce it here

Are you using particular extensions maybe? What is the version you are using?

@xoofx commented on GitHub (Nov 13, 2025): Hm, are you sure that this is the exact setup you have? Cannot reproduce it [here](https://babelmark.github.io/?text=%23%23+Choices%0A%0AThere+are+two+main+types+of+choice%3A%0A%0A%60%60%60%0ASome+story%0A%0A%2B+This+choice+will+be+shown+every+time+the+story+gets+here%0A*+This+choice+will+only+be+shown+until+it+has+been+picked%2C+then+it+will+disappear%0A%60%60%60) Are you using particular extensions maybe? What is the version you are using?
Author
Owner

@mavnn commented on GitHub (Nov 13, 2025):

Thanks for the quick response.

I'm using version 0.43, according to Markdig.Markdown.Version.

The workflow I'm using is:

  • reading the markdown text from a file using System.IO.ReadAllTextAsync
  • call Markdig.Markdown.ToHtml with the string from above

I'm not using any extensions, so I'm not quite sure what would be the next step to help with the debugging.

@mavnn commented on GitHub (Nov 13, 2025): Thanks for the quick response. I'm using version 0.43, according to `Markdig.Markdown.Version`. The workflow I'm using is: - reading the markdown text from a file using `System.IO.ReadAllTextAsync` - call `Markdig.Markdown.ToHtml` with the string from above I'm not using any extensions, so I'm not quite sure what would be the next step to help with the debugging.
Author
Owner

@xoofx commented on GitHub (Nov 13, 2025):

Could you post the exact Program.cs you are using?

@xoofx commented on GitHub (Nov 13, 2025): Could you post the exact Program.cs you are using?
Author
Owner

@mavnn commented on GitHub (Nov 13, 2025):

Sort of! I'll post this here for now, let me see if I can create a reproduction that isn't in the web server context.

module VisualInk.Server.InfoPages

open Prelude
open Markdig
open Microsoft.AspNetCore.Hosting
open System.IO

let private mdToHtml path =
  handler {
    printfn "Markdig version: %A" Markdown.Version
    let! hostEnv = Handler.plug<IWebHostEnvironment, _> ()

    let! html =
      task {
        let! text =
          File.ReadAllTextAsync(
            Path.Join(hostEnv.ContentRootPath, path)
          )
        return Markdown.ToHtml(text)
      }
      |> Handler.returnTask

    return html
  }

@mavnn commented on GitHub (Nov 13, 2025): Sort of! I'll post this here for now, let me see if I can create a reproduction that isn't in the web server context. ```fsharp module VisualInk.Server.InfoPages open Prelude open Markdig open Microsoft.AspNetCore.Hosting open System.IO let private mdToHtml path = handler { printfn "Markdig version: %A" Markdown.Version let! hostEnv = Handler.plug<IWebHostEnvironment, _> () let! html = task { let! text = File.ReadAllTextAsync( Path.Join(hostEnv.ContentRootPath, path) ) return Markdown.ToHtml(text) } |> Handler.returnTask return html } ```
Author
Owner

@mavnn commented on GitHub (Nov 13, 2025):

Actually - ignore me completely: on this page I was feeding the output of Markdown.ToHtml to... Markdown.ToHtml before returning it from the handler.

Apologies for the noise, and thank you for the courteous response!

@mavnn commented on GitHub (Nov 13, 2025): Actually - ignore me completely: on this page I was feeding the output of `Markdown.ToHtml` to... `Markdown.ToHtml` before returning it from the handler. Apologies for the noise, and thank you for the courteous response!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#762