Markdown support for code fragments is broken
-
As a long time user of Markdown, I have come to value it for light-weight and mostly clutter free expression, especially of ideas surrounding programming and programming languages. When I recently decided to add a blog to my company website hosted by WordPress, I did so partially because WordPress claims support for Markdown.
Unfortunately, that support is buggy. See this post where I attempt to exercise punctuation marks in code fragments using the three mechanisms supported in WP’s flavor of Markdown:
Notice in particular the way the ampersand character is mishandled by two of the displays, and the way the less than and greater than characters are lost completely.
Part of the problem seems to be that the text editor (while at least now appearing to remember to remain Text and not Visual, aside from the Beep Beep Boop thing which is another topic entirely) is trying to be helpful and messing with the post before the Markdown engine is given its shot. This post doesn’t show it, but I got here because of another post where the editor refused to let me type a greater than sign without immediately changing it to the HTML entity.
I would propose that the editor used for blogs that have Markdown enabled should be far less intrusive about correcting apparent errors in the text, and if some sort of sanity check is needed that it be applied to the result of the Markdown engine.
The blog I need help with is: (visible only to logged in users)
-
Thanks for the report! Do you have the same trouble if you only use the Visual editor tab without switching to the Text tab?
-
I hadn’t tried the Visual tab (on purpose, at least) since the warning is made reasonably prominently that using it with Markdown will lead to unpredictable results.
I know from other reports on this forum that the VIsual tab removes leading whitespace from lines “by design”. Since leading whitespace is part of the markdown syntax, that is a big problem right there. In particular, one of the examples of code fragment shown in my blog post is written with a four-space indent to signal that the block of text is preformatted code.
As I understand it, the goal of the Visual tab is to be a WYSIWYG editor for HTML and/or WordPress shortcodes.
My goal is to write posts in Markdown which WP claims is supported if the blog is configured to use it, but which does not appear to work as well as claimed. My blog is configured to use Markdown in both posts and comments.
In particular, I can still see in the editor that almost all the characters I intended to write in the post are all present, but something has now replaced the
&signs with their HTML entity equivalents which are then shown literally as&. (Assuming that those ampersands make it through whatever mishmash formatter is applied to these comments, at least.)In short, the Visual tab is a complete non-starter for me because it does not support Markdown at all.
Accidentally opening the post in the Visual tab of the “new” editor causes the editor to surround all of the carefully crafted Markdown text with fresh HTML paragraphs, which destroys its meaning. That destruction is permanent, in that you can’t just switch to the Text tab to see the original post. So for me, the “new” editor is worse than useless, it is actually damaging.
-
One reason for Markdown’s popularity with people writing about programming is that it has a clear mechanism for quoting code, and when that is properly implemented it is possible to copy and paste even large blocks of code into a post without needing to worry about standard notations like comparison operators or pointers, and without worrying too much about whitespace.
Without that, I might as well abandon WordPress entirely as the friction caused by using anything other than Markdown for writing about code is immense.
There is good reason why it was adopted by GitHub and the entire Stack Overflow family among many others.
-
- The topic ‘Markdown support for code fragments is broken’ is closed to new replies.