mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
149b687ee7 | |||
98b17e3354 | |||
da966b83f1 | |||
b9ab495cb4 | |||
408cb5c21f | |||
5dd0e8cb7b | |||
5521afde31 | |||
4317add3a2 | |||
47d8a1382b | |||
fd42f2e864 | |||
c0b7155572 | |||
be366b63ea | |||
68484504ca | |||
4fecd91f7d | |||
9dae844a6e | |||
df6fe915c6 | |||
576b0ea761 | |||
0f027dc04b | |||
179862bd6e | |||
019a4af2af | |||
51a08fad85 | |||
7fb08f334a | |||
85ad014f74 | |||
22336a1bcc | |||
f713e380ee | |||
5b01915a63 | |||
18d112a614 | |||
1b9641ad03 | |||
8baf537c12 | |||
05823567bc | |||
b7029ab176 | |||
102a947c7a | |||
7bb70186c1 |
@ -4,4 +4,5 @@ php:
|
|||||||
- 5.5
|
- 5.5
|
||||||
- 5.4
|
- 5.4
|
||||||
- 5.3
|
- 5.3
|
||||||
- 5.2
|
- 5.2
|
||||||
|
- hhvm
|
600
Parsedown.php
600
Parsedown.php
@ -33,6 +33,19 @@ class Parsedown
|
|||||||
|
|
||||||
private static $instances = array();
|
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
|
# Fields
|
||||||
#
|
#
|
||||||
@ -46,9 +59,6 @@ class Parsedown
|
|||||||
|
|
||||||
function parse($text)
|
function parse($text)
|
||||||
{
|
{
|
||||||
# removes UTF-8 BOM and marker characters
|
|
||||||
$text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text);
|
|
||||||
|
|
||||||
# removes \r characters
|
# removes \r characters
|
||||||
$text = str_replace("\r\n", "\n", $text);
|
$text = str_replace("\r\n", "\n", $text);
|
||||||
$text = str_replace("\r", "\n", $text);
|
$text = str_replace("\r", "\n", $text);
|
||||||
@ -77,7 +87,6 @@ class Parsedown
|
|||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
$text = preg_replace('/\n\s*\n/', "\n\n", $text);
|
|
||||||
$text = trim($text, "\n");
|
$text = trim($text, "\n");
|
||||||
|
|
||||||
$lines = explode("\n", $text);
|
$lines = explode("\n", $text);
|
||||||
@ -91,6 +100,8 @@ class Parsedown
|
|||||||
$text = str_replace($code, $escape_sequence[1], $text);
|
$text = str_replace($code, $escape_sequence[1], $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ~
|
||||||
|
|
||||||
$text = rtrim($text, "\n");
|
$text = rtrim($text, "\n");
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
@ -110,12 +121,11 @@ class Parsedown
|
|||||||
|
|
||||||
foreach ($lines as $line)
|
foreach ($lines as $line)
|
||||||
{
|
{
|
||||||
#
|
|
||||||
# fenced elements
|
# fenced elements
|
||||||
|
|
||||||
switch ($element['type'])
|
switch ($element['type'])
|
||||||
{
|
{
|
||||||
case 'fenced_code_block':
|
case 'fenced block':
|
||||||
|
|
||||||
if ( ! isset($element['closed']))
|
if ( ! isset($element['closed']))
|
||||||
{
|
{
|
||||||
@ -135,16 +145,16 @@ class Parsedown
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'markup':
|
case 'block-level markup':
|
||||||
|
|
||||||
if ( ! isset($element['closed']))
|
if ( ! isset($element['closed']))
|
||||||
{
|
{
|
||||||
if (preg_match('{<'.$element['subtype'].'>$}', $line)) # opening tag
|
if (preg_match('{<'.$element['root '].'>$}', $line)) # opening tag
|
||||||
{
|
{
|
||||||
$element['depth']++;
|
$element['depth']++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('{</'.$element['subtype'].'>$}', $line)) # closing tag
|
if (preg_match('{</'.$element['root '].'>$}', $line)) # closing tag
|
||||||
{
|
{
|
||||||
$element['depth'] > 0
|
$element['depth'] > 0
|
||||||
? $element['depth']--
|
? $element['depth']--
|
||||||
@ -161,14 +171,15 @@ class Parsedown
|
|||||||
|
|
||||||
# *
|
# *
|
||||||
|
|
||||||
if ($line === '')
|
$deindented_line = ltrim($line);
|
||||||
|
|
||||||
|
if ($deindented_line === '')
|
||||||
{
|
{
|
||||||
$element['interrupted'] = true;
|
$element['interrupted'] = true;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# composite elements
|
# composite elements
|
||||||
|
|
||||||
switch ($element['type'])
|
switch ($element['type'])
|
||||||
@ -223,6 +234,8 @@ class Parsedown
|
|||||||
|
|
||||||
$element['lines'] []= $line;
|
$element['lines'] []= $line;
|
||||||
|
|
||||||
|
unset($element['interrupted']);
|
||||||
|
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,29 +251,19 @@ class Parsedown
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# indentation sensitive types
|
# indentation sensitive types
|
||||||
|
|
||||||
$deindented_line = $line;
|
|
||||||
|
|
||||||
switch ($line[0])
|
switch ($line[0])
|
||||||
{
|
{
|
||||||
case ' ':
|
case ' ':
|
||||||
|
|
||||||
# ~
|
|
||||||
|
|
||||||
$deindented_line = ltrim($line);
|
|
||||||
|
|
||||||
if ($deindented_line === '')
|
|
||||||
{
|
|
||||||
continue 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
# code block
|
# code block
|
||||||
|
|
||||||
if (preg_match('/^[ ]{4}(.*)/', $line, $matches))
|
if (isset($line[3]) and $line[3] === ' ' and $line[2] === ' ' and $line[1] === ' ')
|
||||||
{
|
{
|
||||||
if ($element['type'] === 'code_block')
|
$code_line = substr($line, 4);
|
||||||
|
|
||||||
|
if ($element['type'] === 'code block')
|
||||||
{
|
{
|
||||||
if (isset($element['interrupted']))
|
if (isset($element['interrupted']))
|
||||||
{
|
{
|
||||||
@ -269,15 +272,15 @@ class Parsedown
|
|||||||
unset ($element['interrupted']);
|
unset ($element['interrupted']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$element['text'] .= "\n".$matches[1];
|
$element['text'] .= "\n".$code_line;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'code_block',
|
'type' => 'code block',
|
||||||
'text' => $matches[1],
|
'text' => $code_line,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,15 +293,20 @@ class Parsedown
|
|||||||
|
|
||||||
# atx heading (#)
|
# atx heading (#)
|
||||||
|
|
||||||
if (preg_match('/^(#{1,6})[ ]*(.+?)[ ]*#*$/', $line, $matches))
|
if (isset($line[1]))
|
||||||
{
|
{
|
||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$level = strlen($matches[1]);
|
$level = 1;
|
||||||
|
|
||||||
|
while (isset($line[$level]) and $line[$level] === '#')
|
||||||
|
{
|
||||||
|
$level++;
|
||||||
|
}
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'h.',
|
'type' => 'heading',
|
||||||
'text' => $matches[2],
|
'text' => trim($line, '# '),
|
||||||
'level' => $level,
|
'level' => $level,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -308,27 +316,35 @@ class Parsedown
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
|
|
||||||
# setext heading (---)
|
|
||||||
|
|
||||||
if ($line[0] === '-' and $element['type'] === 'p' and ! isset($element['interrupted']) and preg_match('/^[-]+[ ]*$/', $line))
|
|
||||||
{
|
|
||||||
$element['type'] = 'h.';
|
|
||||||
$element['level'] = 2;
|
|
||||||
|
|
||||||
continue 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '=':
|
case '=':
|
||||||
|
|
||||||
# setext heading (===)
|
# setext heading
|
||||||
|
|
||||||
if ($line[0] === '=' and $element['type'] === 'p' and ! isset($element['interrupted']) and preg_match('/^[=]+[ ]*$/', $line))
|
if ($element['type'] === 'paragraph' and isset($element['interrupted']) === false)
|
||||||
{
|
{
|
||||||
$element['type'] = 'h.';
|
$is_heading = true;
|
||||||
$element['level'] = 1;
|
|
||||||
|
$chopped_line = rtrim($line);
|
||||||
|
|
||||||
|
$i = 1;
|
||||||
|
|
||||||
|
while (isset($chopped_line[$i]))
|
||||||
|
{
|
||||||
|
if ($chopped_line[$i] !== $line[0])
|
||||||
|
{
|
||||||
|
$is_heading = false;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($is_heading)
|
||||||
|
{
|
||||||
|
$element['type'] = 'heading';
|
||||||
|
$element['level'] = $line[0] === '-' ? 2 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
@ -336,7 +352,6 @@ class Parsedown
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# indentation insensitive types
|
# indentation insensitive types
|
||||||
|
|
||||||
switch ($deindented_line[0])
|
switch ($deindented_line[0])
|
||||||
@ -350,7 +365,7 @@ class Parsedown
|
|||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => '',
|
'type' => 'self-closing tag',
|
||||||
'text' => $deindented_line,
|
'text' => $deindented_line,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -364,9 +379,9 @@ class Parsedown
|
|||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'markup',
|
'type' => 'block-level markup',
|
||||||
'subtype' => strtolower($matches[1]),
|
|
||||||
'text' => $deindented_line,
|
'text' => $deindented_line,
|
||||||
|
'root ' => strtolower($matches[1]),
|
||||||
'depth' => 0,
|
'depth' => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -401,11 +416,18 @@ class Parsedown
|
|||||||
|
|
||||||
# reference
|
# reference
|
||||||
|
|
||||||
if (preg_match('/^\[(.+?)\]:[ ]*([^ ]+)/', $deindented_line, $matches))
|
if (preg_match('/^\[(.+?)\]:[ ]*(.+?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*$/', $deindented_line, $matches))
|
||||||
{
|
{
|
||||||
$label = strtolower($matches[1]);
|
$label = strtolower($matches[1]);
|
||||||
|
|
||||||
$this->reference_map[$label] = trim($matches[2], '<>');;
|
$this->reference_map[$label] = array(
|
||||||
|
'»' => trim($matches[2], '<>'),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($matches[3]))
|
||||||
|
{
|
||||||
|
$this->reference_map[$label]['#'] = $matches[3];
|
||||||
|
}
|
||||||
|
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
@ -422,7 +444,7 @@ class Parsedown
|
|||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'fenced_code_block',
|
'type' => 'fenced block',
|
||||||
'text' => '',
|
'text' => '',
|
||||||
'fence' => $matches[1],
|
'fence' => $matches[1],
|
||||||
);
|
);
|
||||||
@ -474,7 +496,7 @@ class Parsedown
|
|||||||
|
|
||||||
# li
|
# li
|
||||||
|
|
||||||
if ($deindented_line[0] <= '9' and $deindented_line >= '0' and preg_match('/^([ ]*)\d+[.][ ](.*)/', $line, $matches))
|
if ($deindented_line[0] <= '9' and $deindented_line[0] >= '0' and preg_match('/^([ ]*)\d+[.][ ](.*)/', $line, $matches))
|
||||||
{
|
{
|
||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
@ -493,7 +515,7 @@ class Parsedown
|
|||||||
|
|
||||||
# paragraph
|
# paragraph
|
||||||
|
|
||||||
if ($element['type'] === 'p')
|
if ($element['type'] === 'paragraph')
|
||||||
{
|
{
|
||||||
if (isset($element['interrupted']))
|
if (isset($element['interrupted']))
|
||||||
{
|
{
|
||||||
@ -513,7 +535,7 @@ class Parsedown
|
|||||||
$elements []= $element;
|
$elements []= $element;
|
||||||
|
|
||||||
$element = array(
|
$element = array(
|
||||||
'type' => 'p',
|
'type' => 'paragraph',
|
||||||
'text' => $line,
|
'text' => $line,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -533,12 +555,10 @@ class Parsedown
|
|||||||
{
|
{
|
||||||
switch ($element['type'])
|
switch ($element['type'])
|
||||||
{
|
{
|
||||||
case 'p':
|
case 'paragraph':
|
||||||
|
|
||||||
$text = $this->parse_span_elements($element['text']);
|
$text = $this->parse_span_elements($element['text']);
|
||||||
|
|
||||||
$text = preg_replace('/[ ]{2}\n/', '<br />'."\n", $text);
|
|
||||||
|
|
||||||
if ($context === 'li' and $markup === '')
|
if ($context === 'li' and $markup === '')
|
||||||
{
|
{
|
||||||
if (isset($element['interrupted']))
|
if (isset($element['interrupted']))
|
||||||
@ -565,18 +585,22 @@ class Parsedown
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'code_block':
|
case 'code block':
|
||||||
case 'fenced_code_block':
|
case 'fenced block':
|
||||||
|
|
||||||
$text = htmlspecialchars($element['text'], ENT_NOQUOTES, 'UTF-8');
|
$text = htmlspecialchars($element['text'], ENT_NOQUOTES, 'UTF-8');
|
||||||
|
|
||||||
strpos($text, "\x1A\\") !== FALSE and $text = strtr($text, $this->escape_sequence_map);
|
strpos($text, "\x1A\\") !== FALSE and $text = strtr($text, $this->escape_sequence_map);
|
||||||
|
|
||||||
$markup .= '<pre><code>'.$text.'</code></pre>'."\n";
|
$markup .= isset($element['language'])
|
||||||
|
? '<pre><code class="language-'.$element['language'].'">'.$text.'</code></pre>'
|
||||||
|
: '<pre><code>'.$text.'</code></pre>';
|
||||||
|
|
||||||
|
$markup .= "\n";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h.':
|
case 'heading':
|
||||||
|
|
||||||
$text = $this->parse_span_elements($element['text']);
|
$text = $this->parse_span_elements($element['text']);
|
||||||
|
|
||||||
@ -612,6 +636,12 @@ class Parsedown
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'block-level markup':
|
||||||
|
|
||||||
|
$markup .= $this->parse_span_elements($element['text'])."\n";
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
$markup .= $element['text']."\n";
|
$markup .= $element['text']."\n";
|
||||||
@ -621,181 +651,343 @@ class Parsedown
|
|||||||
return $markup;
|
return $markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parse_span_elements($text)
|
# ~
|
||||||
|
|
||||||
|
private $strong_regex = array(
|
||||||
|
'*' => '/^[*]{2}([^*]+?)[*]{2}(?![*])/s',
|
||||||
|
'_' => '/^__([^_]+?)__(?!_)/s',
|
||||||
|
);
|
||||||
|
|
||||||
|
private $em_regex = array(
|
||||||
|
'*' => '/^[*]([^*]+?)[*](?![*])/s',
|
||||||
|
'_' => '/^_([^_]+?)[_](?![_])\b/s',
|
||||||
|
);
|
||||||
|
|
||||||
|
private $strong_em_regex = array(
|
||||||
|
'*' => '/^[*]{2}(.*?)[*](.+?)[*](.*?)[*]{2}/s',
|
||||||
|
'_' => '/^__(.*?)_(.+?)_(.*?)__/s',
|
||||||
|
);
|
||||||
|
|
||||||
|
private $em_strong_regex = array(
|
||||||
|
'*' => '/^[*](.*?)[*]{2}(.+?)[*]{2}(.*?)[*]/s',
|
||||||
|
'_' => '/^_(.*?)__(.+?)__(.*?)_/s',
|
||||||
|
);
|
||||||
|
|
||||||
|
private function parse_span_elements($text, $markers = array('![', '&', '*', '<', '[', '_', '`', 'http', '~~'))
|
||||||
{
|
{
|
||||||
$map = array();
|
if (isset($text[2]) === false or $markers === array())
|
||||||
|
|
||||||
$index = 0;
|
|
||||||
|
|
||||||
# code span
|
|
||||||
|
|
||||||
if (strpos($text, '`') !== FALSE and preg_match_all('/`(.+?)`/', $text, $matches, PREG_SET_ORDER))
|
|
||||||
{
|
{
|
||||||
foreach ($matches as $matches)
|
return $text;
|
||||||
{
|
|
||||||
$element_text = $matches[1];
|
|
||||||
$element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8');
|
|
||||||
|
|
||||||
# decodes escape sequences
|
|
||||||
|
|
||||||
$this->escape_sequence_map
|
|
||||||
and strpos($element_text, "\x1A") !== FALSE
|
|
||||||
and $element_text = strtr($element_text, $this->escape_sequence_map);
|
|
||||||
|
|
||||||
# composes element
|
|
||||||
|
|
||||||
$element = '<code>'.$element_text.'</code>';
|
|
||||||
|
|
||||||
# encodes element
|
|
||||||
|
|
||||||
$code = "\x1A".'$'.$index;
|
|
||||||
|
|
||||||
$text = str_replace($matches[0], $code, $text);
|
|
||||||
|
|
||||||
$map[$code] = $element;
|
|
||||||
|
|
||||||
$index ++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# inline link or image
|
# ~
|
||||||
|
|
||||||
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
|
$markup = '';
|
||||||
|
|
||||||
|
while ($markers)
|
||||||
{
|
{
|
||||||
foreach ($matches as $matches)
|
$closest_marker = null;
|
||||||
|
$closest_marker_index = 0;
|
||||||
|
$closest_marker_position = null;
|
||||||
|
|
||||||
|
foreach ($markers as $index => $marker)
|
||||||
{
|
{
|
||||||
$url = $matches[4];
|
$marker_position = strpos($text, $marker);
|
||||||
|
|
||||||
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url);
|
if ($marker_position === false)
|
||||||
|
|
||||||
if ($matches[1]) # image
|
|
||||||
{
|
{
|
||||||
$element = '<img alt="'.$matches[3].'" src="'.$url.'">';
|
unset($markers[$index]);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$element_text = $this->parse_span_elements($matches[3]);
|
|
||||||
|
|
||||||
$element = '<a href="'.$url.'">'.$element_text.'</a>';
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ~
|
if ($closest_marker === null or $marker_position < $closest_marker_position)
|
||||||
|
{
|
||||||
$code = "\x1A".'$'.$index;
|
$closest_marker = $marker;
|
||||||
|
$closest_marker_index = $index;
|
||||||
$text = str_replace($matches[0], $code, $text);
|
$closest_marker_position = $marker_position;
|
||||||
|
}
|
||||||
$map[$code] = $element;
|
|
||||||
|
|
||||||
$index ++;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
# reference link or image
|
# ~
|
||||||
|
|
||||||
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
|
if ($closest_marker === null or isset($text[$closest_marker_position + 2]) === false)
|
||||||
{
|
|
||||||
foreach ($matches as $matches)
|
|
||||||
{
|
{
|
||||||
$link_definition = isset($matches[3]) && $matches[3]
|
$markup .= $text;
|
||||||
? $matches[3]
|
|
||||||
: $matches[2]; # implicit
|
|
||||||
|
|
||||||
$link_definition = strtolower($link_definition);
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$markup .= substr($text, 0, $closest_marker_position);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($this->reference_map[$link_definition]))
|
$text = substr($text, $closest_marker_position);
|
||||||
{
|
|
||||||
$url = $this->reference_map[$link_definition];
|
|
||||||
|
|
||||||
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url);
|
# ~
|
||||||
|
|
||||||
if ($matches[1]) # image
|
unset($markers[$closest_marker_index]);
|
||||||
|
|
||||||
|
# ~
|
||||||
|
|
||||||
|
switch ($closest_marker)
|
||||||
|
{
|
||||||
|
case '![':
|
||||||
|
case '[':
|
||||||
|
|
||||||
|
if (strpos($text, ']') and preg_match('/\[((?:[^][]|(?R))*)\]/', $text, $matches))
|
||||||
{
|
{
|
||||||
$element = '<img alt="'.$matches[2].'" src="'.$url.'">';
|
$element = array(
|
||||||
}
|
'!' => $text[0] === '!',
|
||||||
else # anchor
|
'a' => $matches[1],
|
||||||
{
|
);
|
||||||
$element_text = $this->parse_span_elements($matches[2]);
|
|
||||||
|
|
||||||
$element = '<a href="'.$url.'">'.$element_text.'</a>';
|
$offset = strlen($matches[0]);
|
||||||
|
|
||||||
|
$element['!'] and $offset++;
|
||||||
|
|
||||||
|
$remaining_text = substr($text, $offset);
|
||||||
|
|
||||||
|
if ($remaining_text[0] === '(' and preg_match('/\([ ]*(.*?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*\)/', $remaining_text, $matches))
|
||||||
|
{
|
||||||
|
$element['»'] = $matches[1];
|
||||||
|
|
||||||
|
if (isset($matches[2]))
|
||||||
|
{
|
||||||
|
$element['#'] = $matches[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
$offset += strlen($matches[0]);
|
||||||
|
}
|
||||||
|
elseif ($this->reference_map)
|
||||||
|
{
|
||||||
|
$reference = $element['a'];
|
||||||
|
|
||||||
|
if (preg_match('/^\s*\[(.*?)\]/', $remaining_text, $matches))
|
||||||
|
{
|
||||||
|
$reference = $matches[1] ? $matches[1] : $element['a'];
|
||||||
|
|
||||||
|
$offset += strlen($matches[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$reference = strtolower($reference);
|
||||||
|
|
||||||
|
if (isset($this->reference_map[$reference]))
|
||||||
|
{
|
||||||
|
$element['»'] = $this->reference_map[$reference]['»'];
|
||||||
|
|
||||||
|
if (isset($this->reference_map[$reference]['#']))
|
||||||
|
{
|
||||||
|
$element['#'] = $this->reference_map[$reference]['#'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unset($element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unset($element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# ~
|
if (isset($element))
|
||||||
|
|
||||||
$code = "\x1A".'$'.$index;
|
|
||||||
|
|
||||||
$text = str_replace($matches[0], $code, $text);
|
|
||||||
|
|
||||||
$map[$code] = $element;
|
|
||||||
|
|
||||||
$index ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos($text, '://') !== FALSE)
|
|
||||||
{
|
|
||||||
switch (TRUE)
|
|
||||||
{
|
|
||||||
case preg_match_all('{<(https?:[/]{2}[^\s]+)>}i', $text, $matches, PREG_SET_ORDER):
|
|
||||||
case preg_match_all('{\b(https?:[/]{2}[^\s]+)\b}i', $text, $matches, PREG_SET_ORDER):
|
|
||||||
|
|
||||||
foreach ($matches as $matches)
|
|
||||||
{
|
{
|
||||||
$url = $matches[1];
|
$element['»'] = str_replace('&', '&', $element['»']);
|
||||||
|
$element['»'] = str_replace('<', '<', $element['»']);
|
||||||
|
|
||||||
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url);
|
if ($element['!'])
|
||||||
|
{
|
||||||
|
$markup .= '<img alt="'.$element['a'].'" src="'.$element['»'].'" />';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$element['a'] = $this->parse_span_elements($element['a'], $markers);
|
||||||
|
|
||||||
$element = '<a href=":href">:text</a>';
|
$markup .= isset($element['#'])
|
||||||
$element = str_replace(':text', $url, $element);
|
? '<a href="'.$element['»'].'" title="'.$element['#'].'">'.$element['a'].'</a>'
|
||||||
$element = str_replace(':href', $url, $element);
|
: '<a href="'.$element['»'].'">'.$element['a'].'</a>';
|
||||||
|
}
|
||||||
|
|
||||||
# ~
|
unset($element);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$markup .= $closest_marker;
|
||||||
|
|
||||||
$code = "\x1A".'$'.$index;
|
$offset = $closest_marker === '![' ? 2 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
$text = str_replace($matches[0], $code, $text);
|
break;
|
||||||
|
|
||||||
$map[$code] = $element;
|
case '&':
|
||||||
|
|
||||||
$index ++;
|
$markup .= '&';
|
||||||
|
|
||||||
|
$offset = substr($text, 0, 5) === '&' ? 5 : 1;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '*':
|
||||||
|
case '_':
|
||||||
|
|
||||||
|
if ($text[1] === $closest_marker and preg_match($this->strong_regex[$closest_marker], $text, $matches))
|
||||||
|
{
|
||||||
|
$matches[1] = $this->parse_span_elements($matches[1], $markers);
|
||||||
|
|
||||||
|
$markup .= '<strong>'.$matches[1].'</strong>';
|
||||||
|
}
|
||||||
|
elseif (preg_match($this->em_regex[$closest_marker], $text, $matches))
|
||||||
|
{
|
||||||
|
$matches[1] = $this->parse_span_elements($matches[1], $markers);
|
||||||
|
|
||||||
|
$markup .= '<em>'.$matches[1].'</em>';
|
||||||
|
}
|
||||||
|
elseif ($text[1] === $closest_marker and preg_match($this->strong_em_regex[$closest_marker], $text, $matches))
|
||||||
|
{
|
||||||
|
$matches[2] = $this->parse_span_elements($matches[2], $markers);
|
||||||
|
|
||||||
|
$matches[1] and $matches[1] = $this->parse_span_elements($matches[1], $markers);
|
||||||
|
$matches[3] and $matches[3] = $this->parse_span_elements($matches[3], $markers);
|
||||||
|
|
||||||
|
$markup .= '<strong>'.$matches[1].'<em>'.$matches[2].'</em>'.$matches[3].'</strong>';
|
||||||
|
}
|
||||||
|
elseif (preg_match($this->em_strong_regex[$closest_marker], $text, $matches))
|
||||||
|
{
|
||||||
|
$matches[2] = $this->parse_span_elements($matches[2], $markers);
|
||||||
|
|
||||||
|
$matches[1] and $matches[1] = $this->parse_span_elements($matches[1], $markers);
|
||||||
|
$matches[3] and $matches[3] = $this->parse_span_elements($matches[3], $markers);
|
||||||
|
|
||||||
|
$markup .= '<em>'.$matches[1].'<strong>'.$matches[2].'</strong>'.$matches[3].'</em>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($matches) and $matches)
|
||||||
|
{
|
||||||
|
$offset = strlen($matches[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$markup .= $closest_marker;
|
||||||
|
|
||||||
|
$offset = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '<':
|
||||||
|
|
||||||
|
if (strpos($text, '>') !== false)
|
||||||
|
{
|
||||||
|
if ($text[1] === 'h' and preg_match('/^<(https?:[\/]{2}[^\s]+?)>/i', $text, $matches))
|
||||||
|
{
|
||||||
|
$element_url = $matches[1];
|
||||||
|
$element_url = str_replace('&', '&', $element_url);
|
||||||
|
$element_url = str_replace('<', '<', $element_url);
|
||||||
|
|
||||||
|
$markup .= '<a href="'.$element_url.'">'.$element_url.'</a>';
|
||||||
|
|
||||||
|
$offset = strlen($matches[0]);
|
||||||
|
}
|
||||||
|
elseif (preg_match('/^<\/?\w.*?>/', $text, $matches))
|
||||||
|
{
|
||||||
|
$markup .= $matches[0];
|
||||||
|
|
||||||
|
$offset = strlen($matches[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$markup .= '<';
|
||||||
|
|
||||||
|
$offset = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$markup .= '<';
|
||||||
|
|
||||||
|
$offset = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '`':
|
||||||
|
|
||||||
|
if (preg_match('/^`(.+?)`/', $text, $matches))
|
||||||
|
{
|
||||||
|
$element_text = $matches[1];
|
||||||
|
$element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8');
|
||||||
|
|
||||||
|
if ($this->escape_sequence_map and strpos($element_text, "\x1A") !== false)
|
||||||
|
{
|
||||||
|
$element_text = strtr($element_text, $this->escape_sequence_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
$markup .= '<code>'.$element_text.'</code>';
|
||||||
|
|
||||||
|
$offset = strlen($matches[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$markup .= '`';
|
||||||
|
|
||||||
|
$offset = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'http':
|
||||||
|
|
||||||
|
if (preg_match('/^https?:[\/]{2}[^\s]+\b/i', $text, $matches))
|
||||||
|
{
|
||||||
|
$element_url = $matches[0];
|
||||||
|
$element_url = str_replace('&', '&', $element_url);
|
||||||
|
$element_url = str_replace('<', '<', $element_url);
|
||||||
|
|
||||||
|
$markup .= '<a href="'.$element_url.'">'.$element_url.'</a>';
|
||||||
|
|
||||||
|
$offset = strlen($matches[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$markup .= 'http';
|
||||||
|
|
||||||
|
$offset = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '~~':
|
||||||
|
|
||||||
|
if (preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches))
|
||||||
|
{
|
||||||
|
$matches[1] = $this->parse_span_elements($matches[1], $markers);
|
||||||
|
|
||||||
|
$markup .= '<del>'.$matches[1].'</del>';
|
||||||
|
|
||||||
|
$offset = strlen($matches[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$markup .= '~~';
|
||||||
|
|
||||||
|
$offset = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($offset))
|
||||||
|
{
|
||||||
|
$text = substr($text, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
$markers[$closest_marker_index] = $closest_marker;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ~
|
$markup = str_replace($this->break_marker, '<br />'."\n", $markup);
|
||||||
|
|
||||||
strpos($text, '&') !== FALSE and $text = preg_replace('/&(?!#?\w+;)/', '&', $text);
|
return $markup;
|
||||||
strpos($text, '<') !== FALSE and $text = preg_replace('/<(?!\/?\w.*?>)/', '<', $text);
|
|
||||||
|
|
||||||
# ~
|
|
||||||
|
|
||||||
if (strpos($text, '~~') !== FALSE)
|
|
||||||
{
|
|
||||||
$text = preg_replace('/~~(?=\S)(.+?)(?<=\S)~~/s', '<del>$1</del>', $text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos($text, '_') !== FALSE)
|
|
||||||
{
|
|
||||||
$text = preg_replace('/__(?=\S)([^_]+?)(?<=\S)__/s', '<strong>$1</strong>', $text, -1, $count);
|
|
||||||
$count or $text = preg_replace('/__(?=\S)(.+?)(?<=\S)__(?!_)/s', '<strong>$1</strong>', $text);
|
|
||||||
|
|
||||||
$text = preg_replace('/\b_(?=\S)(.+?)(?<=\S)_\b/s', '<em>$1</em>', $text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos($text, '*') !== FALSE)
|
|
||||||
{
|
|
||||||
$text = preg_replace('/\*\*(?=\S)([^*]+?)(?<=\S)\*\*/s', '<strong>$1</strong>', $text, -1, $count);
|
|
||||||
$count or $text = preg_replace('/\*\*(?=\S)(.+?)(?<=\S)\*\*(?!\*)/s', '<strong>$1</strong>', $text);
|
|
||||||
|
|
||||||
$text = preg_replace('/\*(?=\S)([^*]+?)(?<=\S)\*/s', '<em>$1</em>', $text, -1, $count);
|
|
||||||
$count or $text = preg_replace('/\*(?=\S)(.+?)(?<=\S)\*(?!\*)/s', '<em>$1</em>', $text);
|
|
||||||
}
|
|
||||||
|
|
||||||
$text = strtr($text, $map);
|
|
||||||
|
|
||||||
return $text;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
18
README.md
18
README.md
@ -1,8 +1,20 @@
|
|||||||
## Parsedown
|
## Parsedown
|
||||||
|
|
||||||
Fast and consistent [Markdown][1] parser for PHP.
|
Better [Markdown](http://en.wikipedia.org/wiki/Markdown) parser for PHP.
|
||||||
|
|
||||||
[Home](http://parsedown.org) · [Demo](http://parsedown.org/explorer/) · [Tests](http://parsedown.org/tests/)
|
***
|
||||||
|
|
||||||
|
[ [demo](http://parsedown.org/demo) ] [ [tests](http://parsedown.org/tests/) ]
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* [fast](http://parsedown.org/speed)
|
||||||
|
* [consistent](http://parsedown.org/consistency)
|
||||||
|
* [GitHub Flavored](https://help.github.com/articles/github-flavored-markdown)
|
||||||
|
* friendly to international input
|
||||||
|
* [tested](https://travis-ci.org/erusev/parsedown) in PHP 5.2, 5.3, 5.4 and 5.5 as well as in [HHVM](http://www.hhvm.com/)
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
@ -17,5 +29,3 @@ $result = Parsedown::instance()->parse($text);
|
|||||||
|
|
||||||
echo $result; # prints: <p>Hello <strong>Parsedown</strong>!</p>
|
echo $result; # prints: <p>Hello <strong>Parsedown</strong>!</p>
|
||||||
```
|
```
|
||||||
|
|
||||||
[1]: http://daringfireball.net/projects/markdown/
|
|
||||||
|
@ -4,4 +4,5 @@
|
|||||||
<h4>h4</h4>
|
<h4>h4</h4>
|
||||||
<h5>h5</h5>
|
<h5>h5</h5>
|
||||||
<h6>h6</h6>
|
<h6>h6</h6>
|
||||||
<h1>closed h1</h1>
|
<h1>closed h1</h1>
|
||||||
|
<p>#</p>
|
@ -10,4 +10,6 @@
|
|||||||
|
|
||||||
###### h6
|
###### h6
|
||||||
|
|
||||||
# closed h1 #
|
# closed h1 #
|
||||||
|
|
||||||
|
#
|
2
tests/data/compound_emphasis.html
Normal file
2
tests/data/compound_emphasis.html
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<p><em><code>code</code></em> <strong><code>code</code></strong></p>
|
||||||
|
<p><em><code>code</code><strong><code>code</code></strong><code>code</code></em></p>
|
4
tests/data/compound_emphasis.md
Normal file
4
tests/data/compound_emphasis.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
_`code`_ __`code`__
|
||||||
|
|
||||||
|
*`code`**`code`**`code`*
|
||||||
|
|
@ -1,5 +1,8 @@
|
|||||||
<p><strong><em>em strong</em></strong></p>
|
<p><strong><em>em strong</em></strong></p>
|
||||||
<p><strong><em>one</em> at the start</strong></p>
|
<p><strong><em>em strong</em> strong</strong></p>
|
||||||
<p><strong>one at the <em>end</em></strong></p>
|
<p><strong>strong <em>em strong</em></strong></p>
|
||||||
<p><strong>one <em>in the</em> middle</strong></p>
|
<p><strong>strong <em>em strong</em> strong</strong></p>
|
||||||
<p><strong>one with <em>asterisks</em></strong></p>
|
<p><strong><em>em strong</em></strong></p>
|
||||||
|
<p><strong><em>em strong</em> strong</strong></p>
|
||||||
|
<p><strong>strong <em>em strong</em></strong></p>
|
||||||
|
<p><strong>strong <em>em strong</em> strong</strong></p>
|
@ -1,9 +1,15 @@
|
|||||||
___em strong___
|
___em strong___
|
||||||
|
|
||||||
___one_ at the start__
|
___em strong_ strong__
|
||||||
|
|
||||||
__one at the _end___
|
__strong _em strong___
|
||||||
|
|
||||||
__one _in the_ middle__
|
__strong _em strong_ strong__
|
||||||
|
|
||||||
**one with *asterisks***
|
***em strong***
|
||||||
|
|
||||||
|
***em strong* strong**
|
||||||
|
|
||||||
|
**strong *em strong***
|
||||||
|
|
||||||
|
**strong *em strong* strong**
|
@ -1,6 +1,8 @@
|
|||||||
<p><em>underscore</em>, <em>asterisk</em>, <em>one two</em>, <em>three four</em>, <em>a</em>, <em>b</em></p>
|
<p><em>underscore</em>, <em>asterisk</em>, <em>one two</em>, <em>three four</em>, <em>a</em>, <em>b</em></p>
|
||||||
<p><em>multiline
|
<p><strong>strong</strong> and <em>em</em> and <strong>strong</strong> and <em>em</em></p>
|
||||||
emphasis</em></p>
|
<p><em>line
|
||||||
<p>_ this _ is not an emphasis, neither is _ this_, _this _, or _this*</p>
|
line
|
||||||
|
line</em></p>
|
||||||
<p>this_is_not_an_emphasis</p>
|
<p>this_is_not_an_emphasis</p>
|
||||||
<p>an empty emphasis __ ** is not an emphasis</p>
|
<p>an empty emphasis __ ** is not an emphasis</p>
|
||||||
|
<p>*mixed *<em>double and</em> single asterisk** spans</p>
|
@ -1,10 +1,13 @@
|
|||||||
_underscore_, *asterisk*, _one two_, *three four*, _a_, *b*
|
_underscore_, *asterisk*, _one two_, *three four*, _a_, *b*
|
||||||
|
|
||||||
_multiline
|
**strong** and *em* and **strong** and *em*
|
||||||
emphasis_
|
|
||||||
|
|
||||||
_ this _ is not an emphasis, neither is _ this_, _this _, or _this*
|
_line
|
||||||
|
line
|
||||||
|
line_
|
||||||
|
|
||||||
this_is_not_an_emphasis
|
this_is_not_an_emphasis
|
||||||
|
|
||||||
an empty emphasis __ ** is not an emphasis
|
an empty emphasis __ ** is not an emphasis
|
||||||
|
|
||||||
|
*mixed **double and* single asterisk** spans
|
@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
$message = 'fenced code block';
|
$message = 'fenced code block';
|
||||||
echo $message;</code></pre>
|
echo $message;</code></pre>
|
||||||
<pre><code>tilde</code></pre>
|
<pre><code>tilde</code></pre>
|
||||||
|
<pre><code class="language-php">echo 'language identifier';</code></pre>
|
@ -7,4 +7,8 @@ echo $message;
|
|||||||
|
|
||||||
~~~
|
~~~
|
||||||
tilde
|
tilde
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
|
```php
|
||||||
|
echo 'language identifier';
|
||||||
|
```
|
@ -1 +1 @@
|
|||||||
<p><img alt="Markdown Logo" src="/md.png"></p>
|
<p><img alt="Markdown Logo" src="/md.png" /></p>
|
@ -1,3 +1,3 @@
|
|||||||
![Markdown Logo][image]
|
![Markdown Logo][image]
|
||||||
|
|
||||||
[image]: /md.png
|
[image]: /md.png
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
<p>an <a href="http://example.com">implicit</a> reference link</p>
|
<p>an <a href="http://example.com">implicit</a> reference link</p>
|
||||||
<p>an <a href="http://example.com">implicit</a> reference link with an empty link definition</p>
|
<p>an <a href="http://example.com">implicit</a> reference link with an empty link definition</p>
|
||||||
|
<p>an <a href="http://example.com" title="Example">explicit</a> reference link with a title</p>
|
@ -2,4 +2,8 @@ an [implicit] reference link
|
|||||||
|
|
||||||
[implicit]: http://example.com
|
[implicit]: http://example.com
|
||||||
|
|
||||||
an [implicit][] reference link with an empty link definition
|
an [implicit][] reference link with an empty link definition
|
||||||
|
|
||||||
|
an [explicit][example] reference link with a title
|
||||||
|
|
||||||
|
[example]: http://example.com "Example"
|
@ -1,2 +1,4 @@
|
|||||||
<p><a href="http://example.com">link</a></p>
|
<p><a href="http://example.com">link</a> and <a href="/tests/">another link</a></p>
|
||||||
<p><a href="http://example.com"><img alt="MD Logo" src="http://parsedown.org/md.png"></a></p>
|
<p><a href="http://example.com"><code>link</code></a></p>
|
||||||
|
<p><a href="http://example.com"><img alt="MD Logo" src="http://parsedown.org/md.png" /></a></p>
|
||||||
|
<p><a href="http://example.com"><img alt="MD Logo" src="http://parsedown.org/md.png" /> and text</a></p>
|
@ -1,3 +1,7 @@
|
|||||||
[link](http://example.com)
|
[link](http://example.com) and [another link](/tests/)
|
||||||
|
|
||||||
[](http://example.com)
|
[`link`](http://example.com)
|
||||||
|
|
||||||
|
[](http://example.com)
|
||||||
|
|
||||||
|
[ and text](http://example.com)
|
1
tests/data/inline_title.html
Normal file
1
tests/data/inline_title.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<p><a href="http://example.com" title="Example">single quotes</a> and <a href="http://example.com" title="Example">double quotes</a></p>
|
1
tests/data/inline_title.md
Normal file
1
tests/data/inline_title.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
[single quotes](http://example.com 'Example') and [double quotes](http://example.com "Example")
|
7
tests/data/multiline_list_paragraph.html
Normal file
7
tests/data/multiline_list_paragraph.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<p>li</p>
|
||||||
|
<p>line
|
||||||
|
line</p>
|
||||||
|
</li>
|
||||||
|
</ul>
|
4
tests/data/multiline_list_paragraph.md
Normal file
4
tests/data/multiline_list_paragraph.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
- li
|
||||||
|
|
||||||
|
line
|
||||||
|
line
|
1
tests/data/reference_title.html
Normal file
1
tests/data/reference_title.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<p><a href="http://example.com" title="Title">single quotes</a> and <a href="http://example.com" title="Title">double quotes</a></p>
|
1
tests/data/reference_title.md
Normal file
1
tests/data/reference_title.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
[single quotes](http://example.com 'Title') and [double quotes](http://example.com "Title")
|
@ -1,8 +1,7 @@
|
|||||||
<p>AT&T has an ampersand in their name</p>
|
<p>AT&T has an ampersand in their name</p>
|
||||||
<pre><code>Let's play some cards ♠ ♣ ♥ ♦</code></pre>
|
|
||||||
<p>AT&T is another way to write it</p>
|
<p>AT&T is another way to write it</p>
|
||||||
<p>this & that</p>
|
<p>this & that</p>
|
||||||
<p>4 < 5 and 6 > 5</p>
|
<p>4 < 5 and 6 > 5</p>
|
||||||
<p><a href="http://example.com/autolink?a=1&b=2">http://example.com/autolink?a=1&b=2</a> </p>
|
<p><a href="http://example.com/autolink?a=1&b=2">http://example.com/autolink?a=1&b=2</a></p>
|
||||||
<p><a href="/script?a=1&b=2">inline link</a></p>
|
<p><a href="/script?a=1&b=2">inline link</a></p>
|
||||||
<p><a href="http://example.com/?a=1&b=2">reference link</a></p>
|
<p><a href="http://example.com/?a=1&b=2">reference link</a></p>
|
@ -1,14 +1,12 @@
|
|||||||
AT&T has an ampersand in their name
|
AT&T has an ampersand in their name
|
||||||
|
|
||||||
Let's play some cards ♠ ♣ ♥ ♦
|
|
||||||
|
|
||||||
AT&T is another way to write it
|
AT&T is another way to write it
|
||||||
|
|
||||||
this & that
|
this & that
|
||||||
|
|
||||||
4 < 5 and 6 > 5
|
4 < 5 and 6 > 5
|
||||||
|
|
||||||
<http://example.com/autolink?a=1&b=2>
|
<http://example.com/autolink?a=1&b=2>
|
||||||
|
|
||||||
[inline link](/script?a=1&b=2)
|
[inline link](/script?a=1&b=2)
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<p><del>strikethrough</del></p>
|
<p><del>strikethrough</del></p>
|
||||||
<p>in the <del>middle</del> of a sentence</p>
|
<p>here's <del>one</del> followed by <del>another one</del></p>
|
||||||
<p>in the middle of a w<del>or</del>d</p>
|
<p>~~ this ~~ is not one neither is ~this~</p>
|
@ -1,5 +1,5 @@
|
|||||||
~~strikethrough~~
|
~~strikethrough~~
|
||||||
|
|
||||||
in the ~~middle~~ of a sentence
|
here's ~~one~~ followed by ~~another one~~
|
||||||
|
|
||||||
in the middle of a w~~or~~d
|
~~ this ~~ is not one neither is ~this~
|
@ -1,6 +1,6 @@
|
|||||||
<p><em><strong>strong em</strong></em> </p>
|
|
||||||
<p><em>em <strong>strong em</strong></em></p>
|
<p><em>em <strong>strong em</strong></em></p>
|
||||||
<p><em><strong>strong em</strong> em</em></p>
|
<p><em><strong>strong em</strong> em</em></p>
|
||||||
<p><em><strong>strong em</strong></em></p>
|
<p><em>em <strong>strong em</strong> em</em></p>
|
||||||
<p><em>em <strong>strong em</strong></em></p>
|
<p><em>em <strong>strong em</strong></em></p>
|
||||||
<p><em><strong>strong em</strong> em</em></p>
|
<p><em><strong>strong em</strong> em</em></p>
|
||||||
|
<p><em>em <strong>strong em</strong> em</em></p>
|
@ -1,11 +1,11 @@
|
|||||||
***strong em***
|
|
||||||
|
|
||||||
*em **strong em***
|
*em **strong em***
|
||||||
|
|
||||||
***strong em** em*
|
***strong em** em*
|
||||||
|
|
||||||
___strong em___
|
*em **strong em** em*
|
||||||
|
|
||||||
_em __strong em___
|
_em __strong em___
|
||||||
|
|
||||||
___strong em__ em_
|
___strong em__ em_
|
||||||
|
|
||||||
|
_em __strong em__ em_
|
6
tests/data/tab-indented_code_block.html
Normal file
6
tests/data/tab-indented_code_block.html
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<pre><code><?php
|
||||||
|
|
||||||
|
$message = 'Hello World!';
|
||||||
|
echo $message;
|
||||||
|
|
||||||
|
echo "following a blank line";</code></pre>
|
6
tests/data/tab-indented_code_block.md
Normal file
6
tests/data/tab-indented_code_block.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$message = 'Hello World!';
|
||||||
|
echo $message;
|
||||||
|
|
||||||
|
echo "following a blank line";
|
@ -3,4 +3,5 @@
|
|||||||
<p>[one][404] with no definition</p>
|
<p>[one][404] with no definition</p>
|
||||||
<p><a href="http://example.com">multiline
|
<p><a href="http://example.com">multiline
|
||||||
one</a> defined on 2 lines</p>
|
one</a> defined on 2 lines</p>
|
||||||
<p><a href="http://example.com">one</a> with an upper case label</p>
|
<p><a href="http://example.com">one</a> with an upper case label</p>
|
||||||
|
<p><a href="http://example.com"><code>link</code></a></p>
|
@ -13,4 +13,6 @@ one][website] defined on 2 lines
|
|||||||
|
|
||||||
[one][label] with an upper case label
|
[one][label] with an upper case label
|
||||||
|
|
||||||
[LABEL]: http://example.com
|
[LABEL]: http://example.com
|
||||||
|
|
||||||
|
[`link`][website]
|
@ -1 +1,2 @@
|
|||||||
<p>Here's an autolink <a href="http://example.com">http://example.com</a>.</p>
|
<p>an autolink <a href="http://example.com">http://example.com</a></p>
|
||||||
|
<p>inside of brackets [<a href="http://example.com">http://example.com</a>], inside of braces {<a href="http://example.com">http://example.com</a>}, inside of parentheses (<a href="http://example.com">http://example.com</a>)</p>
|
@ -1 +1,3 @@
|
|||||||
Here's an autolink http://example.com.
|
an autolink http://example.com
|
||||||
|
|
||||||
|
inside of brackets [http://example.com], inside of braces {http://example.com}, inside of parentheses (http://example.com)
|
Reference in New Issue
Block a user