mirror of
https://github.com/KnpLabs/KnpMarkdownBundle.git
synced 2024-06-21 07:05:05 +02:00
Use no_html option on the parser itself
Just escaping the text before feeding it into the parser messes up markdown quote blocks, since markdown uses > for quoting, and escaping that turns it into >, which does not get parsed correctly.
This commit is contained in:
parent
c31f07b28d
commit
8b30483894
|
@ -104,6 +104,9 @@ class MarkdownParser extends MarkdownExtra implements MarkdownParserInterface
|
|||
if (!$this->features['entities'] && !$this->features['no_html']) {
|
||||
$this->no_entities = true;
|
||||
}
|
||||
if ($this->features['no_html']) {
|
||||
$this->no_html = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,10 +114,6 @@ class MarkdownParser extends MarkdownExtra implements MarkdownParserInterface
|
|||
*/
|
||||
public function transformMarkdown($text)
|
||||
{
|
||||
if ($this->features['no_html']) {
|
||||
$text = htmlspecialchars($text, ENT_NOQUOTES);
|
||||
}
|
||||
|
||||
return parent::transform($text);
|
||||
}
|
||||
|
||||
|
@ -242,31 +241,4 @@ class MarkdownParser extends MarkdownExtra implements MarkdownParserInterface
|
|||
|
||||
return $text;
|
||||
}
|
||||
|
||||
public function _doCodeBlocks_callback($matches)
|
||||
{
|
||||
$codeblock = $matches[1];
|
||||
|
||||
$codeblock = $this->outdent($codeblock);
|
||||
if (!$this->features['no_html']) {
|
||||
$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
|
||||
}
|
||||
|
||||
# trim leading newlines and trailing newlines
|
||||
$codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock);
|
||||
$codeblock = "<pre><code>$codeblock\n</code></pre>";
|
||||
|
||||
return "\n\n".$this->hashBlock($codeblock)."\n\n";
|
||||
}
|
||||
|
||||
public function makeCodeSpan($code)
|
||||
{
|
||||
if (!$this->features['no_html']) {
|
||||
$code = htmlspecialchars(trim($code), ENT_NOQUOTES);
|
||||
}
|
||||
#
|
||||
# Create a code span markup for $code. Called from handleSpanToken.
|
||||
#
|
||||
return $this->hashPart("<code>$code</code>");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue