Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: html typography applying to entire editor #585

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions inc/class-typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,23 @@ public function enqueue_editor_scripts() {
$html_typography = self::get_css( 'core', 'html' );

if ( $html_typography ) {
// The editor uses the `body` selector for things like `font-size` and
// replaces the `body` selector with `editor-styles-wrapper`. This should make
// it so our `html` selector appears as `body` in the editor and overwrites the
// common.css file.
$desktop_css = str_replace( 'html', 'body:not(.editor-styles-wrapper)', $html_typography );
/**
* We don't want to apply our `html` `font-size` to the `<html>` element in the editor,
* or it will apply to text everywhere, including the inspector controls.
*/
$desktop_css = str_replace( 'html', '.is-desktop-preview', $html_typography );

wp_add_inline_style(
// wp-edit-blocks is enqueued in the editor, including the iframes.
// This may break one day, but it's the only way to add CSS into the iframes
// without WordPress replacing selectors like `html` and `body`.
/**
* `wp-edit-blocks` is enqueued in the editor, including the iframes.
* This is not ideal, as we should use the `block_editor_settings_all` filter to add editor CSS.
* However, that filter prepends all selectors with `.editor-styles-wrapper`, which breaks the above
* selector, as it appears above that element in the DOM.
*
* Related: https://github.com/tomusborne/generatepress/issues/472
*/
'wp-edit-blocks',
// We add `$desktop_css` to apply to the `<body>` element on desktop and
// We add `$desktop_css` to apply to the `.is-desktop-preview` element on desktop and
// then we add `$html_typography` to apply to the `<html>` element in the device previews.
$desktop_css . $html_typography
);
Expand Down