Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add Code → Preformatted block transform #9326
Adds the ability to transform Code blocks into Preformatted blocks. Due to the similar behavior of the two blocks, the transformation is completely lossless.
How has this been tested?
I made a packaged version of this branch, installed it on my website, created a Code block, added some content and a custom CSS class, and converted it to a Preformatted block successfully, with the content and CSS class being preserved.
I would have also added a Preformatted → Code transformation as well, but since the Code block lacks support for inline HTML elements (it does not use RichText), it would be a lossy conversion.
I made an issue about this: #6672. I would have fixed it in this PR and added the aforementioned Preformatted → Code transformation, but fixing it would require updating the Code block to use a RichText field.
At first, this sounds like no problem. However, RichText fields apparently have issues when they are inline elements. See #8785, #9180, and #9195. The content of the Code block is stored inside a
You might think that the solution to this issue is simply removing the
referenced this pull request
Aug 24, 2018
It's a bit of a bummer to allow the conversion to a
Preformatted block but then not back to a
I'd imagine we want to avoid one-way conversions. Are there other instances of one-way conversions like this? If so I'd say this is fine to merge, but if not I don't think we should implement this.
@tofumatt I thought there was, but apparently not. There are lossy conversions, though. You can transform a Cover Image into a Heading, but you lose the background image. I guess that would make it okay to add a Preformatted → Code transformation. Do you think I should do that?
@tofumatt Yeah, I guess it is alright. I just had this hypothetical situation in my head where someone had used a bunch of semantic markup in their code snippet (e.g. highlighting a specific line of code using a
But I guess that since all the Code block really does is add
But then that makes me wonder if the Code block is even that necessary. If it can't be used for the same kind of advanced situations as the Preformatted block (but involving code), then what is the point? Theme styling and the
I really wish the RichText thing was not an issue. As it is, the Preformatted block is much more flexible than the Code block, which makes the latter feel somewhat redundant. If it were not for the possibility of the RichText thing being fixed, I would say that the Code block might as well be removed, since you can just add a wrapping
But I guess until either the RichText issue is fixed, some workaround for inline HTML elements is found for the Code block, or the Code block is just removed entirely, it is fine to have a lossy conversion from the Preformatted block to the Code block. I will go ahead and add that to this PR.
We had a similar discussion several times already. We add only transformations which can be reversed without loosing any content. In this case you would loose all html tags so you can’t convert it back to Code block in thar sense.
See also a related PR which didn’t land in master: #5585.
@gziolo So why is Cover Image → Heading (and vice-versa) a valid transform? That is definitely a lossy conversion, and oddly enough, the Cover Image does not even use a heading element, so the transform would make more sense with a Paragraph block. Should the Cover Image → Heading (and vice-versa) transforms be removed?
Do we have that in a doc anywhere? That’s a good rule, I’m just not sure I’ve run across it reading through docs in the past.
Can this be merged as-is then, with just the one-way transform? Or are you saying we shouldn’t add more one-way transforms either? That seems inconsistent as some exist and the transform here does seem useful.