WordPress not respecting escaped characters and treating as unescaped HTML
-
So I’m trying to insert an inline code block (a section inline which presents code I wrote and am talking about, but don’t want treated as HTML). However, when I add the HTML for the code block, wordpress insists on changing the < to a < when I save the post, thus upon reloading the editor it attempts to parse it as HTML and breaks. Even weirder, it will convert < to < on the first save and reload, then to < on the second save and reload. Can wordpress just treat escaped characters as escaped characters?
The blog I need help with is: (visible only to logged in users)
-
Hi mcottingham931253399,
I used a code example from the draft neural networks post but wasn’t able to replicate the behaviour you described when adding it to a
Codeblock, saving and then loading the post.Would you be able to send the exact steps you worked through in a numbered list? I can then work through them and do some more testing.
Thanks!
-
Recreation:
Open new post
Create paragraph
Enter “”
– Now in preview the full text “Test” appears as expected as we were not editing HTML but a text field
Save post
Leave the editor
Reopen the post in the editor
– Now in preview only “Test” appears, treats text as HTML!
Save post
Leave the editor
Reopen the post in the editor
– Now the block appears with the error message “This block contains unexpected or invalid content”Works on multiple browsers also occurs in mobile app, so maybe a server side parsing weirdness.
I found a workaround is to use the angle brackets Unicode characters, which look like less than and greater than signs, but that doesn’t address the underlying problem. -
Open new post
Create paragraph
Enter “Test”
– Now in preview the full text “Test” appears as expected as we were not editing HTML but a text field
Save post
Leave the editor
Reopen the post in the editor
– Now in preview only “Test” appears, treats text as HTML!
Save post
Leave the editor
Reopen the post in the editor
– Now the block appears with the error message “This block contains unexpected or invalid content”I forgot this is an HTML field…..
-
Okay third time lucky, this also occurs in this forum….
Make a new post with “[lt symbol]div[gt symbol] Test [lt symbol]/div[gt symbol]”
as the body of a paragraph, where the bits in brackets are replaced by the appropriate symbol.Alternatively just paste that as a reply in this thread.
-
-
That screen cast was amazing, thank you. I think the issue here is that you’re entering HTML in to the paragraph block. Try using it with the
codeorHTMLblock. -
The thing is, I don’t want the text to act like HTML, I want to just type this out so my readers can see the original [lt symbol]div[gt symbol]. My problem is that escaped characters are not treated as escaped characters but as their unescaped equivalents. Even in this forum, I can’t type this out properly,
<b> Test </b>
doesn’t appear as it should.
<b> Test </b>
Might also behave weirdly, I haven’t tested it on the forum, but it doesn’t work on posts on wordpress.com.
-
-
-
Okay, so communicating exactly what I am experiencing is rather hard, partly because the same bugs also occur when making posts to this forum.
I’ve written a pdf of the problems I’ve encountered: https://drive.google.com/file/d/1Xtnu7CxYqIQKhS0wK68nrrqviW3jjkOt/view?usp=sharing
Again, to reiterate, I do not want this code treated as code by WordPress, I want it treated as normal text.
-
Probably the fastest way to get a proper appreciation is to paste the contents of this text file as a reply in this thread, presuming you use a similar web-interface as us users.
https://drive.google.com/file/d/1UKGPgJRRZvBzilVvyImEWIlny-D6DSH3/view?usp=sharing
-
mcottingham931253399m so the text file you have there has the actual
& l t ; b & g t ; T e s t & l t ; / b & g t ;
without spaces. Is that what you wanted (with the character references rather than the characters themselves) or did you want to just display the HTML code like I’m seeing in the video?
If you want to show your readers actual HTML code, rather than just character entities, choose a code block. I used a syntax highlighted block and chose HTML for the syntax. It’s continuing to work fine after several saves, even with divs.
If you want to show the character references written out (like I did above, without spaces) instead of displaying the characters… I haven’t been able to sort out how best to do that yet. Let me know if that’s what you’re after though and we can do more digging.
-
It just want to display the HTML code. Effectively, I want to be able to type into an HTML field:
< b > Test < /b >
and have it displayed as:
< b > Test < /b >
except with div inside the < > (which shouldn’t matter, as regardless of what it is, this isn’t meant to be parsed as HTML)
However, when entering this into the HTML field with div:
< div > Test < /div <
This is displayed:
< div > Test < /div >
For reference, the raw text I typed when creating this post, as the issue also occurs in this HTML field as it does when creating a post: https://drive.google.com/open?id=16-QZM-OwialXPnCxlCK-buf6WrI34236
Please do dig deeper, the PDF I provided earlier is a great reference for the exact behavior I find confusing / problematic.
Using a syntax highlighted block does work fine, so that’s an option, but I would prefer to have HTML fields behave normally.
-
-
- The topic ‘WordPress not respecting escaped characters and treating as unescaped HTML’ is closed to new replies.