diff --git a/Parsedown.php b/Parsedown.php index 319548b..47484d8 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -122,6 +122,27 @@ class Parsedown foreach ($lines as $line) { + # Block-Level HTML + + if ($element['type'] === 'block' and ! isset($element['closed'])) + { + if (preg_match('{<'.$element['subtype'].'>$}', $line)) # + { + $element['depth']++; + } + + if (preg_match('{$}', $line)) # + { + $element['depth'] > 0 + ? $element['depth']-- + : $element['closed'] = true; + } + + $element['text'] .= "\n".$line; + + continue; + } + # Empty if ($line === '') @@ -322,6 +343,38 @@ class Parsedown continue; } + + # Block-Level HTML + + if (preg_match('{^<.+?/>$}', $line)) + { + $elements []= $element; + + $element = array( + 'type' => '', + 'text' => $line, + ); + + continue; + } + + # Block-Level HTML + + if (preg_match('{^<(\w+)(?:[ ].*?)?>}', $line, $matches)) + { + $elements []= $element; + + $element = array( + 'type' => 'block', + 'subtype' => strtolower($matches[1]), + 'text' => $line, + 'depth' => 0, + ); + + preg_match('{\s*$}', $line) and $element['closed'] = true; + + continue; + } # ~ @@ -444,6 +497,10 @@ class Parsedown $markup .= '
'."\n"; break; + + default: + + $markup .= $element['text']."\n"; } } diff --git a/tests/data/html.html b/tests/data/html.html new file mode 100644 index 0000000..2e0bf1b --- /dev/null +++ b/tests/data/html.html @@ -0,0 +1,15 @@ +

Self-closing tag:

+
+

Self-closing tag with attributes:

+
+

Bare element:

+
content
+

Element with attributes:

+link +

Nested elements:

+
+parent +
+child +
+
\ No newline at end of file diff --git a/tests/data/html.md b/tests/data/html.md new file mode 100644 index 0000000..f0f01cb --- /dev/null +++ b/tests/data/html.md @@ -0,0 +1,24 @@ +Self-closing tag: + +
+ +Self-closing tag with attributes: + +
+ +Bare element: + +
content
+ +Element with attributes: + +link + +Nested elements: + +
+parent +
+child +
+
\ No newline at end of file