From d25466fa8fbead5d006d49b3db890c2c96965408 Mon Sep 17 00:00:00 2001 From: Haralan Dobrev Date: Thu, 6 Feb 2014 10:56:44 +0200 Subject: [PATCH] Allow a single space in the code span delimiter Fix #89 properly. --- Parsedown.php | 4 ++-- tests/data/code_span.html | 6 +++++- tests/data/code_span.md | 10 +++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 3f74776..e140121 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -1028,9 +1028,9 @@ class Parsedown case '`': - if (preg_match('/^(`+)[ ]*(.+?)[ ]*\1(?!`)/', $text, $matches)) + if (preg_match('/^(`+)([ ]?)(.+?)\2\1(?!`)/', $text, $matches)) { - $element_text = $matches[2]; + $element_text = $matches[3]; $element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8'); $markup .= ''.$element_text.''; diff --git a/tests/data/code_span.html b/tests/data/code_span.html index 351610a..d3ff49a 100644 --- a/tests/data/code_span.html +++ b/tests/data/code_span.html @@ -2,4 +2,8 @@

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`

\ No newline at end of file +

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

+

Trim spaces: code

+

Multiple spaces: like that

+

Unequal number of spaces: like that

+

Space only at the beginning: code

\ No newline at end of file diff --git a/tests/data/code_span.md b/tests/data/code_span.md index 0654262..6db4222 100644 --- a/tests/data/code_span.md +++ b/tests/data/code_span.md @@ -6,4 +6,12 @@ a `code span` single backtick in a code span: `` ` `` -backtick-delimited string in a code span: `` `foo` `` \ No newline at end of file +backtick-delimited string in a code span: `` `foo` `` + +Trim spaces: `` code `` + +Multiple spaces: `` like that `` + +Unequal number of spaces: `` like that `` + +Space only at the beginning: `` code`` \ No newline at end of file