From d4065703302638a8a0529787ab804bd270d0b497 Mon Sep 17 00:00:00 2001 From: naNuke Date: Mon, 2 Jun 2014 06:29:16 +0000 Subject: [PATCH 1/6] HtmlEscaping and SafeLinks --- Parsedown.php | 73 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index f877c4871..5a3e4160c 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -66,6 +66,43 @@ function setBreaksEnabled($breaksEnabled) return $this; } + private $escapingEnabled; + + function setHtmlEscaping($escapingEnabled) + { + $this->escapingEnabled = $escapingEnabled; + + if ($escapingEnabled) + { + // Unset all cases of < recognition as block type. + unset($this->BlockTypes['<']); + + // Remove tag identifier from < span type. + $spanKey = array_search('Tag', $this->SpanTypes['<']); + unset($this->SpanTypes['<'][$spanKey], $spanKey); + } + else + { + // Set < recognition into block types. + $this->BlockTypes['<'] = array('Comment', 'Markup'); + + // Set tag identifier into span types. + // On position 2, after EmailTag + array_splice($this->SpanTypes['<'], 2, 0, 'Tag'); + } + + return $this; + } + + private $safeLinksEnabled; + + function setSafeLinks($safeLinksEnabled) + { + $this->safeLinksEnabled = $safeLinksEnabled; + + return $this; + } + # # Lines # @@ -946,6 +983,7 @@ protected function elements(array $Elements) '*' => array('Emphasis'), '/' => array('Url'), '<' => array('UrlTag', 'EmailTag', 'Tag', 'LessThan'), + '>' => array('GreaterThan'), '[' => array('Link'), '_' => array('Emphasis'), '`' => array('InlineCode'), @@ -955,7 +993,7 @@ protected function elements(array $Elements) # ~ - protected $spanMarkerList = '*_!&[/`~\\'; # # ~ @@ -1091,10 +1129,20 @@ protected function identifyEscapeSequence($Excerpt) { if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters)) { - return array( - 'markup' => $Excerpt['text'][1], - 'extent' => 2, - ); + if ($this->escapingEnabled && $Excerpt['text'][1] == '>') + { + return array( + 'markup' => '>', + 'extent' => 2, + ); + } + else + { + return array( + 'markup' => $Excerpt['text'][1], + 'extent' => 2, + ); + } } } @@ -1106,6 +1154,14 @@ protected function identifyLessThan() ); } + protected function identifyGreaterThan() + { + return array( + 'markup' => '>', + 'extent' => 1, + ); + } + protected function identifyUrlTag($Excerpt) { if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(https?:[\/]{2}[^\s]+?)>/i', $Excerpt['text'], $matches)) @@ -1229,7 +1285,12 @@ protected function identifyLink($Excerpt) return; } - $url = str_replace(array('&', '<'), array('&', '<'), $Link['url']); + if ($this->safeLinksEnabled && stripos($Link['url'], 'javascript:') !== false) + { + return; + } + + $url = str_replace(array('&', '<', '>'), array('&', '<', '>'), $Link['url']); if ($Excerpt['text'][0] === '!') { From d9a848eba30cc9d73be7cb8521ed61ab78ace80d Mon Sep 17 00:00:00 2001 From: naNuke Date: Mon, 2 Jun 2014 14:48:18 +0000 Subject: [PATCH 2/6] Fix failed test with. --- test/data/special_characters.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/special_characters.html b/test/data/special_characters.html index 8199abc19..3b652c338 100644 --- a/test/data/special_characters.html +++ b/test/data/special_characters.html @@ -1,6 +1,6 @@

AT&T has an ampersand in their name

this & that

-

4 < 5 and 6 > 5

+

4 < 5 and 6 > 5

http://example.com/autolink?a=1&b=2

inline link

reference link

\ No newline at end of file From 335975dbffd49a0a6aa2ddc91e607e6a2255102c Mon Sep 17 00:00:00 2001 From: naNuke Date: Mon, 2 Jun 2014 18:37:48 +0000 Subject: [PATCH 3/6] Additional fixes to escaping mode. --- Parsedown.php | 52 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 5a3e4160c..c39ce89e8 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -70,25 +70,37 @@ function setBreaksEnabled($breaksEnabled) function setHtmlEscaping($escapingEnabled) { - $this->escapingEnabled = $escapingEnabled; - - if ($escapingEnabled) + // Modify parser only if the passed value differs from internal one. + // This prevents running the code again and again when used as one liner with instance() method. + if ($this->escapingEnabled !== $escapingEnabled) { - // Unset all cases of < recognition as block type. - unset($this->BlockTypes['<']); + $this->escapingEnabled = $escapingEnabled; - // Remove tag identifier from < span type. - $spanKey = array_search('Tag', $this->SpanTypes['<']); - unset($this->SpanTypes['<'][$spanKey], $spanKey); - } - else - { - // Set < recognition into block types. - $this->BlockTypes['<'] = array('Comment', 'Markup'); + if ($escapingEnabled) + { + // Find comment and markup identifiers in block types. + $CommentKey = array_search('Comment', $this->BlockTypes['<']); + $MarkupKey = array_search('Markup', $this->BlockTypes['<']); + + // Find tag identifier in span types. + $TagKey = array_search('Tag', $this->SpanTypes['<']); + + // Unset Comment, Markup and Tag. + unset( + $this->BlockTypes['<'][$CommentKey], $CommentKey, + $this->BlockTypes['<'][$MarkupKey], $MarkupKey, + $this->SpanTypes['<'][$TagKey], $TagKey + ); + } + else + { + // Set < recognition into block types. + $this->BlockTypes['<'] = array_merge($this->BlockTypes['<'], array('Comment', 'Markup')); - // Set tag identifier into span types. - // On position 2, after EmailTag - array_splice($this->SpanTypes['<'], 2, 0, 'Tag'); + // Set tag identifier into span types. + // On position 2, after EmailTag + array_splice($this->SpanTypes['<'], 2, 0, 'Tag'); + } } return $this; @@ -129,7 +141,7 @@ function setSafeLinks($safeLinksEnabled) '_' => array('Rule'), '`' => array('FencedCode'), '|' => array('Table'), - '~' => array('FencedCode'), + '~' => array('FencedCode') ); # ~ @@ -988,7 +1000,7 @@ protected function elements(array $Elements) '_' => array('Emphasis'), '`' => array('InlineCode'), '~' => array('Strikethrough'), - '\\' => array('EscapeSequence'), + '\\' => array('EscapeSequence') ); # ~ @@ -1078,7 +1090,7 @@ protected function identifyUrl($Excerpt) if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) { - $url = str_replace(array('&', '<'), array('&', '<'), $matches[0][0]); + $url = str_replace(array('&', '<', '>'), array('&', '<', '>'), $matches[0][0]); return array( 'extent' => strlen($matches[0][0]), @@ -1166,7 +1178,7 @@ protected function identifyUrlTag($Excerpt) { if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(https?:[\/]{2}[^\s]+?)>/i', $Excerpt['text'], $matches)) { - $url = str_replace(array('&', '<'), array('&', '<'), $matches[1]); + $url = str_replace(array('&', '<', '>'), array('&', '<', '>'), $matches[1]); return array( 'extent' => strlen($matches[0]), From 5fd6943841444dee03799bca0b75c05fc43a3a18 Mon Sep 17 00:00:00 2001 From: naNuke Date: Mon, 2 Jun 2014 18:39:36 +0000 Subject: [PATCH 4/6] All current tests in escaping mode. --- test/Test.php | 9 ++++- test/data/HTML_Comment_escaped.html | 5 +++ test/data/HTML_Comment_escaped.html~ | 5 +++ test/data/HTML_Comment_escaped.md | 8 ++++ test/data/aesthetic_table_escaped.html | 18 +++++++++ test/data/aesthetic_table_escaped.md | 4 ++ test/data/aligned_table_escaped.html | 21 +++++++++++ test/data/aligned_table_escaped.md | 4 ++ test/data/atx_heading_escaped.html | 8 ++++ test/data/atx_heading_escaped.md | 15 ++++++++ test/data/automatic_link_escaped.html | 1 + test/data/automatic_link_escaped.md | 1 + test/data/block-level_html_escaped.html | 8 ++++ test/data/block-level_html_escaped.md | 11 ++++++ test/data/code_block_escaped.html | 8 ++++ test/data/code_block_escaped.md | 10 +++++ test/data/code_span_escaped.html | 6 +++ test/data/code_span_escaped.md | 11 ++++++ test/data/compound_blockquote_escaped.html | 9 +++++ test/data/compound_blockquote_escaped.md | 10 +++++ test/data/compound_emphasis_escaped.html | 2 + test/data/compound_emphasis_escaped.md | 4 ++ test/data/compound_list_escaped.html | 12 ++++++ test/data/compound_list_escaped.md | 7 ++++ test/data/deeply_nested_list_escaped.html | 12 ++++++ test/data/deeply_nested_list_escaped.md | 6 +++ test/data/em_strong_escaped.html | 8 ++++ test/data/em_strong_escaped.md | 15 ++++++++ test/data/email_escaped.html | 1 + test/data/email_escaped.md | 1 + test/data/emphasis_escaped.html | 8 ++++ test/data/emphasis_escaped.md | 13 +++++++ test/data/escaping_escaped.html | 4 ++ test/data/escaping_escaped.md | 7 ++++ test/data/fenced_code_block_escaped.html | 6 +++ test/data/fenced_code_block_escaped.md | 14 +++++++ test/data/horizontal_rule_escaped.html | 5 +++ test/data/horizontal_rule_escaped.md | 9 +++++ test/data/html_entity_escaped.html | 1 + test/data/html_entity_escaped.md | 1 + test/data/image_reference_escaped.html | 1 + test/data/image_reference_escaped.md | 3 ++ test/data/image_title_escaped.html | 1 + test/data/image_title_escaped.md | 1 + test/data/implicit_reference_escaped.html | 4 ++ test/data/implicit_reference_escaped.md | 13 +++++++ test/data/inline_link_escaped.html | 4 ++ test/data/inline_link_escaped.md | 7 ++++ test/data/inline_link_title_escaped.html | 1 + test/data/inline_link_title_escaped.md | 1 + test/data/inline_title_escaped.html | 1 + test/data/inline_title_escaped.md | 1 + test/data/lazy_blockquote_escaped.html | 6 +++ test/data/lazy_blockquote_escaped.md | 5 +++ test/data/lazy_list_escaped.html | 4 ++ test/data/lazy_list_escaped.md | 2 + test/data/line_break_escaped.html | 2 + test/data/line_break_escaped.md | 2 + .../multiline_list_paragraph_escaped.html | 7 ++++ test/data/multiline_list_paragraph_escaped.md | 4 ++ .../data/nested_block-level_html_escaped.html | 10 +++++ test/data/nested_block-level_html_escaped.md | 11 ++++++ test/data/ordered_list_escaped.html | 13 +++++++ test/data/ordered_list_escaped.md | 11 ++++++ test/data/paragraph_list_escaped.html | 12 ++++++ test/data/paragraph_list_escaped.md | 9 +++++ test/data/reference_title_escaped.html | 2 + test/data/reference_title_escaped.md | 6 +++ test/data/self-closing_html_escaped.html | 12 ++++++ test/data/self-closing_html_escaped.md | 12 ++++++ test/data/separated_nested_list_escaped.html | 9 +++++ test/data/separated_nested_list_escaped.md | 4 ++ test/data/setext_header_escaped.html | 5 +++ test/data/setext_header_escaped.md | 12 ++++++ test/data/simple_blockquote_escaped.html | 11 ++++++ test/data/simple_blockquote_escaped.md | 7 ++++ test/data/simple_table_escaped.html | 37 +++++++++++++++++++ test/data/simple_table_escaped.md | 11 ++++++ test/data/span-level_html_escaped.html | 5 +++ test/data/span-level_html_escaped.md | 8 ++++ test/data/sparse_dense_list_escaped.html | 7 ++++ test/data/sparse_dense_list_escaped.md | 4 ++ test/data/sparse_list_escaped.html | 15 ++++++++ test/data/sparse_list_escaped.md | 9 +++++ test/data/special_characters_escaped.html | 6 +++ test/data/special_characters_escaped.md | 13 +++++++ test/data/strikethrough_escaped.html | 3 ++ test/data/strikethrough_escaped.md | 5 +++ test/data/strong_em_escaped.html | 6 +++ test/data/strong_em_escaped.md | 11 ++++++ .../data/tab-indented_code_block_escaped.html | 6 +++ test/data/tab-indented_code_block_escaped.md | 6 +++ test/data/table_inline_markdown_escaped.html | 18 +++++++++ test/data/table_inline_markdown_escaped.md | 4 ++ test/data/text_reference_escaped.html | 8 ++++ test/data/text_reference_escaped.md | 21 +++++++++++ test/data/unordered_list_escaped.html | 10 +++++ test/data/unordered_list_escaped.md | 8 ++++ test/data/untidy_table_escaped.html | 18 +++++++++ test/data/untidy_table_escaped.md | 4 ++ test/data/url_autolinking_escaped.html | 3 ++ test/data/url_autolinking_escaped.md | 5 +++ test/data/whitespace_escaped.html | 1 + test/data/whitespace_escaped.md | 5 +++ 104 files changed, 780 insertions(+), 1 deletion(-) create mode 100644 test/data/HTML_Comment_escaped.html create mode 100644 test/data/HTML_Comment_escaped.html~ create mode 100644 test/data/HTML_Comment_escaped.md create mode 100644 test/data/aesthetic_table_escaped.html create mode 100644 test/data/aesthetic_table_escaped.md create mode 100644 test/data/aligned_table_escaped.html create mode 100644 test/data/aligned_table_escaped.md create mode 100644 test/data/atx_heading_escaped.html create mode 100644 test/data/atx_heading_escaped.md create mode 100644 test/data/automatic_link_escaped.html create mode 100644 test/data/automatic_link_escaped.md create mode 100644 test/data/block-level_html_escaped.html create mode 100644 test/data/block-level_html_escaped.md create mode 100644 test/data/code_block_escaped.html create mode 100644 test/data/code_block_escaped.md create mode 100644 test/data/code_span_escaped.html create mode 100644 test/data/code_span_escaped.md create mode 100644 test/data/compound_blockquote_escaped.html create mode 100644 test/data/compound_blockquote_escaped.md create mode 100644 test/data/compound_emphasis_escaped.html create mode 100644 test/data/compound_emphasis_escaped.md create mode 100644 test/data/compound_list_escaped.html create mode 100644 test/data/compound_list_escaped.md create mode 100644 test/data/deeply_nested_list_escaped.html create mode 100644 test/data/deeply_nested_list_escaped.md create mode 100644 test/data/em_strong_escaped.html create mode 100644 test/data/em_strong_escaped.md create mode 100644 test/data/email_escaped.html create mode 100644 test/data/email_escaped.md create mode 100644 test/data/emphasis_escaped.html create mode 100644 test/data/emphasis_escaped.md create mode 100644 test/data/escaping_escaped.html create mode 100644 test/data/escaping_escaped.md create mode 100644 test/data/fenced_code_block_escaped.html create mode 100644 test/data/fenced_code_block_escaped.md create mode 100644 test/data/horizontal_rule_escaped.html create mode 100644 test/data/horizontal_rule_escaped.md create mode 100644 test/data/html_entity_escaped.html create mode 100644 test/data/html_entity_escaped.md create mode 100644 test/data/image_reference_escaped.html create mode 100644 test/data/image_reference_escaped.md create mode 100644 test/data/image_title_escaped.html create mode 100644 test/data/image_title_escaped.md create mode 100644 test/data/implicit_reference_escaped.html create mode 100644 test/data/implicit_reference_escaped.md create mode 100644 test/data/inline_link_escaped.html create mode 100644 test/data/inline_link_escaped.md create mode 100644 test/data/inline_link_title_escaped.html create mode 100644 test/data/inline_link_title_escaped.md create mode 100644 test/data/inline_title_escaped.html create mode 100644 test/data/inline_title_escaped.md create mode 100644 test/data/lazy_blockquote_escaped.html create mode 100644 test/data/lazy_blockquote_escaped.md create mode 100644 test/data/lazy_list_escaped.html create mode 100644 test/data/lazy_list_escaped.md create mode 100644 test/data/line_break_escaped.html create mode 100644 test/data/line_break_escaped.md create mode 100644 test/data/multiline_list_paragraph_escaped.html create mode 100644 test/data/multiline_list_paragraph_escaped.md create mode 100644 test/data/nested_block-level_html_escaped.html create mode 100644 test/data/nested_block-level_html_escaped.md create mode 100644 test/data/ordered_list_escaped.html create mode 100644 test/data/ordered_list_escaped.md create mode 100644 test/data/paragraph_list_escaped.html create mode 100644 test/data/paragraph_list_escaped.md create mode 100644 test/data/reference_title_escaped.html create mode 100644 test/data/reference_title_escaped.md create mode 100644 test/data/self-closing_html_escaped.html create mode 100644 test/data/self-closing_html_escaped.md create mode 100644 test/data/separated_nested_list_escaped.html create mode 100644 test/data/separated_nested_list_escaped.md create mode 100644 test/data/setext_header_escaped.html create mode 100644 test/data/setext_header_escaped.md create mode 100644 test/data/simple_blockquote_escaped.html create mode 100644 test/data/simple_blockquote_escaped.md create mode 100644 test/data/simple_table_escaped.html create mode 100644 test/data/simple_table_escaped.md create mode 100644 test/data/span-level_html_escaped.html create mode 100644 test/data/span-level_html_escaped.md create mode 100644 test/data/sparse_dense_list_escaped.html create mode 100644 test/data/sparse_dense_list_escaped.md create mode 100644 test/data/sparse_list_escaped.html create mode 100644 test/data/sparse_list_escaped.md create mode 100644 test/data/special_characters_escaped.html create mode 100644 test/data/special_characters_escaped.md create mode 100644 test/data/strikethrough_escaped.html create mode 100644 test/data/strikethrough_escaped.md create mode 100644 test/data/strong_em_escaped.html create mode 100644 test/data/strong_em_escaped.md create mode 100644 test/data/tab-indented_code_block_escaped.html create mode 100644 test/data/tab-indented_code_block_escaped.md create mode 100644 test/data/table_inline_markdown_escaped.html create mode 100644 test/data/table_inline_markdown_escaped.md create mode 100644 test/data/text_reference_escaped.html create mode 100644 test/data/text_reference_escaped.md create mode 100644 test/data/unordered_list_escaped.html create mode 100644 test/data/unordered_list_escaped.md create mode 100644 test/data/untidy_table_escaped.html create mode 100644 test/data/untidy_table_escaped.md create mode 100644 test/data/url_autolinking_escaped.html create mode 100644 test/data/url_autolinking_escaped.md create mode 100644 test/data/whitespace_escaped.html create mode 100644 test/data/whitespace_escaped.md diff --git a/test/Test.php b/test/Test.php index 5171d846f..ba4cd4365 100644 --- a/test/Test.php +++ b/test/Test.php @@ -23,7 +23,14 @@ function test_($filename) $expectedMarkup = str_replace("\r\n", "\n", $expectedMarkup); $expectedMarkup = str_replace("\r", "\n", $expectedMarkup); - $actualMarkup = Parsedown::instance()->text($markdown); + if (strpos($filename, '_escaped') !== false) + { + $actualMarkup = Parsedown::instance('escaped')->setHtmlEscaping(true)->text($markdown); + } + else + { + $actualMarkup = Parsedown::instance()->text($markdown); + } $this->assertEquals($expectedMarkup, $actualMarkup); } diff --git a/test/data/HTML_Comment_escaped.html b/test/data/HTML_Comment_escaped.html new file mode 100644 index 000000000..1e24c1712 --- /dev/null +++ b/test/data/HTML_Comment_escaped.html @@ -0,0 +1,5 @@ +

<!-- single line -->

+

paragraph

+

<!-- +multiline -->

+

paragraph

\ No newline at end of file diff --git a/test/data/HTML_Comment_escaped.html~ b/test/data/HTML_Comment_escaped.html~ new file mode 100644 index 000000000..a2afab37d --- /dev/null +++ b/test/data/HTML_Comment_escaped.html~ @@ -0,0 +1,5 @@ +

<!-- single line -->

+

paragraph

+

<!-- +multiline -->

+

paragraph

diff --git a/test/data/HTML_Comment_escaped.md b/test/data/HTML_Comment_escaped.md new file mode 100644 index 000000000..6ddfdb441 --- /dev/null +++ b/test/data/HTML_Comment_escaped.md @@ -0,0 +1,8 @@ + + +paragraph + + + +paragraph \ No newline at end of file diff --git a/test/data/aesthetic_table_escaped.html b/test/data/aesthetic_table_escaped.html new file mode 100644 index 000000000..88e1c2bd4 --- /dev/null +++ b/test/data/aesthetic_table_escaped.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +
header 1header 2
cell 1.1cell 1.2
cell 2.1cell 2.2
\ No newline at end of file diff --git a/test/data/aesthetic_table_escaped.md b/test/data/aesthetic_table_escaped.md new file mode 100644 index 000000000..5245e6c9d --- /dev/null +++ b/test/data/aesthetic_table_escaped.md @@ -0,0 +1,4 @@ +| header 1 | header 2 | +| -------- | -------- | +| cell 1.1 | cell 1.2 | +| cell 2.1 | cell 2.2 | \ No newline at end of file diff --git a/test/data/aligned_table_escaped.html b/test/data/aligned_table_escaped.html new file mode 100644 index 000000000..0657bd172 --- /dev/null +++ b/test/data/aligned_table_escaped.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +
header 1header 2header 2
cell 1.1cell 1.2cell 1.3
cell 2.1cell 2.2cell 2.3
\ No newline at end of file diff --git a/test/data/aligned_table_escaped.md b/test/data/aligned_table_escaped.md new file mode 100644 index 000000000..69a45f90f --- /dev/null +++ b/test/data/aligned_table_escaped.md @@ -0,0 +1,4 @@ +| header 1 | header 2 | header 2 | +| :------- | :------: | -------: | +| cell 1.1 | cell 1.2 | cell 1.3 | +| cell 2.1 | cell 2.2 | cell 2.3 | \ No newline at end of file diff --git a/test/data/atx_heading_escaped.html b/test/data/atx_heading_escaped.html new file mode 100644 index 000000000..22d865de7 --- /dev/null +++ b/test/data/atx_heading_escaped.html @@ -0,0 +1,8 @@ +

h1

+

h2

+

h3

+

h4

+
h5
+
h6
+

closed h1

+

#

\ No newline at end of file diff --git a/test/data/atx_heading_escaped.md b/test/data/atx_heading_escaped.md new file mode 100644 index 000000000..039baaa90 --- /dev/null +++ b/test/data/atx_heading_escaped.md @@ -0,0 +1,15 @@ +# h1 + +## h2 + +### h3 + +#### h4 + +##### h5 + +###### h6 + +# closed h1 # + +# \ No newline at end of file diff --git a/test/data/automatic_link_escaped.html b/test/data/automatic_link_escaped.html new file mode 100644 index 000000000..50a94ba0f --- /dev/null +++ b/test/data/automatic_link_escaped.html @@ -0,0 +1 @@ +

http://example.com

\ No newline at end of file diff --git a/test/data/automatic_link_escaped.md b/test/data/automatic_link_escaped.md new file mode 100644 index 000000000..08d3bf46a --- /dev/null +++ b/test/data/automatic_link_escaped.md @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/block-level_html_escaped.html b/test/data/block-level_html_escaped.html new file mode 100644 index 000000000..c73df668b --- /dev/null +++ b/test/data/block-level_html_escaped.html @@ -0,0 +1,8 @@ +

<div>content</div>

+

sparse:

+

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

+

paragraph

\ No newline at end of file diff --git a/test/data/block-level_html_escaped.md b/test/data/block-level_html_escaped.md new file mode 100644 index 000000000..943e183c3 --- /dev/null +++ b/test/data/block-level_html_escaped.md @@ -0,0 +1,11 @@ +
_content_
+ +sparse: + +
+
+_content_ +
+
+ +paragraph \ No newline at end of file diff --git a/test/data/code_block_escaped.html b/test/data/code_block_escaped.html new file mode 100644 index 000000000..889b02d99 --- /dev/null +++ b/test/data/code_block_escaped.html @@ -0,0 +1,8 @@ +
<?php
+
+$message = 'Hello World!';
+echo $message;
+
+
> not a quote
+- not a list item
+[not a reference]: http://foo.com
\ No newline at end of file diff --git a/test/data/code_block_escaped.md b/test/data/code_block_escaped.md new file mode 100644 index 000000000..2cfc953cc --- /dev/null +++ b/test/data/code_block_escaped.md @@ -0,0 +1,10 @@ + not a quote + - not a list item + [not a reference]: http://foo.com \ No newline at end of file diff --git a/test/data/code_span_escaped.html b/test/data/code_span_escaped.html new file mode 100644 index 000000000..5c4c231e3 --- /dev/null +++ b/test/data/code_span_escaped.html @@ -0,0 +1,6 @@ +

a code span

+

this is also a codespan trailing text

+

and look at this one!

+

single backtick in a code span: `

+

backtick-delimited string in a code span: `foo`

+

sth `` sth

\ No newline at end of file diff --git a/test/data/code_span_escaped.md b/test/data/code_span_escaped.md new file mode 100644 index 000000000..c2f1a7442 --- /dev/null +++ b/test/data/code_span_escaped.md @@ -0,0 +1,11 @@ +a `code span` + +`this is also a codespan` trailing text + +`and look at this one!` + +single backtick in a code span: `` ` `` + +backtick-delimited string in a code span: `` `foo` `` + +`sth `` sth` \ No newline at end of file diff --git a/test/data/compound_blockquote_escaped.html b/test/data/compound_blockquote_escaped.html new file mode 100644 index 000000000..37afb57a4 --- /dev/null +++ b/test/data/compound_blockquote_escaped.html @@ -0,0 +1,9 @@ +
+

header

+

paragraph

+
    +
  • li
  • +
+
+

paragraph

+
\ No newline at end of file diff --git a/test/data/compound_blockquote_escaped.md b/test/data/compound_blockquote_escaped.md new file mode 100644 index 000000000..80c4aed16 --- /dev/null +++ b/test/data/compound_blockquote_escaped.md @@ -0,0 +1,10 @@ +> header +> ------ +> +> paragraph +> +> - li +> +> --- +> +> paragraph \ No newline at end of file diff --git a/test/data/compound_emphasis_escaped.html b/test/data/compound_emphasis_escaped.html new file mode 100644 index 000000000..178dd54ba --- /dev/null +++ b/test/data/compound_emphasis_escaped.html @@ -0,0 +1,2 @@ +

code code

+

codecodecode

\ No newline at end of file diff --git a/test/data/compound_emphasis_escaped.md b/test/data/compound_emphasis_escaped.md new file mode 100644 index 000000000..6fe07f260 --- /dev/null +++ b/test/data/compound_emphasis_escaped.md @@ -0,0 +1,4 @@ +_`code`_ __`code`__ + +*`code`**`code`**`code`* + diff --git a/test/data/compound_list_escaped.html b/test/data/compound_list_escaped.html new file mode 100644 index 000000000..f5593c142 --- /dev/null +++ b/test/data/compound_list_escaped.html @@ -0,0 +1,12 @@ +
    +
  • +

    paragraph

    +

    paragraph

    +
  • +
  • +

    paragraph

    +
    +

    quote

    +
    +
  • +
\ No newline at end of file diff --git a/test/data/compound_list_escaped.md b/test/data/compound_list_escaped.md new file mode 100644 index 000000000..ed7f0c60f --- /dev/null +++ b/test/data/compound_list_escaped.md @@ -0,0 +1,7 @@ +- paragraph + + paragraph + +- paragraph + + > quote \ No newline at end of file diff --git a/test/data/deeply_nested_list_escaped.html b/test/data/deeply_nested_list_escaped.html new file mode 100644 index 000000000..d2c7e5acc --- /dev/null +++ b/test/data/deeply_nested_list_escaped.html @@ -0,0 +1,12 @@ +
    +
  • li +
      +
    • li +
        +
      • li
      • +
      • li
      • +
    • +
    • li
    • +
  • +
  • li
  • +
\ No newline at end of file diff --git a/test/data/deeply_nested_list_escaped.md b/test/data/deeply_nested_list_escaped.md new file mode 100644 index 000000000..76b7552d8 --- /dev/null +++ b/test/data/deeply_nested_list_escaped.md @@ -0,0 +1,6 @@ +- li + - li + - li + - li + - li +- li \ No newline at end of file diff --git a/test/data/em_strong_escaped.html b/test/data/em_strong_escaped.html new file mode 100644 index 000000000..323d60aec --- /dev/null +++ b/test/data/em_strong_escaped.html @@ -0,0 +1,8 @@ +

em strong

+

em strong strong

+

strong em strong

+

strong em strong strong

+

em strong

+

em strong strong

+

strong em strong

+

strong em strong strong

\ No newline at end of file diff --git a/test/data/em_strong_escaped.md b/test/data/em_strong_escaped.md new file mode 100644 index 000000000..9abeb3fd4 --- /dev/null +++ b/test/data/em_strong_escaped.md @@ -0,0 +1,15 @@ +___em strong___ + +___em strong_ strong__ + +__strong _em strong___ + +__strong _em strong_ strong__ + +***em strong*** + +***em strong* strong** + +**strong *em strong*** + +**strong *em strong* strong** \ No newline at end of file diff --git a/test/data/email_escaped.html b/test/data/email_escaped.html new file mode 100644 index 000000000..c40759c96 --- /dev/null +++ b/test/data/email_escaped.html @@ -0,0 +1 @@ +

my email is me@example.com

\ No newline at end of file diff --git a/test/data/email_escaped.md b/test/data/email_escaped.md new file mode 100644 index 000000000..26b7b6cc5 --- /dev/null +++ b/test/data/email_escaped.md @@ -0,0 +1 @@ +my email is \ No newline at end of file diff --git a/test/data/emphasis_escaped.html b/test/data/emphasis_escaped.html new file mode 100644 index 000000000..60ff4bd8b --- /dev/null +++ b/test/data/emphasis_escaped.html @@ -0,0 +1,8 @@ +

underscore, asterisk, one two, three four, a, b

+

strong and em and strong and em

+

line +line +line

+

this_is_not_an_emphasis

+

an empty emphasis __ ** is not an emphasis

+

*mixed *double and single asterisk** spans

\ No newline at end of file diff --git a/test/data/emphasis_escaped.md b/test/data/emphasis_escaped.md new file mode 100644 index 000000000..85b9d2299 --- /dev/null +++ b/test/data/emphasis_escaped.md @@ -0,0 +1,13 @@ +_underscore_, *asterisk*, _one two_, *three four*, _a_, *b* + +**strong** and *em* and **strong** and *em* + +_line +line +line_ + +this_is_not_an_emphasis + +an empty emphasis __ ** is not an emphasis + +*mixed **double and* single asterisk** spans \ No newline at end of file diff --git a/test/data/escaping_escaped.html b/test/data/escaping_escaped.html new file mode 100644 index 000000000..c73b30970 --- /dev/null +++ b/test/data/escaping_escaped.html @@ -0,0 +1,4 @@ +

escaped *emphasis*.

+

escaped \*emphasis\* in a code span

+
escaped \*emphasis\* in a code block
+

\ ` * _ { } [ ] ( ) > # + - . !

\ No newline at end of file diff --git a/test/data/escaping_escaped.md b/test/data/escaping_escaped.md new file mode 100644 index 000000000..164039f80 --- /dev/null +++ b/test/data/escaping_escaped.md @@ -0,0 +1,7 @@ +escaped \*emphasis\*. + +`escaped \*emphasis\* in a code span` + + escaped \*emphasis\* in a code block + +\\ \` \* \_ \{ \} \[ \] \( \) \> \# \+ \- \. \! \ No newline at end of file diff --git a/test/data/fenced_code_block_escaped.html b/test/data/fenced_code_block_escaped.html new file mode 100644 index 000000000..8bdabba96 --- /dev/null +++ b/test/data/fenced_code_block_escaped.html @@ -0,0 +1,6 @@ +
<?php
+
+$message = 'fenced code block';
+echo $message;
+
tilde
+
echo 'language identifier';
\ No newline at end of file diff --git a/test/data/fenced_code_block_escaped.md b/test/data/fenced_code_block_escaped.md new file mode 100644 index 000000000..cbed8ebb5 --- /dev/null +++ b/test/data/fenced_code_block_escaped.md @@ -0,0 +1,14 @@ +``` + +
+
+
+
\ No newline at end of file diff --git a/test/data/horizontal_rule_escaped.md b/test/data/horizontal_rule_escaped.md new file mode 100644 index 000000000..bf461a925 --- /dev/null +++ b/test/data/horizontal_rule_escaped.md @@ -0,0 +1,9 @@ +--- + +- - - + + - - - + +*** + +___ \ No newline at end of file diff --git a/test/data/html_entity_escaped.html b/test/data/html_entity_escaped.html new file mode 100644 index 000000000..4d23e3cd4 --- /dev/null +++ b/test/data/html_entity_escaped.html @@ -0,0 +1 @@ +

& © {

\ No newline at end of file diff --git a/test/data/html_entity_escaped.md b/test/data/html_entity_escaped.md new file mode 100644 index 000000000..ff545ea5c --- /dev/null +++ b/test/data/html_entity_escaped.md @@ -0,0 +1 @@ +& © { \ No newline at end of file diff --git a/test/data/image_reference_escaped.html b/test/data/image_reference_escaped.html new file mode 100644 index 000000000..b3249cba2 --- /dev/null +++ b/test/data/image_reference_escaped.html @@ -0,0 +1 @@ +

Markdown Logo

\ No newline at end of file diff --git a/test/data/image_reference_escaped.md b/test/data/image_reference_escaped.md new file mode 100644 index 000000000..dcb1414dd --- /dev/null +++ b/test/data/image_reference_escaped.md @@ -0,0 +1,3 @@ +![Markdown Logo][image] + +[image]: /md.png diff --git a/test/data/image_title_escaped.html b/test/data/image_title_escaped.html new file mode 100644 index 000000000..82c155f61 --- /dev/null +++ b/test/data/image_title_escaped.html @@ -0,0 +1 @@ +

alt

\ No newline at end of file diff --git a/test/data/image_title_escaped.md b/test/data/image_title_escaped.md new file mode 100644 index 000000000..3e58ee555 --- /dev/null +++ b/test/data/image_title_escaped.md @@ -0,0 +1 @@ +![alt](/md.png "title") \ No newline at end of file diff --git a/test/data/implicit_reference_escaped.html b/test/data/implicit_reference_escaped.html new file mode 100644 index 000000000..24b51c1b0 --- /dev/null +++ b/test/data/implicit_reference_escaped.html @@ -0,0 +1,4 @@ +

an implicit reference link

+

an implicit reference link with an empty link definition

+

an implicit reference link followed by another

+

an explicit reference link with a title

\ No newline at end of file diff --git a/test/data/implicit_reference_escaped.md b/test/data/implicit_reference_escaped.md new file mode 100644 index 000000000..f850df964 --- /dev/null +++ b/test/data/implicit_reference_escaped.md @@ -0,0 +1,13 @@ +an [implicit] reference link + +[implicit]: http://example.com + +an [implicit][] reference link with an empty link definition + +an [implicit][] reference link followed by [another][] + +[another]: http://cnn.com + +an [explicit][example] reference link with a title + +[example]: http://example.com "Example" \ No newline at end of file diff --git a/test/data/inline_link_escaped.html b/test/data/inline_link_escaped.html new file mode 100644 index 000000000..2b9e649d6 --- /dev/null +++ b/test/data/inline_link_escaped.html @@ -0,0 +1,4 @@ +

link and another link

+

link

+

MD Logo

+

MD Logo and text

\ No newline at end of file diff --git a/test/data/inline_link_escaped.md b/test/data/inline_link_escaped.md new file mode 100644 index 000000000..cd8e5a63f --- /dev/null +++ b/test/data/inline_link_escaped.md @@ -0,0 +1,7 @@ +[link](http://example.com) and [another link](/tests/) + +[`link`](http://example.com) + +[![MD Logo](http://parsedown.org/md.png)](http://example.com) + +[![MD Logo](http://parsedown.org/md.png) and text](http://example.com) \ No newline at end of file diff --git a/test/data/inline_link_title_escaped.html b/test/data/inline_link_title_escaped.html new file mode 100644 index 000000000..70e589aa8 --- /dev/null +++ b/test/data/inline_link_title_escaped.html @@ -0,0 +1 @@ +

single quotes and double quotes

\ No newline at end of file diff --git a/test/data/inline_link_title_escaped.md b/test/data/inline_link_title_escaped.md new file mode 100644 index 000000000..162b832ac --- /dev/null +++ b/test/data/inline_link_title_escaped.md @@ -0,0 +1 @@ +[single quotes](http://example.com 'Title') and [double quotes](http://example.com "Title") \ No newline at end of file diff --git a/test/data/inline_title_escaped.html b/test/data/inline_title_escaped.html new file mode 100644 index 000000000..bbab93b6c --- /dev/null +++ b/test/data/inline_title_escaped.html @@ -0,0 +1 @@ +

single quotes and double quotes

\ No newline at end of file diff --git a/test/data/inline_title_escaped.md b/test/data/inline_title_escaped.md new file mode 100644 index 000000000..cb09344a1 --- /dev/null +++ b/test/data/inline_title_escaped.md @@ -0,0 +1 @@ +[single quotes](http://example.com 'Example') and [double quotes](http://example.com "Example") \ No newline at end of file diff --git a/test/data/lazy_blockquote_escaped.html b/test/data/lazy_blockquote_escaped.html new file mode 100644 index 000000000..0a2a2aaf9 --- /dev/null +++ b/test/data/lazy_blockquote_escaped.html @@ -0,0 +1,6 @@ +
+

quote +the rest of it

+

another paragraph +the rest of it

+
\ No newline at end of file diff --git a/test/data/lazy_blockquote_escaped.md b/test/data/lazy_blockquote_escaped.md new file mode 100644 index 000000000..48f645f94 --- /dev/null +++ b/test/data/lazy_blockquote_escaped.md @@ -0,0 +1,5 @@ +> quote +the rest of it + +> another paragraph +the rest of it \ No newline at end of file diff --git a/test/data/lazy_list_escaped.html b/test/data/lazy_list_escaped.html new file mode 100644 index 000000000..1a5199249 --- /dev/null +++ b/test/data/lazy_list_escaped.html @@ -0,0 +1,4 @@ +
    +
  • li +the rest of it
  • +
\ No newline at end of file diff --git a/test/data/lazy_list_escaped.md b/test/data/lazy_list_escaped.md new file mode 100644 index 000000000..62ad9d719 --- /dev/null +++ b/test/data/lazy_list_escaped.md @@ -0,0 +1,2 @@ +- li +the rest of it \ No newline at end of file diff --git a/test/data/line_break_escaped.html b/test/data/line_break_escaped.html new file mode 100644 index 000000000..5f37d854c --- /dev/null +++ b/test/data/line_break_escaped.html @@ -0,0 +1,2 @@ +

line
+line

\ No newline at end of file diff --git a/test/data/line_break_escaped.md b/test/data/line_break_escaped.md new file mode 100644 index 000000000..04dff43e0 --- /dev/null +++ b/test/data/line_break_escaped.md @@ -0,0 +1,2 @@ +line +line \ No newline at end of file diff --git a/test/data/multiline_list_paragraph_escaped.html b/test/data/multiline_list_paragraph_escaped.html new file mode 100644 index 000000000..3247bd227 --- /dev/null +++ b/test/data/multiline_list_paragraph_escaped.html @@ -0,0 +1,7 @@ +
    +
  • +

    li

    +

    line +line

    +
  • +
\ No newline at end of file diff --git a/test/data/multiline_list_paragraph_escaped.md b/test/data/multiline_list_paragraph_escaped.md new file mode 100644 index 000000000..f5b42729f --- /dev/null +++ b/test/data/multiline_list_paragraph_escaped.md @@ -0,0 +1,4 @@ +- li + + line + line \ No newline at end of file diff --git a/test/data/nested_block-level_html_escaped.html b/test/data/nested_block-level_html_escaped.html new file mode 100644 index 000000000..e6474c3ea --- /dev/null +++ b/test/data/nested_block-level_html_escaped.html @@ -0,0 +1,10 @@ +

<div> +parent +<div> +child +</div> +<pre> +adopted child +</pre> +</div>

+

outside

\ No newline at end of file diff --git a/test/data/nested_block-level_html_escaped.md b/test/data/nested_block-level_html_escaped.md new file mode 100644 index 000000000..5e01e1097 --- /dev/null +++ b/test/data/nested_block-level_html_escaped.md @@ -0,0 +1,11 @@ +
+_parent_ +
+_child_ +
+
+_adopted child_
+
+
+ +_outside_ \ No newline at end of file diff --git a/test/data/ordered_list_escaped.html b/test/data/ordered_list_escaped.html new file mode 100644 index 000000000..b6c5216ca --- /dev/null +++ b/test/data/ordered_list_escaped.html @@ -0,0 +1,13 @@ +
    +
  1. one
  2. +
  3. two
  4. +
+

repeating numbers:

+
    +
  1. one
  2. +
  3. two
  4. +
+

large numbers:

+
    +
  1. one
  2. +
\ No newline at end of file diff --git a/test/data/ordered_list_escaped.md b/test/data/ordered_list_escaped.md new file mode 100644 index 000000000..b307032cf --- /dev/null +++ b/test/data/ordered_list_escaped.md @@ -0,0 +1,11 @@ +1. one +2. two + +repeating numbers: + +1. one +1. two + +large numbers: + +123. one \ No newline at end of file diff --git a/test/data/paragraph_list_escaped.html b/test/data/paragraph_list_escaped.html new file mode 100644 index 000000000..ced1c43ee --- /dev/null +++ b/test/data/paragraph_list_escaped.html @@ -0,0 +1,12 @@ +

paragraph

+
    +
  • li
  • +
  • li
  • +
+

paragraph

+
    +
  • +

    li

    +
  • +
  • li
  • +
\ No newline at end of file diff --git a/test/data/paragraph_list_escaped.md b/test/data/paragraph_list_escaped.md new file mode 100644 index 000000000..b973908ce --- /dev/null +++ b/test/data/paragraph_list_escaped.md @@ -0,0 +1,9 @@ +paragraph +- li +- li + +paragraph + + * li + + * li \ No newline at end of file diff --git a/test/data/reference_title_escaped.html b/test/data/reference_title_escaped.html new file mode 100644 index 000000000..8f2be944c --- /dev/null +++ b/test/data/reference_title_escaped.html @@ -0,0 +1,2 @@ +

double quotes and single quotes and parentheses

+

[invalid title]: http://example.com example title

\ No newline at end of file diff --git a/test/data/reference_title_escaped.md b/test/data/reference_title_escaped.md new file mode 100644 index 000000000..43cb21708 --- /dev/null +++ b/test/data/reference_title_escaped.md @@ -0,0 +1,6 @@ +[double quotes] and [single quotes] and [parentheses] + +[double quotes]: http://example.com "example title" +[single quotes]: http://example.com 'example title' +[parentheses]: http://example.com (example title) +[invalid title]: http://example.com example title \ No newline at end of file diff --git a/test/data/self-closing_html_escaped.html b/test/data/self-closing_html_escaped.html new file mode 100644 index 000000000..df415ebb9 --- /dev/null +++ b/test/data/self-closing_html_escaped.html @@ -0,0 +1,12 @@ +

<hr> +paragraph +<hr/> +paragraph +<hr /> +paragraph +<hr class="foo" id="bar" /> +paragraph +<hr class="foo" id="bar"/> +paragraph +<hr class="foo" id="bar" > +paragraph

\ No newline at end of file diff --git a/test/data/self-closing_html_escaped.md b/test/data/self-closing_html_escaped.md new file mode 100644 index 000000000..acb20327d --- /dev/null +++ b/test/data/self-closing_html_escaped.md @@ -0,0 +1,12 @@ +
+paragraph +
+paragraph +
+paragraph +
+paragraph +
+paragraph +
+paragraph \ No newline at end of file diff --git a/test/data/separated_nested_list_escaped.html b/test/data/separated_nested_list_escaped.html new file mode 100644 index 000000000..80a5cae26 --- /dev/null +++ b/test/data/separated_nested_list_escaped.html @@ -0,0 +1,9 @@ +
    +
  • +

    li

    +
      +
    • li
    • +
    • li
    • +
    +
  • +
\ No newline at end of file diff --git a/test/data/separated_nested_list_escaped.md b/test/data/separated_nested_list_escaped.md new file mode 100644 index 000000000..d7cd1af79 --- /dev/null +++ b/test/data/separated_nested_list_escaped.md @@ -0,0 +1,4 @@ +- li + + - li + - li \ No newline at end of file diff --git a/test/data/setext_header_escaped.html b/test/data/setext_header_escaped.html new file mode 100644 index 000000000..60aac0815 --- /dev/null +++ b/test/data/setext_header_escaped.html @@ -0,0 +1,5 @@ +

h1

+

h2

+

single character

+

not a header

+
\ No newline at end of file diff --git a/test/data/setext_header_escaped.md b/test/data/setext_header_escaped.md new file mode 100644 index 000000000..c43b52c36 --- /dev/null +++ b/test/data/setext_header_escaped.md @@ -0,0 +1,12 @@ +h1 +== + +h2 +-- + +single character +- + +not a header + +------------ \ No newline at end of file diff --git a/test/data/simple_blockquote_escaped.html b/test/data/simple_blockquote_escaped.html new file mode 100644 index 000000000..8225d57cc --- /dev/null +++ b/test/data/simple_blockquote_escaped.html @@ -0,0 +1,11 @@ +
+

quote

+
+

indented:

+
+

quote

+
+

no space after >:

+
+

quote

+
\ No newline at end of file diff --git a/test/data/simple_blockquote_escaped.md b/test/data/simple_blockquote_escaped.md new file mode 100644 index 000000000..22b6b11a9 --- /dev/null +++ b/test/data/simple_blockquote_escaped.md @@ -0,0 +1,7 @@ +> quote + +indented: + > quote + +no space after `>`: +>quote \ No newline at end of file diff --git a/test/data/simple_table_escaped.html b/test/data/simple_table_escaped.html new file mode 100644 index 000000000..64b7a9a23 --- /dev/null +++ b/test/data/simple_table_escaped.html @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + +
header 1header 2
cell 1.1cell 1.2
cell 2.1cell 2.2
+
+ + + + + + + + + + + + + + + + + +
header 1header 2
cell 1.1cell 1.2
cell 2.1cell 2.2
\ No newline at end of file diff --git a/test/data/simple_table_escaped.md b/test/data/simple_table_escaped.md new file mode 100644 index 000000000..466d140e3 --- /dev/null +++ b/test/data/simple_table_escaped.md @@ -0,0 +1,11 @@ +header 1 | header 2 +-------- | -------- +cell 1.1 | cell 1.2 +cell 2.1 | cell 2.2 + +--- + +header 1 | header 2 +:------- | -------- +cell 1.1 | cell 1.2 +cell 2.1 | cell 2.2 \ No newline at end of file diff --git a/test/data/span-level_html_escaped.html b/test/data/span-level_html_escaped.html new file mode 100644 index 000000000..e24d6522d --- /dev/null +++ b/test/data/span-level_html_escaped.html @@ -0,0 +1,5 @@ +

an <b>important</b> <a href=''>link</a>

+

broken<br/> +line

+

<b>inline tag</b> at the beginning

+

<span>http://example.com</span>

\ No newline at end of file diff --git a/test/data/span-level_html_escaped.md b/test/data/span-level_html_escaped.md new file mode 100644 index 000000000..f22196555 --- /dev/null +++ b/test/data/span-level_html_escaped.md @@ -0,0 +1,8 @@ +an important link + +broken
+line + +inline tag at the beginning + +http://example.com \ No newline at end of file diff --git a/test/data/sparse_dense_list_escaped.html b/test/data/sparse_dense_list_escaped.html new file mode 100644 index 000000000..095bc7396 --- /dev/null +++ b/test/data/sparse_dense_list_escaped.html @@ -0,0 +1,7 @@ +
    +
  • +

    li

    +
  • +
  • li
  • +
  • li
  • +
\ No newline at end of file diff --git a/test/data/sparse_dense_list_escaped.md b/test/data/sparse_dense_list_escaped.md new file mode 100644 index 000000000..576842277 --- /dev/null +++ b/test/data/sparse_dense_list_escaped.md @@ -0,0 +1,4 @@ +- li + +- li +- li \ No newline at end of file diff --git a/test/data/sparse_list_escaped.html b/test/data/sparse_list_escaped.html new file mode 100644 index 000000000..452b2b86d --- /dev/null +++ b/test/data/sparse_list_escaped.html @@ -0,0 +1,15 @@ +
    +
  • +

    li

    +
  • +
  • li
  • +
+
+
    +
  • +

    li

    +
      +
    • indented li
    • +
    +
  • +
\ No newline at end of file diff --git a/test/data/sparse_list_escaped.md b/test/data/sparse_list_escaped.md new file mode 100644 index 000000000..362a35f57 --- /dev/null +++ b/test/data/sparse_list_escaped.md @@ -0,0 +1,9 @@ +- li + +- li + +--- + +- li + + - indented li \ No newline at end of file diff --git a/test/data/special_characters_escaped.html b/test/data/special_characters_escaped.html new file mode 100644 index 000000000..3b652c338 --- /dev/null +++ b/test/data/special_characters_escaped.html @@ -0,0 +1,6 @@ +

AT&T has an ampersand in their name

+

this & that

+

4 < 5 and 6 > 5

+

http://example.com/autolink?a=1&b=2

+

inline link

+

reference link

\ No newline at end of file diff --git a/test/data/special_characters_escaped.md b/test/data/special_characters_escaped.md new file mode 100644 index 000000000..111b03b63 --- /dev/null +++ b/test/data/special_characters_escaped.md @@ -0,0 +1,13 @@ +AT&T has an ampersand in their name + +this & that + +4 < 5 and 6 > 5 + + + +[inline link](/script?a=1&b=2) + +[reference link][1] + +[1]: http://example.com/?a=1&b=2 \ No newline at end of file diff --git a/test/data/strikethrough_escaped.html b/test/data/strikethrough_escaped.html new file mode 100644 index 000000000..2a9da9821 --- /dev/null +++ b/test/data/strikethrough_escaped.html @@ -0,0 +1,3 @@ +

strikethrough

+

here's one followed by another one

+

~~ this ~~ is not one neither is ~this~

\ No newline at end of file diff --git a/test/data/strikethrough_escaped.md b/test/data/strikethrough_escaped.md new file mode 100644 index 000000000..d169144d2 --- /dev/null +++ b/test/data/strikethrough_escaped.md @@ -0,0 +1,5 @@ +~~strikethrough~~ + +here's ~~one~~ followed by ~~another one~~ + +~~ this ~~ is not one neither is ~this~ \ No newline at end of file diff --git a/test/data/strong_em_escaped.html b/test/data/strong_em_escaped.html new file mode 100644 index 000000000..b709c9914 --- /dev/null +++ b/test/data/strong_em_escaped.html @@ -0,0 +1,6 @@ +

em strong em

+

strong em em

+

em strong em em

+

em strong em

+

strong em em

+

em strong em em

\ No newline at end of file diff --git a/test/data/strong_em_escaped.md b/test/data/strong_em_escaped.md new file mode 100644 index 000000000..f2aa3c782 --- /dev/null +++ b/test/data/strong_em_escaped.md @@ -0,0 +1,11 @@ +*em **strong em*** + +***strong em** em* + +*em **strong em** em* + +_em __strong em___ + +___strong em__ em_ + +_em __strong em__ em_ \ No newline at end of file diff --git a/test/data/tab-indented_code_block_escaped.html b/test/data/tab-indented_code_block_escaped.html new file mode 100644 index 000000000..7c140de73 --- /dev/null +++ b/test/data/tab-indented_code_block_escaped.html @@ -0,0 +1,6 @@ +
<?php
+
+$message = 'Hello World!';
+echo $message;
+
+echo "following a blank line";
\ No newline at end of file diff --git a/test/data/tab-indented_code_block_escaped.md b/test/data/tab-indented_code_block_escaped.md new file mode 100644 index 000000000..a405a1609 --- /dev/null +++ b/test/data/tab-indented_code_block_escaped.md @@ -0,0 +1,6 @@ + + + +header 1 +header 2 + + + + +cell 1.1 +cell 1.2 + + +cell 2.1 +cell 2.2 + + + \ No newline at end of file diff --git a/test/data/table_inline_markdown_escaped.md b/test/data/table_inline_markdown_escaped.md new file mode 100644 index 000000000..c2fe1080c --- /dev/null +++ b/test/data/table_inline_markdown_escaped.md @@ -0,0 +1,4 @@ +| _header_ 1 | header 2 | +| ------------ | ------------ | +| _cell_ 1.1 | ~~cell~~ 1.2 | +| `cell` 2.1 | cell 2.2 | \ No newline at end of file diff --git a/test/data/text_reference_escaped.html b/test/data/text_reference_escaped.html new file mode 100644 index 000000000..11e4d37ff --- /dev/null +++ b/test/data/text_reference_escaped.html @@ -0,0 +1,8 @@ +

reference link

+

one with a semantic name

+

[one][404] with no definition

+

multiline +one defined on 2 lines

+

one with a mixed case label and an upper case definition

+

one with the a label on the next line

+

link

\ No newline at end of file diff --git a/test/data/text_reference_escaped.md b/test/data/text_reference_escaped.md new file mode 100644 index 000000000..1a66a5cf6 --- /dev/null +++ b/test/data/text_reference_escaped.md @@ -0,0 +1,21 @@ +[reference link][1] + +[1]: http://example.com + +[one][website] with a semantic name + +[website]: http://example.com + +[one][404] with no definition + +[multiline +one][website] defined on 2 lines + +[one][Label] with a mixed case label and an upper case definition + +[LABEL]: http://example.com + +[one] +[1] with the a label on the next line + +[`link`][website] \ No newline at end of file diff --git a/test/data/unordered_list_escaped.html b/test/data/unordered_list_escaped.html new file mode 100644 index 000000000..cd95567b7 --- /dev/null +++ b/test/data/unordered_list_escaped.html @@ -0,0 +1,10 @@ +
    +
  • li
  • +
  • li
  • +
+

mixed markers:

+
    +
  • li
  • +
  • li
  • +
  • li
  • +
\ No newline at end of file diff --git a/test/data/unordered_list_escaped.md b/test/data/unordered_list_escaped.md new file mode 100644 index 000000000..cf62c99f2 --- /dev/null +++ b/test/data/unordered_list_escaped.md @@ -0,0 +1,8 @@ +- li +- li + +mixed markers: + +* li ++ li +- li \ No newline at end of file diff --git a/test/data/untidy_table_escaped.html b/test/data/untidy_table_escaped.html new file mode 100644 index 000000000..88e1c2bd4 --- /dev/null +++ b/test/data/untidy_table_escaped.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +
header 1header 2
cell 1.1cell 1.2
cell 2.1cell 2.2
\ No newline at end of file diff --git a/test/data/untidy_table_escaped.md b/test/data/untidy_table_escaped.md new file mode 100644 index 000000000..8524eb184 --- /dev/null +++ b/test/data/untidy_table_escaped.md @@ -0,0 +1,4 @@ +| header 1 | header 2 | +| ------------- | ----------- | +| cell 1.1 | cell 1.2 | +| cell 2.1 | cell 2.2 | \ No newline at end of file diff --git a/test/data/url_autolinking_escaped.html b/test/data/url_autolinking_escaped.html new file mode 100644 index 000000000..58ca94c6b --- /dev/null +++ b/test/data/url_autolinking_escaped.html @@ -0,0 +1,3 @@ +

an autolink http://example.com

+

inside of brackets [http://example.com], inside of braces {http://example.com}, inside of parentheses (http://example.com)

+

trailing slash http://example.com/ and http://example.com/path/

\ No newline at end of file diff --git a/test/data/url_autolinking_escaped.md b/test/data/url_autolinking_escaped.md new file mode 100644 index 000000000..840f35404 --- /dev/null +++ b/test/data/url_autolinking_escaped.md @@ -0,0 +1,5 @@ +an autolink http://example.com + +inside of brackets [http://example.com], inside of braces {http://example.com}, inside of parentheses (http://example.com) + +trailing slash http://example.com/ and http://example.com/path/ \ No newline at end of file diff --git a/test/data/whitespace_escaped.html b/test/data/whitespace_escaped.html new file mode 100644 index 000000000..f2dd7a002 --- /dev/null +++ b/test/data/whitespace_escaped.html @@ -0,0 +1 @@ +
code
\ No newline at end of file diff --git a/test/data/whitespace_escaped.md b/test/data/whitespace_escaped.md new file mode 100644 index 000000000..4cf926a8a --- /dev/null +++ b/test/data/whitespace_escaped.md @@ -0,0 +1,5 @@ + + + code + + \ No newline at end of file From dc367c1dd1f12ee9f5704e3e5ca7a2b52df9f019 Mon Sep 17 00:00:00 2001 From: naNuke Date: Mon, 2 Jun 2014 20:42:26 +0000 Subject: [PATCH 5/6] Removing stray hidden file. --- test/data/HTML_Comment_escaped.html~ | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 test/data/HTML_Comment_escaped.html~ diff --git a/test/data/HTML_Comment_escaped.html~ b/test/data/HTML_Comment_escaped.html~ deleted file mode 100644 index a2afab37d..000000000 --- a/test/data/HTML_Comment_escaped.html~ +++ /dev/null @@ -1,5 +0,0 @@ -

<!-- single line -->

-

paragraph

-

<!-- -multiline -->

-

paragraph

From 10f62ddeb7947f320d9765ddc0bfa7746fc9d9f1 Mon Sep 17 00:00:00 2001 From: naNuke Date: Mon, 2 Jun 2014 21:33:02 +0000 Subject: [PATCH 6/6] Change escaping setter to set variable only. Blocking identifiers in the specific methods instead. --- Parsedown.php | 52 ++++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index c39ce89e8..75ba01464 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -70,38 +70,7 @@ function setBreaksEnabled($breaksEnabled) function setHtmlEscaping($escapingEnabled) { - // Modify parser only if the passed value differs from internal one. - // This prevents running the code again and again when used as one liner with instance() method. - if ($this->escapingEnabled !== $escapingEnabled) - { - $this->escapingEnabled = $escapingEnabled; - - if ($escapingEnabled) - { - // Find comment and markup identifiers in block types. - $CommentKey = array_search('Comment', $this->BlockTypes['<']); - $MarkupKey = array_search('Markup', $this->BlockTypes['<']); - - // Find tag identifier in span types. - $TagKey = array_search('Tag', $this->SpanTypes['<']); - - // Unset Comment, Markup and Tag. - unset( - $this->BlockTypes['<'][$CommentKey], $CommentKey, - $this->BlockTypes['<'][$MarkupKey], $MarkupKey, - $this->SpanTypes['<'][$TagKey], $TagKey - ); - } - else - { - // Set < recognition into block types. - $this->BlockTypes['<'] = array_merge($this->BlockTypes['<'], array('Comment', 'Markup')); - - // Set tag identifier into span types. - // On position 2, after EmailTag - array_splice($this->SpanTypes['<'], 2, 0, 'Tag'); - } - } + $this->escapingEnabled = $escapingEnabled; return $this; } @@ -399,6 +368,11 @@ protected function completeCodeBlock($Block) protected function identifyComment($Line) { + if ($this->escapingEnabled) + { + return; + } + if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!') { $Block = array( @@ -416,7 +390,7 @@ protected function identifyComment($Line) protected function addToComment($Line, array $Block) { - if (isset($Block['closed'])) + if (isset($Block['closed']) || $this->escapingEnabled) { return; } @@ -668,6 +642,11 @@ protected function identifySetext($Line, array $Block = null) protected function identifyMarkup($Line) { + if ($this->escapingEnabled) + { + return; + } + if (preg_match('/^<(\w[\w\d]*)(?:[ ][^>\/]*)?(\/?)[ ]*>/', $Line['text'], $matches)) { if (in_array($matches[1], $this->textLevelElements)) @@ -695,7 +674,7 @@ protected function identifyMarkup($Line) protected function addToMarkup($Line, array $Block) { - if (isset($Block['closed'])) + if (isset($Block['closed']) || $this->escapingEnabled) { return; } @@ -1212,6 +1191,11 @@ protected function identifyEmailTag($Excerpt) protected function identifyTag($Excerpt) { + if ($this->escapingEnabled) + { + return; + } + if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<\/?\w.*?>/', $Excerpt['text'], $matches)) { return array(