showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.26k stars 1.56k forks source link

Reserved HTML characters are not replaced by their corresponding entities in code blocks #878

Closed aakodadi closed 2 years ago

aakodadi commented 2 years ago

What I did:

I have a markdown file that looks like this:

...

    #include <stdio.h>
    #include <stdlib.h>

    int
    main (int argc, char** argv)
    {
      printf("Hello world!\n");
      return (EXIT_SUCCESS);
    }

...

I use the command line tool to generate the HTML file.

What I expect:

Since the lines are prefixed with four spaces, I expect them to be interpreted as code and the < and > symbols in <stdio.h> and <stdlib.h> should be replaced by their entities counterparts. i.e &lt; and &gt;

What I got:

My HTML looks like this:

...
<pre><code>#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char** argv)
{
  printf("Hello world!\n");
  return (EXIT_SUCCESS);
}
</code></pre>
...

< and > are left as they are in the resulting HTML. As a result, the browser interpret <stdio.h> and <stdlib.h> as HTML tags, and they don't appear as text.

Version

1.9.1

SyntaxRules commented 2 years ago

What browser is this happening on?

This seems related to: https://github.com/showdownjs/showdown/issues/861 That issue seems to have the problem where these entity counterparts are created, and you are having the opposite problem.

aakodadi commented 2 years ago

What browser is this happening on?

This seems related to: #861 That issue seems to have the problem where these entity counterparts are created, and you are having the opposite problem.

I am using it as a command line tool with Node.js v17.3.0 not on a browser. And yes, you are right, it seems to be the opposite of #861. However, my issue happens with markdown style code blocks (with four spaces prefix and ``</code>) and #861 is for HTML style code blocks (using` tags)

EDIT: I believe that #861 is not an issue (correct me if I'm wrong), it's supposed to behave that way.

aakodadi commented 2 years ago

Never mind, showdown works correctly. My issue was caused by something else.