Editing posts with markdown markup.
-
I’ve noticed a problem with blog posts created with markdown. Using HTML special characters like ”, or ‘&’ works as expected until you’ve published your blog post and want to edit them. Then those characters show up as ‘<‘, ‘>’ and ‘&’ (that is, as escaped sequences), both while editing the post, and subsequent saving it.
This makes editing posts with blockquotes (which uses ‘>’) or code (which uses all of ‘>’, ‘<', and '&') a nightmare.
How do I solve this?
-
Hi there,
The idea of WordPress.com is to be able to create a blog or a site without the need of using the code. Still, you are able to add some HTML to the HTML Block, if you need.
What process are you following exactly to create your posts and what are you trying to achieve?
Also, please confirm the address of the site you’re working on. -
I’m not using “the code”. I’m making a programming blog, which shows code (as in, fragments of programs in computer languages).
In particular, I’m trying to use a blockquote using markdown (which means each line starts with a ‘>’), or showing code fragments, by it inlininging it (using markdown’s backticks) or as code blocks (using markdown’s ~~~~). An example of a code fragment is ‘a < b && c > d’.
All works fine when editing, previewing, and saving the post. It goes wrong when editing a saved post — each ‘>’ is turned into a ‘>’, each ‘&’ into an ‘&’, and each ‘<‘ into a ‘<‘. Worse, anything which looks like it could be an HTML tag, disappears (so, ‘a<b && c>d’ becomes ‘ad’).
The blog I’m working on is https://programmingblog910557004.wordpress.com/
-
Arg, when I wrote “each ‘>’ is turned into a ‘>’, it converted the latter back to a ‘>’. What I mean is:
Each ‘>’ is turned into a ‘>’
Each ‘<‘ is turned into a ‘<’
Each ‘&’ is turned into a ‘&’ -
Seems the post above turned the escapes back.
What I mean is that every ‘>’ is turned into ‘<’, every ‘<‘ is turned into ‘<’, and each ‘&’ is turned into ‘&’. That is, each of those characters is turned into its HTML escape.
-
Hi there,
Maybe you should try to use the Syntax Highlighter Code block, in order to add formatted code for others to view.
https://wordpress.com/support/wordpress-editor/blocks/syntax-highlighter-code-block/view-all/
-
Thanks for the details. As @billiemaroudas mentioned, you’ll want to use a Block that will allow you to post code without rendering it. Syntax Highlighter is one but you can also add the Code Block:
https://wordpress.com/support/wordpress-editor/blocks/code-block/
I hope that helps :)
-
While code blocks and syntax highlighter does not have the issue described, it does not solve the issue when using ‘>’, ‘<‘ or ‘&’ in markdown paragraphs. Or markdown blockquotes (where each line starts with ‘>’).
Further more, code blocks have another issue: if copy and pasting text into a code block, leading white space is not preserved. Code without leading white space is not readable.
-
The characters converting into HTML entities in the custom HTML block is a known issue and is being worked on over on WordPress.org. Once they figure out a fix there, it will also work here. You’re welcome to follow along on progress on this in https://github.com/WordPress/gutenberg/issues/24282
I’m able to replicate the issue in the markdown block. This appears to be specific to WordPress.com, so I’ve reported it for our developers to look into.
Further more, code blocks have another issue: if copy and pasting text into a code block, leading white space is not preserved. Code without leading white space is not readable.
Are you pasting from a particular text editor?
Can you paste a snippet of example code for me here that I can use to try and replicate it? You can paste code in the forums using backticks, and it should be posted exactly the way you enter it.
-
I’m copying & pasting from vi running in a terminal (MacOS). But the same happens when copying & pasting the output from “cat”, from a different editor, or even from a webpage.
A sample example which goes wrong:
if (a < b) { printf ("Yesn"); }Copy-and-pasting this loses the indentation of the print statement inside the block.
-
For what it’s worth, if I put just this code in a syntax highlighter block, it renders nicely:
if (a < b) { printf ("Yesn"); }I’m trying to understand why you would put markdown in the syntax highlighter block, rather than using markdown block for that. Are you hoping to display the markdown code?
-
I am not trying to put markdown in a syntax highlighter block.
I am not even trying to use a syntax highlighter block. I’m just trying to use markdown. Either as a blockquote (which uses ‘>’ to signal it’s a blockquote), as a code block (delimited by ~~~~, should render “as is”), or just as regular text. The problem is that markdown -> save -> edit isn’t preserving, it turns ‘<‘, ‘>’ and ‘&’ into its HTML entities.
And I’m sure the three lines of code render perfectly in a syntax highlighter block. But that was the not the issue. This was about the side issue of copy-and-paste not preserving leading white space in code blocks — code blocks were suggested as an alternative to display code.
-
Thank you for explaining. To clarify, you prefer to compose your entire post as markdown? What if you try to add the same markdown here in the wp-admin version of the block editor:
https://programmingblog910557004.wordpress.com/wp-admin/post-new.php
The block interface in this view is similar to what you use, but the underpinnings are a bit different. If you add a Markdown block and compose a new post (or a test post) in this place do you have the same issue of character getting converted into HTML entities?
Thanks for the additional info!
-
I get the same issue. If I add a markdown block, and add
a > b, save it, then edit the new post, it turns intoa > b, that is, the greater than symbol is turned into an its HTML escape sequence. -
Ah, lovely,
in posts not doing what it ought to do (keeping things as is).What I mean is that typing in
a > b, saving it, then editing the new posts, turns in intoa > b. -
Ok….. how often does this forum turn deescape escaped sequences?
One more try, after saving in editing, the text shows up as:
a & a m p ; l t; b(but then without the spaces). -
Thanks for confirming. We have reported this to our engineers for a closer look. I don’t have a workaround in the meantime, so you will need to use our standard blocks to format your post rather than purely using markdown.
Thanks for your patience!
-
Same issue. I want to quote a bulleted list and reflexively used a Markdown block. The block ate my formatting after coming back to edit.
> Cmdlets differ from commands in other command-shell environments in the following ways:> * Cmdlets are instances of .NET classes; they are not stand-alone executables.
> * Cmdlets can be created from as few as a dozen lines of code.> * Cmdlets do not generally do their own parsing, error presentation, or output formatting. Parsing, error presentation, and output formatting are handled by the PowerShell runtime.
> * Cmdlets process input objects from the pipeline rather than from streams of text, and cmdlets typically deliver objects as output to the pipeline.> * Cmdlets are record-oriented because they process a single object at a time.
Thanks for the link to the bug.
Separately, and addressing my own experience, I have a strong habit of editing outside of WordPress. I didn’t use the block editor until the forced change. And the classic editor would eat entities all the time. So, pasting into WP isn’t strange to me.
-
Formatting problems aside, the result is here:
https://mypowershellnotes.wordpress.com/2020/10/24/how-cmdlets-differ-from-commands/
-
- The topic ‘Editing posts with markdown markup.’ is closed to new replies.