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`
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