Skip to content

Commit 5f060c3

Browse files
Typography: Add text indent support
1 parent d676a07 commit 5f060c3

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

src/wp-includes/block-supports/typography.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function wp_register_typography_support( $block_type ) {
3434
$has_text_align_support = isset( $typography_supports['textAlign'] ) ? $typography_supports['textAlign'] : false;
3535
$has_text_columns_support = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
3636
$has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
37+
$has_text_indent_support = isset( $typography_supports['textIndent'] ) ? $typography_supports['textIndent'] : false;
3738
$has_text_transform_support = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
3839
$has_writing_mode_support = isset( $typography_supports['__experimentalWritingMode'] ) ? $typography_supports['__experimentalWritingMode'] : false;
3940

@@ -46,6 +47,7 @@ function wp_register_typography_support( $block_type ) {
4647
|| $has_text_align_support
4748
|| $has_text_columns_support
4849
|| $has_text_decoration_support
50+
|| $has_text_indent_support
4951
|| $has_text_transform_support
5052
|| $has_writing_mode_support;
5153

@@ -111,6 +113,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
111113
$has_text_align_support = isset( $typography_supports['textAlign'] ) ? $typography_supports['textAlign'] : false;
112114
$has_text_columns_support = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
113115
$has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
116+
$has_text_indent_support = isset( $typography_supports['textIndent'] ) ? $typography_supports['textIndent'] : false;
114117
$has_text_transform_support = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
115118
$has_writing_mode_support = isset( $typography_supports['__experimentalWritingMode'] ) ? $typography_supports['__experimentalWritingMode'] : false;
116119

@@ -123,6 +126,7 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
123126
$should_skip_text_align = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textAlign' );
124127
$should_skip_text_columns = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textColumns' );
125128
$should_skip_text_decoration = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' );
129+
$should_skip_text_indent = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textIndent' );
126130
$should_skip_text_transform = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' );
127131
$should_skip_letter_spacing = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' );
128132
$should_skip_writing_mode = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'writingMode' );
@@ -203,6 +207,17 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
203207
);
204208
}
205209

210+
if (
211+
$has_text_indent_support &&
212+
! $should_skip_text_indent &&
213+
isset( $block_attributes['style']['typography']['textIndent'] )
214+
) {
215+
$typography_block_styles['textIndent'] = wp_typography_get_preset_inline_style_value(
216+
$block_attributes['style']['typography']['textIndent'],
217+
'text-indent'
218+
);
219+
}
220+
206221
if (
207222
$has_text_transform_support &&
208223
! $should_skip_text_transform &&

src/wp-includes/class-wp-theme-json.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class WP_Theme_JSON {
237237
* @since 6.5.0 Added `aspect-ratio` property.
238238
* @since 6.6.0 Added `background-[image|position|repeat|size]` properties.
239239
* @since 6.7.0 Added `background-attachment` property.
240+
* @since 7.0.0 Added `text-indent` property.
240241
* @var array
241242
*/
242243
const PROPERTIES_METADATA = array(
@@ -298,6 +299,7 @@ class WP_Theme_JSON {
298299
'--wp--style--root--padding-bottom' => array( 'spacing', 'padding', 'bottom' ),
299300
'--wp--style--root--padding-left' => array( 'spacing', 'padding', 'left' ),
300301
'text-decoration' => array( 'typography', 'textDecoration' ),
302+
'text-indent' => array( 'typography', 'textIndent' ),
301303
'text-transform' => array( 'typography', 'textTransform' ),
302304
'filter' => array( 'filter', 'duotone' ),
303305
'box-shadow' => array( 'shadow' ),
@@ -395,6 +397,7 @@ class WP_Theme_JSON {
395397
* @since 6.6.0 Added support for 'dimensions.aspectRatios', 'dimensions.defaultAspectRatios',
396398
* 'typography.defaultFontSizes', and 'spacing.defaultSpacingSizes'.
397399
* @since 6.9.0 Added support for `border.radiusSizes`.
400+
* @since 7.0.0 Added support for `typography.text-indent`.
398401
* @var array
399402
*/
400403
const VALID_SETTINGS = array(
@@ -477,6 +480,7 @@ class WP_Theme_JSON {
477480
'textAlign' => null,
478481
'textColumns' => null,
479482
'textDecoration' => null,
483+
'textIndent' => null,
480484
'textTransform' => null,
481485
'writingMode' => null,
482486
),
@@ -527,6 +531,7 @@ class WP_Theme_JSON {
527531
* @since 6.3.0 Added support for `typography.textColumns`.
528532
* @since 6.5.0 Added support for `dimensions.aspectRatio`.
529533
* @since 6.6.0 Added `background` sub properties to top-level only.
534+
* @since 7.0.0 Added support for `typography.textIndent`.
530535
* @var array
531536
*/
532537
const VALID_STYLES = array(
@@ -581,6 +586,7 @@ class WP_Theme_JSON {
581586
'textAlign' => null,
582587
'textColumns' => null,
583588
'textDecoration' => null,
589+
'textIndent' => null,
584590
'textTransform' => null,
585591
'writingMode' => null,
586592
),
@@ -630,6 +636,7 @@ class WP_Theme_JSON {
630636
// The block classes are necessary to target older content that won't use the new class names.
631637
'caption' => '.wp-element-caption, .wp-block-audio figcaption, .wp-block-embed figcaption, .wp-block-gallery figcaption, .wp-block-image figcaption, .wp-block-table figcaption, .wp-block-video figcaption',
632638
'cite' => 'cite',
639+
'text' => 'p',
633640
'textInput' => 'textarea, input:where([type=email],[type=number],[type=password],[type=search],[type=text],[type=tel],[type=url])',
634641
'select' => 'select',
635642
);
@@ -2998,6 +3005,24 @@ static function ( $pseudo_selector ) use ( $selector ) {
29983005
$declarations = static::update_separator_declarations( $declarations );
29993006
}
30003007

3008+
// Handle text-indent for paragraph blocks and text element: extract it and generate p + p selector.
3009+
$text_indent_declarations = array();
3010+
$is_processing_element = in_array( 'elements', $block_metadata['path'], true );
3011+
$current_element = $is_processing_element ? $block_metadata['path'][ count( $block_metadata['path'] ) - 1 ] : null;
3012+
$should_use_p_plus_p = ( ! empty( $block_metadata['name'] ) && 'core/paragraph' === $block_metadata['name'] ) ||
3013+
( 'text' === $current_element );
3014+
3015+
if ( $should_use_p_plus_p ) {
3016+
foreach ( $declarations as $index => $declaration ) {
3017+
if ( 'text-indent' === $declaration['name'] ) {
3018+
$text_indent_declarations[] = $declaration;
3019+
unset( $declarations[ $index ] );
3020+
}
3021+
}
3022+
// Re-index array after unsetting elements.
3023+
$declarations = array_values( $declarations );
3024+
}
3025+
30013026
/*
30023027
* Root selector (body) styles should not be wrapped in `:root where()` to keep
30033028
* specificity at (0,0,1) and maintain backwards compatibility.
@@ -3026,6 +3051,11 @@ static function ( $pseudo_selector ) use ( $selector ) {
30263051
$block_rules .= static::to_ruleset( $block_metadata['duotone'], $declarations_duotone );
30273052
}
30283053

3054+
// 3a. Generate and append text-indent rules for paragraph blocks using p + p selector.
3055+
if ( ! empty( $text_indent_declarations ) ) {
3056+
$block_rules .= static::to_ruleset( 'p + p', $text_indent_declarations );
3057+
}
3058+
30293059
// 4. Generate Layout block gap styles.
30303060
if (
30313061
! $is_root_selector &&

src/wp-includes/style-engine/class-wp-style-engine.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ final class WP_Style_Engine {
297297
),
298298
'path' => array( 'typography', 'textDecoration' ),
299299
),
300+
'textIndent' => array(
301+
'property_keys' => array(
302+
'default' => 'text-indent',
303+
),
304+
'path' => array( 'typography', 'textIndent' ),
305+
),
300306
'textTransform' => array(
301307
'property_keys' => array(
302308
'default' => 'text-transform',

src/wp-includes/theme.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@
307307
"lineHeight": false,
308308
"textAlign": true,
309309
"textDecoration": true,
310+
"textIndent": true,
310311
"textTransform": true,
311312
"writingMode": false
312313
},

0 commit comments

Comments
 (0)