r52983 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52982‎ | r52983 | r52984 >
Date:15:17, 9 July 2009
Author:werdna
Status:reverted (Comments)
Tags:
Comment:
* Allow leading-> as syntax for quoting.
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/maintenance/parserTests.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.txt
@@ -6550,9 +6550,9 @@
65516551 !! test
65526552 Always escape literal '>' in output, not just after '<'
65536553 !! input
6554 -><>
 6554+test ><>
65556555 !! result
6556 -<p>&gt;&lt;&gt;
 6556+<p>test &gt;&lt;&gt;
65576557 </p>
65586558 !! end
65596559
@@ -7320,6 +7320,24 @@
73217321 </p>
73227322 !! end
73237323
 7324+!! test
 7325+Leading > blockquote syntax
 7326+!! input
 7327+> Hi
 7328+> This
 7329+> Is
 7330+> A
 7331+> Quote
 7332+!! result
 7333+<blockquote><p> Hi
 7334+</p><p> This
 7335+</p><p> Is
 7336+</p><p> A
 7337+</p><p> Quote
 7338+</p></blockquote>
 7339+
 7340+!! end
 7341+
73247342 #
73257343 #
73267344 #
Index: trunk/phase3/includes/parser/Parser.php
@@ -1947,7 +1947,7 @@
19481948 elseif ( ';' === $char ) {
19491949 $result .= '<dl><dt>';
19501950 $this->mDTopen = true;
1951 - }
 1951+ } elseif ( '>' === $char ) { $result .= "<blockquote><p>"; }
19521952 else { $result = '<!-- ERR 1 -->'; }
19531953
19541954 return $result;
@@ -1955,6 +1955,7 @@
19561956
19571957 /* private */ function nextItem( $char ) {
19581958 if ( '*' === $char || '#' === $char ) { return '</li><li>'; }
 1959+ elseif ( '>' === $char ) { return "</p><p>"; }
19591960 elseif ( ':' === $char || ';' === $char ) {
19601961 $close = '</dd>';
19611962 if ( $this->mDTopen ) { $close = '</dt>'; }
@@ -1972,6 +1973,7 @@
19731974 /* private */ function closeList( $char ) {
19741975 if ( '*' === $char ) { $text = '</li></ul>'; }
19751976 elseif ( '#' === $char ) { $text = '</li></ol>'; }
 1977+ elseif ( '>' === $char ) { $text = "</p></blockquote>"; }
19761978 elseif ( ':' === $char ) {
19771979 if ( $this->mDTopen ) {
19781980 $this->mDTopen = false;
@@ -2017,14 +2019,23 @@
20182020 // # = ol
20192021 // ; = dt
20202022 // : = dd
 2023+ // > = blockquote
20212024
20222025 $lastPrefixLength = strlen( $lastPrefix );
20232026 $preCloseMatch = preg_match('/<\\/pre/i', $oLine );
20242027 $preOpenMatch = preg_match('/<pre/i', $oLine );
 2028+
 2029+ // Need to decode &gt; --> > for blockquote syntax. Re-encode later.
 2030+ // To avoid collision with real >s, we temporarily convert them to &gt;
 2031+ // This is a weird choice of armouring, but it's totally resistant to any
 2032+ // collision.
 2033+ $orig = $oLine;
 2034+ $oLine = strtr( $oLine, array( '&gt;' => '>', '>' => '&gt;' ) );
 2035+
20252036 // If not in a <pre> element, scan for and figure out what prefixes are there.
20262037 if ( !$this->mInPre ) {
20272038 # Multiple prefixes may abut each other for nested lists.
2028 - $prefixLength = strspn( $oLine, '*#:;' );
 2039+ $prefixLength = strspn( $oLine, '*#:;>' );
20292040 $prefix = substr( $oLine, 0, $prefixLength );
20302041
20312042 # eh?
@@ -2040,6 +2051,9 @@
20412052 $prefix = $prefix2 = '';
20422053 $t = $oLine;
20432054 }
 2055+
 2056+ // Re-encode >s now
 2057+ $t = strtr( $t, array( '&gt;' => '>', '>' => '&gt;' ) );
20442058
20452059 # List generation
20462060 if( $prefixLength && $lastPrefix === $prefix2 ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r52984Release notes updates for r52983werdna15:19, 9 July 2009
r55635Revert r52983 for now, could cause unexpected syntax interactions, we want to...werdna17:16, 27 August 2009

Comments

#Comment by UV (talk | contribs)   20:47, 9 July 2009

I would like to suggest to assign a class to the blockquote tag thus produced, so that quotes can be styled more easily (both per-site and per-user).

#Comment by Brion VIBBER (talk | contribs)   18:55, 22 August 2009

This doesn't seem to work as expected with whitespace...

For instance this:

># we had a list
># with a couple items

has a functioning list while this:

> # we had a list
> # with a couple items

emits literal # characters.

#Comment by Werdna (talk | contribs)   17:17, 27 August 2009

Reverted for now in r55635, to avoid annoying syntax interactions.

Status & tagging log