Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1306
wtm-bug487-comments.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Authored By
•
bzimport
Nov 21 2014, 6:56 PM
2014-11-21 18:56:17 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
wtm-bug487-comments.patch
View Options
Index: Parser.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/Parser.php,v
retrieving revision 1.269
diff -u -r1.269 Parser.php
--- Parser.php 15 Sep 2004 05:53:21 -0000 1.269
+++ Parser.php 16 Sep 2004 03:24:31 -0000
@@ -1784,7 +1784,7 @@
$htmlattrs = $this->getHTMLattrs () ;
# Remove HTML comments
- $text = preg_replace( '/(\\n *<!--.*--> *|<!--.*?-->)/sU', '', $text );
+ $text = $this->removeHTMLcomments( $text );
$bits = explode( '<', $text );
$text = array_shift( $bits );
@@ -1863,6 +1863,42 @@
return $text;
}
+ # Remove '<!--', '-->', and everything between.
+ # To avoid leaving blank lines, when a comment is both preceded
+ # and followed by a newline (ignoring spaces), trim leading and
+ # trailing spaces and one of the newlines.
+ /* private */ function removeHTMLcomments( $text ) {
+ while (($start = strpos($text, '<!--')) !== false) {
+ $end = strpos($text, '-->', $start + 4);
+ if ($end === false) {
+ # Unterminated comment; bail out
+ break;
+ }
+
+ $end += 3;
+
+ # Trim space and newline if the comment is both
+ # preceded and followed by a newline
+ $spaceStart = $start - 1;
+ $spaceLen = $end - $spaceStart;
+ while (substr($text, $spaceStart, 1) === ' ') {
+ $spaceStart--;
+ $spaceLen++;
+ }
+ while (substr($text, $spaceStart + $spaceLen, 1) === ' ')
+ $spaceLen++;
+ if (substr($text, $spaceStart, 1) === "\n" and substr($text, $spaceStart + $spaceLen, 1) === "\n") {
+ # Remove the comment, leading and trailing
+ # spaces, and leave only one newline.
+ $text = substr_replace($text, "\n", $spaceStart, $spaceLen + 1);
+ }
+ else {
+ # Remove just the comment.
+ $text = substr_replace($text, '', $start, $end - $start);
+ }
+ }
+ return $text;
+ }
# This function accomplishes several tasks:
# 1) Auto-number headings if that option is enabled
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1205
Default Alt Text
wtm-bug487-comments.patch (1 KB)
Attached To
Mode
T2487: HTML comments cause invisible text in tables
Attached
Detach File
Event Timeline
Log In to Comment