Problem with html when converting to blocks
-
The problem I find is that when I convert to blocks from a page previously written in classic editor, very often the html gets screwe up for instance this code:
<div class="rightfloat"> <strong>The best one out there...</strong> <strong>Phill Straker (sax.co.uk)</strong> [caption id="" align="alignnone" width="260"]<a href="https://tamingthesaxophone.com/saxophone-instruction-dvd" name="internal"><img src="https://tamingthesaxophone.com/pic-sax/saxophone-instruction-dvd.gif" alt="Learn Saxophone with Pete Thomas Saxophone Instruction DVD" width="260" height="294" /></a> Devised and presented by Pete ThomasAll profits to charity[/caption] [add_to_cart id="1217" sku="BDV013"] </div>
Gets converted to html block but only the text: the image and woocommerce shortcode are outside (below the html block) and so are not shown correctly within the div (which has a border is floated to the right)
So how do I make it so that everything within a div stays within the div?
Thank you.
-
This topic was modified 4 years, 10 months ago by
Mr Lucky.
-
This topic was modified 4 years, 10 months ago by
-
You could add a classic block to your page and change it to HTML mode and try to paste that in and it should hopefully work as expected.
Realistically, not all old post content, especially those with inline HTML, can be directly converted to blocks. You should leave such content in the Classic Block instead, and let it be.
If you want to convert such things, then you would essentially need to rebuild it by hand.
Looking at your content here, you essentially have a DIV with rightfloat on it, which contains a couple of bolded lines and a couple of shortcodes.
So, in 5.4, I’d start by making a group, put a couple of Paragraph blocks into it with the text lines, then add a couple of Shortcode blocks and paste the shortcodes into them. Since you want the whole thing floated right, then I’d select the group, and set it to align on the right.
It won’t produce the exact same HTML, but the purpose of the editor is to make these things so that you don’t have to know HTML.
Yes, except that there’s lots of this type of thing, I just want it to automatically convert to blocks without faffing.
Likewise I could copy and paste those shortcodes into the html block, but I’m just wanting it to be a quicker process so I can convert the page (or rather pages as there are a lot) and then carry on working with them not spend forever editing just so they work…
Well, the thing about converting to blocks is that you don’t actually need to do it. The existing code will work just fine and will keep on working just fine for the future. WordPress doesn’t break your old posts, since it doesn’t edit them for you.
The only reason to convert an old post to blocks is if you want to change that post in some way. Simply converting it without making any changes to it doesn’t really accomplish anything.
Well, the thing about converting to blocks is that you don’t actually need to do it. The existing code will work just fine and will keep on working just fine for the future. WordPress doesn’t break your old posts, since it doesn’t edit them for you.
The only reason to convert an old post to blocks is if you want to change that post in some way. Simply converting it without making any changes to it doesn’t really accomplish anything.
I think you are misunderstanding what I want. See my post above:
and then carry on working with them…
I appreciate the workarounds, all I was trying to find out was why the “convert to blocks” messed my pages up. I want to convert to blocks so I can then continue and use blocks on those pages. I understand I could just leave everything as is but my question is about converting to blocks so that I can continue working on the pages and using blocks.
So either I am missing something or there is a bug in the conversion to blocks because surely it should just do what it says on the tin, ie convert to blocks.
You could add a classic block to your page and change it to HTML mode
This sounds useful, but when I click on add block, I do not see classic block??? It is not there in the block library.
all I was trying to find out was why the “convert to blocks” messed my pages up
Because the “convert to blocks” function is not all-knowing. It does its best, but the truth is that with the old editor, you could have literally anything in there. Invalid HTML, weird stuff like DIVs, etc. It can’t convert from “literally anything” to “a structured format” like blocks are.
Converting to blocks is not, and never will be, perfect. It’s meant to be a way to help transition from the most common types of posts to blocks, but even with all the smarts in the world, it still needs manual fiddling on some posts to complete the process.
Manual intervention will always be required when converting to blocks. Even with some rather basic post styles.
This sounds useful, but when I click on add block, I do not see classic block??? It is not there in the block library.
It’s a default block. It’s built in. Not sure why you wouldn’t see it, it’s right there in a normal installation:
Because the “convert to blocks” function is not all-knowing. It does its best, but the truth is that with the old editor, you could have literally anything in there. Invalid HTML,
No – yes of course there might be – but in this case the html was not invalid.
weird stuff like DIVs, etc.
Do you mean divs are weird when in uppercase? Maybe, but all of my divs are in lower case but of course divs per se are not weird, a very normal and very basic part of html.
I do unsder stand if something is very complex then things would be trickier, but i don’t understand why something as simple as one div tag with a correct closing tag </div> cannot be rendered to a html block with all its contents intact – even with shortcodes in there because there is nothing complex about a couple of shortcodes.
Do you mean divs are weird when in uppercase? Maybe, but all of my divs are in lower case but of course divs per se are not weird, a very normal and very basic part of html.
Yeah, but they’re not typically a part of WordPress Post content. Recently, the block editor added support for Group Blocks, and those use DIVs, but that’s an entirely new addition. Having DIVs in old posts is, well, strange. Unusual. Not typical.
For most people, posts are, by an large, text. Paragraphs. Maybe some images, shortcodes, or HTML to modify that text like em and strong and such. Having DIVs and blocks and floating things around: not typical. The converter isn’t going to know how to deal with things like that all the time.
I do unsder stand if something is very complex then things would be trickier, but i don’t understand why something as simple as one div tag with a correct closing tag </div> cannot be rendered to a html block with all its contents intact – even with shortcodes in there because there is nothing complex about a couple of shortcodes.
What is it supposed to convert the DIV into? Groups were only just recently added, and no other block uses DIVs like that. Not arbitrary DIVs anyway. Shortcodes it usually will convert to a shortcode block, which is fair since it has no idea what the shortcode does. But yeah, it likely has no idea how to convert an arbitrary and random DIV into a group. Too new.
Yeah, but they’re not typically a part of WordPress Post content. Recently, the block editor added support for Group Blocks, and those use DIVs, but that’s an entirely new addition. Having DIVs in old posts is, well, strange. Unusual. Not typical.
To be fair I think that is arguable. After all for years wordpress editor has the default option to switch between visual and html, so html is an expected part of post creation and editing, as is the use of custom css with the customizer “additional CSS” feature.
What is it supposed to convert the DIV into? Groups were only just recently added, and no other block uses DIVs like that. Not arbitrary DIVs anyway. Shortcodes it usually will convert to a shortcode block, which is fair since it has no idea what the shortcode does. But yeah, it likely has no idea how to convert an arbitrary and random DIV into a group. Too new.
I completely get your point, yes group blocks are new so I can see why it doesn’t (yet) work.
But would it be fair to say that the convert to blocks feature should catch up technologically with the blocks? And so this may be added in the future?
It could be very useful for those who at first kicked against the concept of Gutenberg editor (saying it was “dumbing down”) as it seemed limited and not so useful for those who may want to go just a little beyond what you describe most people do:
For most people, posts are, by an large, text. Paragraphs.
In my case it is simply doing something not too weird. I want a right floated box with text, image and woocommerce product shortcode. Kind of thing you see on standard websites.
After all for years wordpress editor has the default option to switch between visual and html, so html is an expected part of post creation and editing, as is the use of custom css with the customizer “additional CSS” feature.
The general notion is that most people don’t know HTML, don’t want to know HTML, and would prefer to edit things visually, without having to learn HTML.
So, if you know HTML well enough to have been using the thing in that manner for a while, then it’s not really a burden on you to convert it yourself, basically. The Custom HTML block exists to use whatever HTML you want in a block, the Code Editor exists to let you fiddle with the HTML directly, etc.
But would it be fair to say that the convert to blocks feature should catch up technologically with the blocks? And so this may be added in the future?
I don’t develop the editor myself and thus have no say or knowledge of the matter directly, but I would doubt it. When it comes to arcane HTML code (and yes, for a post’s content, a DIV is “arcane”), then it is unlikely to see any support added. Just my opinion, I might be wrong.
While you may consider DIVs and CSS and floating things to be perfectly normal, try explaining layout notions like these to somebody making a church blog who just wants to put up the transcript of yesterday’s sermon and make it look nice.
The advanced functionality is there if you need it. But expecting the functionality meant for less advanced users, which block conversion is definitely intended for, to understand complex HTML is just asking too much.
In my case it is simply doing something not too weird. I want a right floated box with text, image and woocommerce product shortcode. Kind of thing you see on standard websites.
Yes, but up until now that has been a weird thing to do in the post editor. There was no easy way to do that in the classic editor. Not without knowing HTML. The block editor now has a way to do that: make a group, align it right, stuff some other blocks in the group. This is entirely new functionality that the neither the old nor the new editor has never actually had before. For it to recognize something that you added by hand to be the same thing is unreasonable.
There might be a case where a DIV could be recognized as a group and converted to such, but there’s no case where it’s going to know your custom classes and recognize their meaning.
- The topic ‘Problem with html when converting to blocks’ is closed to new replies.