Make WordPress Core

Opened 10 years ago

Closed 4 years ago

Last modified 5 months ago

#13340 closed enhancement (wontfix)

wpautop breaks inline MathMl

Reported by: nicholaswilson Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.9.2
Component: Formatting Keywords:
Focuses: Cc:
PR Number:


wpautop treats inline <math> tags as block; they in fact may be placed block or inline, with their flow model dependent on the mode or CSS display property.

Trivial to fix; just needs someone to commit the change. Remove "|math" from $allblocks in file wp-includes/formatting.php. math tags on their own will be wrapped in a paragraph, which is fine.

As a very convenient enhancement, please replace on line 210:

     if ($br) {
-        $pee = preg_replace_callback('/<(script|style). ....
+        $pee = preg_replace_callback('/<(script|style|math) ...

to prevent MathML being polluted with breaks (current required workaround people are using is to have the whole block on one line, which is very messy to edit).

Attachments (1)

13340.diff (1.8 KB) - added by wojtek.szkutnik 10 years ago.

Download all attachments as: .zip

Change History (17)

#1 @nicholaswilson
10 years ago

  • Cc nicholas@… added

#2 @wojtek.szkutnik
10 years ago

  • Keywords has-patch added

Adding the patch. All looks pretty straightforward to me, shouldn't break anything.

#3 @wojtek.szkutnik
10 years ago

  • Cc wojtek.szkutnik@… added

#4 @wojtek.szkutnik
10 years ago

  • Keywords gsoc added

#5 @hakre
10 years ago

  • Keywords needs-testing needs-unit-tests added

wpautop() related/informative tickets:

Related: #1706
Related: #2833
Related: #3007
Related: #3833
Related: #4857
Related: #4298
Related: #5250
Related: #6984
Related: #7988
Related: #9437
Related: #10033
Related: #10490
Related: #11678
Related: #12061
Related: #13327

Informative: #7937
Informative: #9744

AutoP tickets get only fixed in very specific situations. In any case they need extensive testing because of backward compabilities and side-effects and therefore normally Unit-Tests.

#6 @nacin
9 years ago

  • Milestone changed from Awaiting Review to 3.1

This looks straightforward.

#7 @nacin
9 years ago

  • Keywords 3.2-early added
  • Milestone changed from 3.1 to Future Release
  • Type changed from defect (bug) to enhancement

Not knowing anything about MatML, I want confirmation before doing anything like this.

enhancements can go to 3.2.

#8 @WraithKenny
8 years ago

  • Keywords wpautop added

#9 @chriscct7
5 years ago

  • Keywords 3.2-early gsoc removed

Can anyone confirm this works per @nacin?

#10 @ericlewis
5 years ago

Can anyone offer boilerplate to reproduce the issue here?

#11 @ericlewis
5 years ago

<math> is a separate markup language which is a subset of XML. It is not supported by modern browsers. It would be odd to support this as a first-class citizen of wpautop().

#12 @ericlewis
4 years ago

  • Keywords has-patch needs-testing needs-unit-tests wpautop removed
  • Milestone Future Release deleted

Closing this out as per my previous comments, feel free to reopen with follow-up if the feature is justified.

#13 @ericlewis
4 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

#14 @hughie.molloy
3 years ago

<math> tag has been a support element in HTML5 since 2011. https://www.w3.org/wiki/HTML/Elements/math
Please consider reopening this as it makes a huge difference to inline formatting.



Plain Text:
<h3>Quantum quandary</h3>At first sight, magnetic monopoles seem to be incompatible with quantum mechanics. That is because in quantum mechanics, electromagnetic fields have to be described in terms of a scalar potential <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>ϕ</mi></math> and vector potential <math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="bold">A</mi></math>. The magnetic field is given by the curl of the vector potential, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="bold">B</mi><mo>=</mo><mi mathvariant="bold">∇</mi><mo>×</mo><mi mathvariant="bold">A</mi></math>, and it follows from elementary vector calculus that the field must then be sourceless, <math xmlns="http://www.w3.org/1998/Math/MathML"><mi mathvariant="bold">∇</mi><mo>.</mo><mi mathvariant="bold">B</mi><mo>=</mo><mn>0</mn></math>. In other words, magnetic field lines cannot end. So how can there be magnetic monopoles?

#15 @conner_bw
6 months ago

Chiming in with a me too.

If I apply this patch it fixes the issue:


For obvious reasons, I won't patch wp-includes/formatting.php, WordPress must do it...

Or, let us filter those strings? Example:

$allblocks = apply_filters( 'autop_allblocks', 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary' );
$allblocks = '(?:' . $allblocks . ')';

// ... snip ...

// Replace newlines that shouldn't be touched with a placeholder.
$newline_preservation_helper = apply_filters( 'autop_newline_preservation_helper', 'script|style' );
$pee = preg_replace_callback( '/<(' . $newline_preservation_helper . ').*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee );
Note: See TracTickets for help on using tickets.