Make WordPress Core

Opened 12 years ago

Last modified 2 years ago

#13340 reopened enhancement

wpautop breaks inline MathML

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


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 12 years ago.

Download all attachments as: .zip

Change History (19)

#1 @nicholaswilson
12 years ago

  • Cc nicholas@… added

#2 @wojtek.szkutnik
12 years ago

  • Keywords has-patch added

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

#3 @wojtek.szkutnik
12 years ago

  • Cc wojtek.szkutnik@… added

#4 @wojtek.szkutnik
12 years ago

  • Keywords gsoc added

#5 @hakre
12 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
11 years ago

  • Milestone changed from Awaiting Review to 3.1

This looks straightforward.

#7 @nacin
11 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
10 years ago

  • Keywords wpautop added

#9 @chriscct7
7 years ago

  • Keywords 3.2-early gsoc removed

Can anyone confirm this works per @nacin?

#10 @ericlewis
7 years ago

Can anyone offer boilerplate to reproduce the issue here?

#11 @ericlewis
7 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
6 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
6 years ago

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

#14 @hughie.molloy
5 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
3 years 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 );

#17 @SteelWagstaff
2 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Summary changed from wpautop breaks inline MathMl to wpautop breaks inline MathML

Hi all,

While it’s true that browser support for MathML is incomplete, MathML has been a W3C recommendation for more than 15 years, the 3rd version (released in 2014) is an ISO standard, and it has been a standard element in the HTML5 specification since 2014 (references: https://www.w3.org/TR/MathML/ + https://www.w3.org/2015/06/mathmlpas.html.en + https://www.w3.org/TR/html52/semantics-embedded-content.html#mathml). Furthermore, there’s a widely-used, openly-licensed, cross-platform JavaScript display engine for mathematics called MathJax that works in all browsers that can accept MathML as one of its input syntaxes (https://www.mathjax.org/). There are clear reasons, based both in our desire to use web standards and to make more accessible websites, that many of us would like to use MathML in our WordPress-based sites. Would you be willing to reconsider your decision not to treat <math> as a "first-class citizen of wpautop()", or failing that, allow us to filter the strings proposed a few months ago by @conner_bw?

This ticket was mentioned in Slack in #core by steelwagstaff. View the logs.

2 years ago

Note: See TracTickets for help on using tickets.