From f5dd3455f9addd5740aea6e9cae9af073142f609 Mon Sep 17 00:00:00 2001 From: Emanuil Rusev Date: Sun, 19 Jan 2014 00:52:07 +0200 Subject: [PATCH] resolve #58 --- Parsedown.php | 13 +++++++++++-- tests/data/html_entity.html | 1 + tests/data/html_entity.md | 1 + tests/data/special_characters.html | 1 - tests/data/special_characters.md | 2 -- 5 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 tests/data/html_entity.html create mode 100644 tests/data/html_entity.md diff --git a/Parsedown.php b/Parsedown.php index b7f4714..77642fe 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -825,9 +825,18 @@ class Parsedown case '&': - $markup .= '&'; + if (preg_match('/^&#?\w+;/', $text, $matches)) + { + $markup .= $matches[0]; - $offset = substr($text, 0, 5) === '&' ? 5 : 1; + $offset = strlen($matches[0]); + } + else + { + $markup .= '&'; + + $offset = 1; + } break; diff --git a/tests/data/html_entity.html b/tests/data/html_entity.html new file mode 100644 index 0000000..4d23e3c --- /dev/null +++ b/tests/data/html_entity.html @@ -0,0 +1 @@ +

& © {

\ No newline at end of file diff --git a/tests/data/html_entity.md b/tests/data/html_entity.md new file mode 100644 index 0000000..ff545ea --- /dev/null +++ b/tests/data/html_entity.md @@ -0,0 +1 @@ +& © { \ No newline at end of file diff --git a/tests/data/special_characters.html b/tests/data/special_characters.html index 7cebe8a..79fad4c 100644 --- a/tests/data/special_characters.html +++ b/tests/data/special_characters.html @@ -1,5 +1,4 @@

AT&T has an ampersand in their name

-

AT&T is another way to write it

this & that

4 < 5 and 6 > 5

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

diff --git a/tests/data/special_characters.md b/tests/data/special_characters.md index d91adc5..13597e6 100644 --- a/tests/data/special_characters.md +++ b/tests/data/special_characters.md @@ -1,7 +1,5 @@ AT&T has an ampersand in their name -AT&T is another way to write it - this & that 4 < 5 and 6 > 5