1
0
mirror of https://github.com/erusev/parsedown.git synced 2025-09-05 04:31:45 +02:00

Compare commits

...

5 Commits
0.2.0 ... 0.3.0

Author SHA1 Message Date
Emanuil Rusev
2e314ad474 resolve #24 2013-11-02 21:42:55 +02:00
Emanuil Rusev
e475602e2f simplify parsing of code blocks 2013-11-02 02:18:13 +02:00
Emanuil Rusev
f43f54b877 remove redundant parse_inline_elements call 2013-10-23 00:50:32 +03:00
Emanuil Rusev
d733acc94e add .idea to .gitignore 2013-10-23 00:44:21 +03:00
Emanuil Rusev
6a0695deb9 correct spelling of $link_definition 2013-10-13 22:52:36 +03:00
4 changed files with 104 additions and 11 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.DS_Store
.idea
nbproject

View File

@@ -122,14 +122,33 @@ class Parsedown
foreach ($lines as $line)
{
# Block-Level HTML
if ($element['type'] === 'block' and ! isset($element['closed']))
{
if (preg_match('{<'.$element['subtype'].'>$}', $line)) # <open>
{
$element['depth']++;
}
if (preg_match('{</'.$element['subtype'].'>$}', $line)) # </close>
{
$element['depth'] > 0
? $element['depth']--
: $element['closed'] = true;
}
$element['text'] .= "\n".$line;
continue;
}
# Empty
if ($line === '')
{
$element['interrupted'] = true;
$element['type'] === 'code' and $element['text'] .= "\n";
continue;
}
@@ -251,6 +270,8 @@ class Parsedown
{
if ($element['type'] === 'code')
{
isset($element['interrupted']) and $element['text'] .= "\n";
$element['text'] .= "\n".$matches[1];
}
else
@@ -322,6 +343,38 @@ class Parsedown
continue;
}
# Block-Level HTML <self-closing/>
if (preg_match('{^<.+?/>$}', $line))
{
$elements []= $element;
$element = array(
'type' => '',
'text' => $line,
);
continue;
}
# Block-Level HTML <open>
if (preg_match('{^<(\w+)(?:[ ].*?)?>}', $line, $matches))
{
$elements []= $element;
$element = array(
'type' => 'block',
'subtype' => strtolower($matches[1]),
'text' => $line,
'depth' => 0,
);
preg_match('{</'.$matches[1].'>\s*$}', $line) and $element['closed'] = true;
continue;
}
# ~
@@ -415,9 +468,7 @@ class Parsedown
case 'code':
$text = rtrim($element['text'], "\n");
$text = htmlentities($text, ENT_NOQUOTES);
$text = htmlentities($element['text'], ENT_NOQUOTES);
strpos($text, "\x1A\\") !== FALSE and $text = strtr($text, $this->escape_sequence_map);
@@ -446,6 +497,10 @@ class Parsedown
$markup .= '<hr />'."\n";
break;
default:
$markup .= $element['text']."\n";
}
}
@@ -506,8 +561,6 @@ class Parsedown
$element = '<a href="'.$matches[4].'">'.$element_text.'</a>';
}
$element_text = $this->parse_inline_elements($matches[1]);
# ~
$code = "\x1A".'$'.$index;
@@ -526,15 +579,15 @@ class Parsedown
{
foreach ($matches as $matches)
{
$link_difinition = isset($matches[3]) && $matches[3]
$link_definition = isset($matches[3]) && $matches[3]
? $matches[3]
: $matches[2]; # implicit
$link_difinition = strtolower($link_difinition);
$link_definition = strtolower($link_definition);
if (isset($this->reference_map[$link_difinition]))
if (isset($this->reference_map[$link_definition]))
{
$url = $this->reference_map[$link_difinition];
$url = $this->reference_map[$link_definition];
if ($matches[1]) # image
{

15
tests/data/html.html Normal file
View File

@@ -0,0 +1,15 @@
<p>Self-closing tag:</p>
<hr/>
<p>Self-closing tag with attributes:</p>
<hr style="background: #eaa" />
<p>Bare element:</p>
<div>content</div>
<p>Element with attributes:</p>
<a href="http://parsedown.org">link</a>
<p>Nested elements:</p>
<div>
parent
<div>
child
</div>
</div>

24
tests/data/html.md Normal file
View File

@@ -0,0 +1,24 @@
Self-closing tag:
<hr/>
Self-closing tag with attributes:
<hr style="background: #eaa" />
Bare element:
<div>content</div>
Element with attributes:
<a href="http://parsedown.org">link</a>
Nested elements:
<div>
parent
<div>
child
</div>
</div>