Skip to content

Commit

Permalink
implement automatic line breaks as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
erusev committed Dec 26, 2013
1 parent fd42f2e commit 47d8a13
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ static function instance($name = 'default')

private static $instances = array();

#
# Setters
#

private $break_marker = " \n";

function set_breaks_enabled($breaks_enabled)
{
$this->break_marker = $breaks_enabled ? "\n" : " \n";

return $this;
}

#
# Fields
#
Expand Down Expand Up @@ -658,7 +671,7 @@ private function parse_block_elements(array $lines, $context = '')
'_' => '/^_(.*?)__(.+?)__(.*?)_/s',
);

private function parse_span_elements($text, $markers = array(" \n", '![', '&', '*', '<', '[', '_', '`', 'http', '~~'))
private function parse_span_elements($text, $markers = array('![', '&', '*', '<', '[', '_', '`', 'http', '~~'))
{
if (isset($text[2]) === false or $markers === array())
{
Expand Down Expand Up @@ -717,14 +730,6 @@ private function parse_span_elements($text, $markers = array(" \n", '![', '&',

switch ($closest_marker)
{
case " \n":

$markup .= '<br />';

$offset = 2;

break;

case '![':
case '[':

Expand Down Expand Up @@ -979,6 +984,8 @@ private function parse_span_elements($text, $markers = array(" \n", '![', '&',
$markers[$closest_marker_index] = $closest_marker;
}

$markup = str_replace($this->break_marker, '<br />'."\n", $markup);

return $markup;
}
}

4 comments on commit 47d8a13

@hkdobrev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erusev Nice one! But there are not unit tests for the new method.

@erusev
Copy link
Owner Author

@erusev erusev commented on 47d8a13 Dec 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'm writing a separate test case for configuration options.

@metude
Copy link

@metude metude commented on 47d8a13 Dec 31, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to enable line breaks? Also can I able fully enable Github FM?

@erusev
Copy link
Owner Author

@erusev erusev commented on 47d8a13 Jan 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@metude See the wiki.

Please sign in to comment.