stephenharris / WP-MarkDown

WP-MarkDown plug-in. Allows Markdown to be enabled in posts, comments and bbPress forums.
http://wordpress.org/extend/plugins/wp-markdown/
112 stars 19 forks source link

Markdownify fails for GitHub flavor-like codeblocks #69

Open magadanskiuchen opened 8 years ago

magadanskiuchen commented 8 years ago

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">&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;
</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
&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;
\```

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!

mAAdhaTTah commented 8 years ago

I think it needs to be rendered that way. Otherwise, the browser renders the html in the code block as html rather than text.

magadanskiuchen commented 8 years ago

@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:

&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;utf-8&quot; /&amp;gt;
    &amp;lt;title&amp;gt;Slider&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;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.

magadanskiuchen commented 8 years ago

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 ).

stephenharris commented 7 years ago

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).

sivyel commented 4 years ago

@stephenharris How to use c# code blocks instead of writing csharp. Actually git flavour markdown supports other terms of languages.

```C# instead of ```csharp