Page MenuHomePhabricator

Whitespace between syntax of table or heading and percent sign is converted to a non-breaking space (French spaces)
Open, LowPublic

Description

The following wiki code

{| class="wikitable"
|-
| A
| %
|}
== A ==
== % ==

is converted to the following HTML:

<table class="wikitable">
<tbody><tr>
<td>A</td>
<td>&nbsp;%</td>
</tr>
</tbody></table>
<h2> <span id="A" class="mw-headline">A</span></h2>
<h2> <span id=".25" class="mw-headline">&nbsp;%</span></h2>

Expected result:

<table class="wikitable">
<tbody><tr>
<td>A</td>
<td>%</td>
</tr>
</tbody></table>
<h2> <span id="A" class="mw-headline">A</span></h2>
<h2> <span id=".25" class="mw-headline">%</span></h2>

Version: 1.20.x
Severity: normal
URL: https://meta.wikimedia.org/wiki/Help:Newlines_and_spaces#Non-breaking_spaces

Details

Reference
bz38797

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:08 AM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz38797.
bzimport added a subscriber: Unknown Object (MLST).

Work around is to do

%

instead. (yeah i know, not a fix, but is a workable work around. Also replacing the space before the % with an &#32; would probably work, but not tested)

We add a nbsp (note the entity actually output is &#160; not &nbsp; We avoid outputting named entities for compatibility with xml libs when in html5 mode) for things of the form "20 %" which in most langs should be a non-breaking space (Esp. french from my understanding). Bug 18443 comment 7 explains precisely when we do this.

Are these two cases (header and table) the only places, where this automatic replacing is unwanted? In that case, an quick and dirt^Weasy solution would be to replace

'/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1&#160;',

by

'/([^=|!]) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1&#160;',

or equivalently

'/[^=|!]\K (?=[?:;!%]|\\302\\273)/' => '&#160;',

However, bug #18443 would lead to a renewal of those pattern, anyway.

  • Bug 28248 has been marked as a duplicate of this bug. ***

Further wrong converted whitespace:

  • %
  • %

: %
; %

Then one of the following solutions would be better:

'/[^=|!+#:;]\K (?=[?:;!%]|\\302\\273)/' => '&#160;'

or even a separate substitution

'/[^=|!+#:;]\K (?=[?:;!]|\\302\\273)/' => '&#160;'
'/[0-9]\K (?=%)/' => '&#160;'

Of course, there may occur things such as "a %" or "(a+b) %", but I guess, in those (rare) cases tex or a manual '&nbsp;' or '&#160;' should be used instead.

Bug <s>#18443</s>T20443 (meanwhile marked as a duplicate of bug <s>#13619</s>T15619) gives a typographically better solution of the replacement part:

'/[0-9]\K (?=%)/' => '<span style="margin-left:0.167em"><span style="display:none">&nbsp;</span></span>'

Looks horrible, but is a great (and tested) solution, concerning readability of wiki source code and usability.

edit: fixed layout and links of post, after porting to new issue tracker

matmarex renamed this task from Whitespace between syntax of table or heading and percent sign is converted to a non-breaking space to Whitespace between syntax of table or heading and percent sign is converted to a non-breaking space (French spaces).May 14 2015, 5:31 PM
matmarex updated the task description. (Show Details)
matmarex set Security to None.

The problem on headings is fixed. A

%

does not generate a &nbsp; before the % anymore.

  NODES
eth 3