Make WordPress Core

Changeset 61632


Ignore:
Timestamp:
02/13/2026 01:51:03 AM (9 months ago)
Author:
ramonopoly
Message:

Block Supports: Add text indent to typography supports

This commit adds CSS text-indent support for paragraph blocks with traditional typography conventions - subsequent paragraphs get first-line indented in LTR languages, with an option to indent all paragraphs (default for RTL languages).

Text indentation is a fundamental typography feature. Traditional print typography conventions dictate that only subsequent paragraphs (not the first) should have their first line indented in LTR languages, while RTL languages typically indent all paragraphs. This feature enables proper typographic styling that matches publishing standards.

Props aaronrobertshaw, ramonopoly, andrewserong, wildworks, matveb, skorasaurus, greenshady, kjellr.

Fixes #64326.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/typography.php

    r61430 r61632  
    1212 * @since 5.6.0
    1313 * @since 6.3.0 Added support for text-columns.
     14 * @since 7.0.0 Added support for text-indent.
    1415 * @access private
    1516 *
    … …  
    3637        $has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
    3738        $has_text_transform_support  = $typography_supports['__experimentalTextTransform'] ?? false;
     39        $has_text_indent_support     = $typography_supports['textIndent'] ?? false;
    3840        $has_writing_mode_support    = $typography_supports['__experimentalWritingMode'] ?? false;
    3941
    … …  
    4850                || $has_text_decoration_support
    4951                || $has_text_transform_support
     52                || $has_text_indent_support
    5053                || $has_writing_mode_support;
    5154
    … …  
    8184 * @since 6.1.0 Used the style engine to generate CSS and classnames.
    8285 * @since 6.3.0 Added support for text-columns.
     86 * @since 7.0.0 Added support for text-indent.
    8387 * @access private
    8488 *
    … …  
    111115        $has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
    112116        $has_text_transform_support  = $typography_supports['__experimentalTextTransform'] ?? false;
     117        $has_text_indent_support     = $typography_supports['textIndent'] ?? false;
    113118        $has_writing_mode_support    = $typography_supports['__experimentalWritingMode'] ?? false;
    114119
    … …  
    124129        $should_skip_text_transform  = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' );
    125130        $should_skip_letter_spacing  = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' );
     131        $should_skip_text_indent     = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textIndent' );
    126132        $should_skip_writing_mode    = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'writingMode' );
    127133
    … …  
    221227        ) {
    222228                $typography_block_styles['writingMode'] = $block_attributes['style']['typography']['writingMode'] ?? null;
     229        }
     230
     231        if ( $has_text_indent_support && ! $should_skip_text_indent && isset( $block_attributes['style']['typography']['textIndent'] ) ) {
     232                $typography_block_styles['textIndent'] = $block_attributes['style']['typography']['textIndent'] ?? null;
    223233        }
    224234
  • trunk/src/wp-includes/class-wp-theme-json.php

    r61631 r61632  
    248248         * @since 6.7.0 Added `background-attachment` property.
    249249         * @since 7.0.0 Added `dimensions.width` and `dimensions.height`.
     250         *              Added `text-indent` property.
    250251         * @var array
    251252         */
    … …  
    310311                'text-decoration'                   => array( 'typography', 'textDecoration' ),
    311312                'text-transform'                    => array( 'typography', 'textTransform' ),
     313                'text-indent'                       => array( 'typography', 'textIndent' ),
    312314                'filter'                            => array( 'filter', 'duotone' ),
    313315                'box-shadow'                        => array( 'shadow' ),
    … …  
    410412         * @since 7.0.0 Added type markers to the schema for boolean values.
    411413         *              Added support for `dimensions.width` and `dimensions.height`.
     414         *              Added support for `typography.textIndent`.
    412415         * @var array
    413416         */
    … …  
    495498                        'textColumns'      => null,
    496499                        'textDecoration'   => null,
     500                        'textIndent'       => null,
    497501                        'textTransform'    => null,
    498502                        'writingMode'      => null,
    … …  
    602606                        'textColumns'    => null,
    603607                        'textDecoration' => null,
     608                        'textIndent'     => null,
    604609                        'textTransform'  => null,
    605610                        'writingMode'    => null,
    … …  
    27512756
    27522757        /**
     2758         * Updates the text indent selector for paragraph blocks based on the textIndent setting.
     2759         *
     2760         * The textIndent setting can be 'subsequent' (default), 'all', or false.
     2761         * When set to 'all', the selector should be '.wp-block-paragraph' instead of
     2762         * '.wp-block-paragraph + .wp-block-paragraph' to apply indent to all paragraphs.
     2763         *
     2764         * @since 7.0.0
     2765         *
     2766         * @param array  $feature_declarations The feature declarations keyed by selector.
     2767         * @param array  $settings             The theme.json settings.
     2768         * @param string $block_name           The block name being processed.
     2769         * @return array The updated feature declarations.
     2770         */
     2771        private static function update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name ) {
     2772                if ( 'core/paragraph' !== $block_name ) {
     2773                        return $feature_declarations;
     2774                }
     2775
     2776                // Check block-level settings first, then fall back to global settings.
     2777                $block_settings      = $settings['blocks']['core/paragraph'] ?? null;
     2778                $text_indent_setting = $block_settings['typography']['textIndent']
     2779                        ?? $settings['typography']['textIndent']
     2780                        ?? 'subsequent';
     2781
     2782                if ( 'all' !== $text_indent_setting ) {
     2783                        return $feature_declarations;
     2784                }
     2785
     2786                // Look for the text indent selector and replace it.
     2787                $old_selector = '.wp-block-paragraph + .wp-block-paragraph';
     2788                $new_selector = '.wp-block-paragraph';
     2789
     2790                if ( isset( $feature_declarations[ $old_selector ] ) ) {
     2791                        $declarations = $feature_declarations[ $old_selector ];
     2792                        unset( $feature_declarations[ $old_selector ] );
     2793                        $feature_declarations[ $new_selector ] = $declarations;
     2794                }
     2795
     2796                return $feature_declarations;
     2797        }
     2798
     2799        /**
    27532800         * An internal method to get the block nodes from a theme.json file.
    27542801         *
    … …  
    29112958                $is_root_selector     = static::ROOT_BLOCK_SELECTOR === $selector;
    29122959
     2960                // Update text indent selector for paragraph blocks based on the textIndent setting.
     2961                $block_name           = $block_metadata['name'] ?? null;
     2962                $feature_declarations = static::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name );
     2963
    29132964                // If there are style variations, generate the declarations for them, including any feature selectors the block may have.
    29142965                $style_variation_declarations    = array();
    … …  
    29222973                                // Generate any feature/subfeature style declarations for the current style variation.
    29232974                                $variation_declarations = static::get_feature_declarations_for_node( $block_metadata, $style_variation_node );
     2975
     2976                                // Update text indent selector for paragraph blocks based on the textIndent setting.
     2977                                $variation_declarations = static::update_paragraph_text_indent_selector( $variation_declarations, $settings, $block_name );
    29242978
    29252979                                // Combine selectors with style variation's selector and add to overall style variation declarations.
  • trunk/src/wp-includes/style-engine/class-wp-style-engine.php

    r61631 r61632  
    2727 *              background.backgroundRepeat and dimensions.aspectRatio.
    2828 * @since 6.7.0 Added support for typography.writingMode.
     29 * @since 7.0.0 Added support for typography.textIndent.
    2930 */
    3031#[AllowDynamicProperties]
    … …  
    315316                                ),
    316317                                'path'          => array( 'typography', 'textDecoration' ),
     318                        ),
     319                        'textIndent'     => array(
     320                                'property_keys' => array(
     321                                        'default' => 'text-indent',
     322                                ),
     323                                'path'          => array( 'typography', 'textIndent' ),
    317324                        ),
    318325                        'textTransform'  => array(
  • trunk/tests/phpunit/tests/theme/wpThemeJson.php

    r61631 r61632  
    580580                                                        'typography' => array(
    581581                                                                'textColumns' => 2,
     582                                                                'textIndent'  => '2em',
    582583                                                        ),
    583584                                                ),
    … …  
    608609
    609610                $variables = ':root{--wp--preset--color--grey: grey;--wp--preset--gradient--custom-gradient: linear-gradient(135deg,rgba(0,0,0) 0%,rgb(0,0,0) 100%);--wp--preset--font-size--small: 14px;--wp--preset--font-size--big: 41px;--wp--preset--font-family--arial: Arial, serif;--wp--preset--border-radius--small: 2px;--wp--preset--border-radius--medium: 4px;--wp--preset--dimension--small: 100px;--wp--preset--dimension--large: 200px;}.wp-block-group{--wp--custom--base-font: 16;--wp--custom--line-height--small: 1.2;--wp--custom--line-height--medium: 1.4;--wp--custom--line-height--large: 1.8;}';
    610                 $styles    = ':where(body) { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}.is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}.is-layout-flex{flex-wrap: wrap;align-items: center;}.is-layout-flex > :is(*, div){margin: 0;}body .is-layout-grid{display: grid;}.is-layout-grid > :is(*, div){margin: 0;}body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}:root :where(.wp-element-button, .wp-block-button__link){box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.66);}:root :where(.wp-block-cover){min-height: unset;aspect-ratio: 16/9;border-radius: var(--wp--preset--border-radius--small);}:root :where(.wp-block-group){background: var(--wp--preset--gradient--custom-gradient);border-radius: 10px;min-height: 50vh;padding: 24px;height: 500px;width: var(--wp--preset--dimension--large);}:root :where(.wp-block-group a:where(:not(.wp-element-button))){color: #111;}:root :where(.wp-block-heading){color: #123456;}:root :where(.wp-block-heading a:where(:not(.wp-element-button))){background-color: #333;color: #111;font-size: 60px;}:root :where(.wp-block-media-text){text-align: center;}:root :where(.wp-block-post-date){color: #123456;}:root :where(.wp-block-post-date a:where(:not(.wp-element-button))){background-color: #777;color: #555;}:root :where(.wp-block-post-excerpt){column-count: 2;}:root :where(.wp-block-image){margin-bottom: 30px;}:root :where(.wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder){border-top-left-radius: 10px;border-bottom-right-radius: 1em;}:root :where(.wp-block-image img, .wp-block-image .components-placeholder){filter: var(--wp--preset--duotone--custom-duotone);}';
     611                $styles    = ':where(body) { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}.is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}.is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}.is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}.is-layout-flex{flex-wrap: wrap;align-items: center;}.is-layout-flex > :is(*, div){margin: 0;}body .is-layout-grid{display: grid;}.is-layout-grid > :is(*, div){margin: 0;}body{color: var(--wp--preset--color--grey);}a:where(:not(.wp-element-button)){background-color: #333;color: #111;}:root :where(.wp-element-button, .wp-block-button__link){box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.66);}:root :where(.wp-block-cover){min-height: unset;aspect-ratio: 16/9;border-radius: var(--wp--preset--border-radius--small);}:root :where(.wp-block-group){background: var(--wp--preset--gradient--custom-gradient);border-radius: 10px;min-height: 50vh;padding: 24px;height: 500px;width: var(--wp--preset--dimension--large);}:root :where(.wp-block-group a:where(:not(.wp-element-button))){color: #111;}:root :where(.wp-block-heading){color: #123456;}:root :where(.wp-block-heading a:where(:not(.wp-element-button))){background-color: #333;color: #111;font-size: 60px;}:root :where(.wp-block-media-text){text-align: center;}:root :where(.wp-block-post-date){color: #123456;}:root :where(.wp-block-post-date a:where(:not(.wp-element-button))){background-color: #777;color: #555;}:root :where(.wp-block-post-excerpt){column-count: 2;text-indent: 2em;}:root :where(.wp-block-image){margin-bottom: 30px;}:root :where(.wp-block-image img, .wp-block-image .wp-block-image__crop-area, .wp-block-image .components-placeholder){border-top-left-radius: 10px;border-bottom-right-radius: 1em;}:root :where(.wp-block-image img, .wp-block-image .components-placeholder){filter: var(--wp--preset--duotone--custom-duotone);}';
    611612                $presets   = '.has-grey-color{color: var(--wp--preset--color--grey) !important;}.has-grey-background-color{background-color: var(--wp--preset--color--grey) !important;}.has-grey-border-color{border-color: var(--wp--preset--color--grey) !important;}.has-custom-gradient-gradient-background{background: var(--wp--preset--gradient--custom-gradient) !important;}.has-small-font-size{font-size: var(--wp--preset--font-size--small) !important;}.has-big-font-size{font-size: var(--wp--preset--font-size--big) !important;}.has-arial-font-family{font-family: var(--wp--preset--font-family--arial) !important;}';
    612613                $all       = $variables . $styles . $presets;
Note: See TracChangeset for help on using the changeset viewer.