Make WordPress Core


Ignore:
Timestamp:
02/07/2023 04:16:47 PM (2 years ago)
Author:
joedolson
Message:

Formatting: Treat math elements as block-level elements.

The math element can be displayed either as a block or inline element. If wpautop only treats it as an inline element, it will break multiline elements by inserting br elements. Treating the element as a block element means that the editor won't break common normative usages of the math element.

Prevent math elements from having internal elements split up with br elements, disrupting formatting.

Props nicholaswilson, wojtek.szkutnik, hakre, conner_bw, ericlewis, hughie.molloy, SteelWagstaff, ryokuhi, joedolson, bgoewert, adamsilverstein, joedolson.
Fixes #13340.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/wpAutop.php

    r53687 r55272  
    106106
    107107    /**
     108     * wpautop() Should add <p> around inline "<math>" elements.
     109     *
     110     * @ticket 13340
     111     */
     112    public function test_wrap_inline_math_elements() {
     113        $str = '<math><mrow><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup><mo>=</mo><msup><mi>c</mi><mn>2</mn></msup></mrow></math>';
     114
     115        $this->assertSame( "<p>$str</p>", trim( wpautop( $str ) ) );
     116    }
     117
     118    /**
     119     * wpautop() Should not add <br> inside block "<math>" elements.
     120     *
     121     * @ticket 13340
     122     */
     123    public function test_skip_block_math_elements() {
     124        $str = '<math display="block">
     125    <mtable>
     126        <mtr>
     127            <mtd>
     128                <msup><mrow><mo>(</mo><mi>a</mi><mo>+</mo><mi>b</mi><mo>)</mo></mrow><mn>2</mn></msup>
     129            </mtd>
     130            <mtd>
     131                <mo>=</mo>
     132            </mtd>
     133            <mtd>
     134                <msup><mi>c</mi><mn>2</mn></msup>
     135                <mo>+</mo><mn>4</mn><mo>⋅</mo>
     136                <mo>(</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mi>a</mi><mi>b</mi><mo>)</mo>
     137            </mtd>
     138        </mtr>
     139        <mtr>
     140            <mtd>
     141                <msup><mi>a</mi><mn>2</mn></msup>
     142                <mo>+</mo><mn>2</mn><mi>a</mi><mi>b</mi><mo>+</mo>
     143                <msup><mi>b</mi><mn>2</mn></msup>
     144            </mtd>
     145            <mtd>
     146                <mo>=</mo>
     147            </mtd>
     148            <mtd>
     149                <msup><mi>c</mi><mn>2</mn></msup>
     150                <mo>+</mo><mn>2</mn><mi>a</mi><mi>b</mi>
     151            </mtd>
     152        </mtr>
     153        <mtr>
     154            <mtd><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup></mtd>
     155            <mtd><mo>=</mo></mtd>
     156            <mtd><msup><mi>c</mi><mn>2</mn></msup></mtd>
     157        </mtr>
     158    </mtable>
     159</math>';
     160
     161        $this->assertSame( "<p>$str</p>", trim( wpautop( $str ) ) );
     162    }
     163
     164    /**
    108165     * wpautop() Should not add <p> and <br/> around <source> and <track>
    109166     *
     
    309366            'area',
    310367            'address',
    311             'math',
    312368            'style',
    313369            'p',
Note: See TracChangeset for help on using the changeset viewer.