Skip to content

Commit a943d0d

Browse files
committed
Fix API output formatting (change lines delimited with * as bold)
Problem: on API documentation pages, lines delimited with asterisks are automatically converted to bold. However, some lines aren't, such as the one with the url in the main header of the root API page: https://en.wikipedia.org/w/api.php Not only this is breaks the standard formatting for module headers, etc, but if the font used by the browser for monospaced text doesn't preserve character width between bold and regular weight (which it should), any layout structures will break. Example: http://i.imgur.com/PVh6i.png The regex that applies bold to the lines starting and ending in * doesn't accept < and > inside the string, but these are added by the url-formatting regex. Simply changing the order of these operations fixes the issue. Note: this change also removes the regex applying italics to lines in the $ ... $ form, as suggested by Anomie and Yurik in code review comments. Change-Id: I7173f812bebb8a722fefdaa6cce9fcd554c82c84
1 parent 5db75ef commit a943d0d

File tree

Image for: File tree

1 file changed

Image for: 1 file changed
+5
-8
lines changed

1 file changed

Image for: 1 file changed
+5
-8
lines changed

‎includes/api/ApiFormatBase.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function setBufferResult( $value ) {
248248
}
249249

250250
/**
251-
* Sets whether the pretty-printer should format *bold* and $italics$
251+
* Sets whether the pretty-printer should format *bold*
252252
* @param $help bool
253253
*/
254254
public function setHelp( $help = true ) {
@@ -264,22 +264,19 @@ public function setHelp( $help = true ) {
264264
protected function formatHTML( $text ) {
265265
// Escape everything first for full coverage
266266
$text = htmlspecialchars( $text );
267-
268267
// encode all comments or tags as safe blue strings
269268
$text = str_replace( '&lt;', '<span style="color:blue;">&lt;', $text );
270269
$text = str_replace( '&gt;', '&gt;</span>', $text );
271-
// identify URLs
272-
$protos = wfUrlProtocolsWithoutProtRel();
273-
// This regex hacks around bug 13218 (&quot; included in the URL)
274-
$text = preg_replace( "#(((?i)$protos).*?)(&quot;)?([ \\'\"<>\n]|&lt;|&gt;|&quot;)#", '<a href="\\1">\\1</a>\\3\\4', $text );
275270
// identify requests to api.php
276271
$text = preg_replace( "#api\\.php\\?[^ <\n\t]+#", '<a href="\\0">\\0</a>', $text );
277272
if ( $this->mHelp ) {
278273
// make strings inside * bold
279274
$text = preg_replace( "#\\*[^<>\n]+\\*#", '<b>\\0</b>', $text );
280-
// make strings inside $ italic
281-
$text = preg_replace( "#\\$[^<>\n]+\\$#", '<b><i>\\0</i></b>', $text );
282275
}
276+
// identify URLs
277+
$protos = wfUrlProtocolsWithoutProtRel();
278+
// This regex hacks around bug 13218 (&quot; included in the URL)
279+
$text = preg_replace( "#(((?i)$protos).*?)(&quot;)?([ \\'\"<>\n]|&lt;|&gt;|&quot;)#", '<a href="\\1">\\1</a>\\3\\4', $text );
283280

284281
/**
285282
* Temporary fix for bad links in help messages. As a special case,

0 commit comments

Image for: 0 commit comments
Comments
 (0)