Skip to content

Commit

Permalink
Don't strip the leading linebreak off blockquotes.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Sep 1, 2017
1 parent 894f823 commit 438cd53
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions Text/Wiki/Parse/Default/Blockquote.php
@@ -1,69 +1,69 @@
<?php

/**
*
*
* Parse for block-quoted text.
*
*
* @category Text
*
*
* @package Text_Wiki
*
*
* @author Paul M. Jones <pmjones@php.net>
*
*
* @license LGPL
*
*
* @version $Id$
*
*
*/

/**
*
*
* Parse for block-quoted text.
*
*
* Find source text marked as a blockquote, identified by any number of
* greater-than signs '>' at the start of the line, followed by a space,
* and then the quote text; each '>' indicates an additional level of
* quoting.
*
*
* @category Text
*
*
* @package Text_Wiki
*
*
* @author Paul M. Jones <pmjones@php.net>
*
*
*/

class Text_Wiki_Parse_Blockquote extends Text_Wiki_Parse {


/**
*
*
* Regex for parsing the source text.
*
*
* @access public
*
*
* @var string
*
*
* @see parse()
*
*
*/

var $regex = '/\n(\>+ .*\n)(?!\>+ )/Us';


/**
*
*
* Generates a replacement for the matched text.
*
*
* Token options are:
*
*
* 'type' =>
* 'start' : the start of a blockquote
* 'end' : the end of a blockquote
*
* 'level' => the indent level (0 for the first level, 1 for the
* second, etc)
*
*
* @access public
*
* @param array &$matches The array of matches from parse().
Expand All @@ -72,15 +72,15 @@ class Text_Wiki_Parse_Blockquote extends Text_Wiki_Parse {
* list text and list elements.
*
*/

function process(&$matches)
{
// the replacement text we will return to parse()
$return = '';
$return = "\n";

// the list of post-processing matches
$list = array();

// $matches[1] is the text matched as a blockquote by parse();
// create an array called $list that contains a new set of
// matches for the various blockquote lines.
Expand All @@ -90,73 +90,73 @@ function process(&$matches)
$list,
PREG_SET_ORDER
);

$curLevel = 0;

// loop through each blockquote line.
foreach ($list as $key => $val) {

// $val[0] is the full matched line
// $val[1] is the number of initial '>' chars (indent level)
// $val[2] is the quote text

// we number levels starting at 1, not zero
$level = strlen($val[1]);

// add a level?
while ($level > $curLevel) {
// the current indent level is greater than the number
// of stack elements, so we must be starting a new
// level.
++$curLevel;

// ...and add a start token to the return.
$return .= $this->wiki->addToken(
$this->rule,
$this->rule,
array(
'type' => 'start',
'level' => $curLevel
)
);
}

// remove a level?
while ($curLevel > $level) {

// as long as the stack count is greater than the
// current indent level, we need to end list types.
// continue adding end-list tokens until the stack count
// and the indent level are the same.

$return .= $this->wiki->addToken(
$this->rule,
$this->rule,
array (
'type' => 'end',
'level' => $curLevel
)
);

--$curLevel;
}

// add the line text.
$return .= $val[2];
}

// close the pending levels
while ($curLevel > 0) {
$return .= $this->wiki->addToken(
$this->rule,
$this->rule,
array (
'type' => 'end',
'level' => $curLevel
)
);
--$curLevel;
}

// we're done! send back the replacement text.
return $return;
}
}
?>
?>

0 comments on commit 438cd53

Please sign in to comment.