diff --git a/Parsedown.php b/Parsedown.php index e9a8cbd..7be569c 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -59,6 +59,11 @@ class Parsedown private $breaksEnabled; + /** + * @var boolean If true HTML is escaped + */ + private $noMarkup = false; + function setBreaksEnabled($breaksEnabled) { $this->breaksEnabled = $breaksEnabled; @@ -66,6 +71,19 @@ class Parsedown return $this; } + /** + * Set the `noMarkup` option + * + * @param boolean $noMarkup If true HTML is escaped + * @return $this + */ + function setNoMarkup($noMarkup) + { + $this->noMarkup = (bool) $noMarkup; + + return $this; + } + # # Lines # @@ -619,6 +637,11 @@ class Parsedown protected function identifyMarkup($Line) { + if ($this->noMarkup) + { + return null; + } + if (preg_match('/^<(\w[\w\d]*)(?:[ ][^>]*)?(\/?)[ ]*>/', $Line['text'], $matches)) { if (in_array($matches[1], $this->textLevelElements)) @@ -1144,6 +1167,11 @@ class Parsedown protected function identifyTag($Excerpt) { + if ($this->noMarkup) + { + return null; + } + if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<\/?\w.*?>/', $Excerpt['text'], $matches)) { return array( diff --git a/test/Test.php b/test/Test.php index 5171d84..7b60def 100644 --- a/test/Test.php +++ b/test/Test.php @@ -62,4 +62,46 @@ class Test extends PHPUnit_Framework_TestCase return $data; } + + public function test_no_markup() + { + $markdownWithHtml = <<_content_ + +sparse: + +
+
+_content_ +
+
+ +paragraph + + +MARKDOWN_WITH_MARKUP; + + $expectedHtml = <<<div>content</div>

+

sparse:

+

<div> +<div class="inner"> +content +</div> +</div>

+

paragraph

+

<style type="text/css">

+
p {
+    color: red;
+}
+

</style>

+EXPECTED_HTML; + $parsedownWithNoMarkup = new Parsedown(); + $parsedownWithNoMarkup->setNoMarkup(true); + $this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml)); + } }