WP-MarkDown
WP-MarkDown copied to clipboard
Markdownify fails for GitHub flavor-like codeblocks
I've noticed that the 1.6 alpha version here in GitHub has support for parsing MarkDown with ability to specify a language such as:
```language-name
which is great for the alternative prismjs syntax highlighter I'm using!
However, when the post is edited the Markdownify class fails to properly display that with MarkDown code. So in my particular case this:
\```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Slider</title>
</head>
<body>
</body>
</html>
\```
is rendered as:
<pre><code class="language-html"><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Slider</title>
</head>
<body>
</body>
</html>
</code></pre>
which no longer allows me to easily make edits to my blogpost.
I've tried sorting this out (and had I succeeded I would have submitted a pull request), however, I only got that to:
\```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Slider</title>
</head>
<body>
</body>
</html>
\```
where still html entities are used.
You can see patch of my code here: https://gist.github.com/magadanskiuchen/74aa03205f2167c89ded7bffcf412ee2
If you're able to further resolve this and merge into master that would be awesome!
I think it needs to be rendered that way. Otherwise, the browser renders the html in the code block as html rather than text.
@mAAdhaTTah maybe I wasn't clear but this is not the raw output, rather what's displayed in the editor.
The actual markup is double-escaped:
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="utf-8" /&gt;
&lt;title&gt;Slider&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
So my guess would be that I need to run it once through htmlspecialchars_decode
, however, since this function does not seem to be called in the plugin anywhere else (at least I cannot find it) I would guess a different approach is taken in other similar cases and I'd like to keep is consistent. I just seem to be missing something.
OK, I've found that the Markdownify
class has a decode
method that's used with that purpose in other placed within the class, so I've just ran the code though that and it works nicely.
I've just submitted a PR for this ( #70 ).
I've added a (failing-but-skipped) test for this. It is a bug, but unfortunately #70 breaks some other tests.
I have found that it only affects code blocks with language identifiers. Code blocks without and rendered correctly into MarkDown (albeit not GitHub flavoured markdown - i.e. the blocks appear using the indentation syntax, not the fences).
@stephenharris How to use c# code blocks instead of writing csharp. Actually git flavour markdown supports other terms of languages.
```C# instead of ```csharp