Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Preformatted block: Add support for font sizes #27584
Conversation
@@ -0,0 +1,4 @@ | |||
.wp-block-preformatted { | |||
overflow-x: auto; |
jasmussen
Dec 9, 2020
Contributor
The style.scss
file always gets loaded into the editor, so if a rule exists in that file, it does not need to be replicated in editor.scss
.
The style.scss
file always gets loaded into the editor, so if a rule exists in that file, it does not need to be replicated in editor.scss
.
mendezcode
Dec 9, 2020
Author
Oh, yes, true that. I'll fix accordingly.
Oh, yes, true that. I'll fix accordingly.
@@ -0,0 +1,4 @@ | |||
.wp-block-preformatted { | |||
overflow-x: auto; | |||
white-space: pre !important; |
jasmussen
Dec 9, 2020
Contributor
Since this rule also exists in style.scss
, we are so close to not needing any editor style at all for this block. And we should be avoiding !important anyway, if at all possible. I dug in to see why the !important was necessary, and it appears that white-space: pre-wrap;
is applied as an inline style on the preformatted block:
Why does that exist? I'm not sure, but from digging at the code, it looks to be related to this PR: #18656. Or possibly #17779. Specifically there's some commentary in https://github.com/WordPress/gutenberg/pull/17779/files#diff-7df6f5253ccec2f2e6d1bb22e81f87a4b6bccd2604463eeecded163aa27fd333R70 which seems relevant.
It seems we need to figure out why that output
Since this rule also exists in style.scss
, we are so close to not needing any editor style at all for this block. And we should be avoiding !important anyway, if at all possible. I dug in to see why the !important was necessary, and it appears that white-space: pre-wrap;
is applied as an inline style on the preformatted block:
Why does that exist? I'm not sure, but from digging at the code, it looks to be related to this PR: #18656. Or possibly #17779. Specifically there's some commentary in https://github.com/WordPress/gutenberg/pull/17779/files#diff-7df6f5253ccec2f2e6d1bb22e81f87a4b6bccd2604463eeecded163aa27fd333R70 which seems relevant.
It seems we need to figure out why that output
Thanks so much for this PR! Here's the editor, before: Frontend, before: Here's the editor, after: Here's the frontend, after: The font size control is also added: That font size stuff all seems fine. It also adds a
It seems the safest way forward, which still puts the frontend in sync with the editor, is to go in the opposite direction. Instead of:
you output
That way you can also remove the editor style you added again, and we sync up the frontend. I'd also argue that this serves as a good bugfix for the lacklustre overflow handling. What do you think? |
This is a more elegant solution compared to the previous one, which relied on overflow.
@jasmussen What I think would make sense here is to do the following: Set the default font size to match the existing size in Gutenberg. Right now it is My thinking here is that this needs to be done as progressive enhancement instead of doing it like I did initially. It must have backwards compatibility with the existing preformatted block, which means it would be totally better for it to have the same size it had. I'll work on the backwards compatibility fix for the font size and will keep you posted.
Makes absolute sense, I pushed a commit to address the |
The size looks the same to me in my testing of TT1
I think that's generally the safe mindset, but it doesn't have to be the case always. If the existing block has a bug or something in that category, it's fine to fix it. So the fact that it goes out to every user, is arguably a key benefit. So this isn't a fundamental issue, so much as us being careful that we do this deliberately and thinking through any potential side effects. |
Description
Adds support for font sizes to the preformatted code block. It also changes the CSS for this block to use the global styles variable, setting a fallback font size.
How has this been tested?
Tested with a block based and non block based version of
twentytwentyone
.Screenshots
Types of changes
New feature (non-breaking change which adds functionality).
Checklist: