From be3b39bf4250a113bda91005b0362c8bc84fe5ab Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 25 Jan 2014 14:09:56 +0100 Subject: [PATCH] Markdown: disabled atx-style header support Rationale - collision with tag syntax: if #tag was first word in given line, the line was treated like header. --- src/CustomMarkdown.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/CustomMarkdown.php b/src/CustomMarkdown.php index e23105bb..63082475 100644 --- a/src/CustomMarkdown.php +++ b/src/CustomMarkdown.php @@ -27,6 +27,13 @@ class CustomMarkdown extends \Michelf\Markdown parent::__construct(); } + //disable atx-style headers + protected function _doHeaders_callback_atx($matches) + { + return $matches[0]; + } + + //disable paragraph forming when using simple markdown protected function formParagraphs($text) { if ($this->simple) @@ -56,6 +63,7 @@ class CustomMarkdown extends \Michelf\Markdown return $parser->transform($text); } + //automatically form links out of http://(...) and www.(...) protected function doAutoLinks2($text) { $text = preg_replace_callback('{(?<\s(){}]+)}i', [&$this, '_doAutoLinks_url_callback'], $text); @@ -63,6 +71,7 @@ class CustomMarkdown extends \Michelf\Markdown return $text; } + //extend anchors callback for doAutolinks2 protected function _doAnchors_inline_callback($matches) { if ($matches[3] == '') @@ -74,6 +83,8 @@ class CustomMarkdown extends \Michelf\Markdown return parent::_doAnchors_inline_callback($matches); } + //handle white characters inside code blocks + //so that they won't be optimized away by prettifying HTML protected function _doCodeBlocks_callback($matches) { $codeblock = $matches[1]; @@ -89,7 +100,8 @@ class CustomMarkdown extends \Michelf\Markdown return "\n\n".$this->hashBlock($codeblock)."\n\n"; } - + //change hard breaks trigger - simple \n followed by text + //instead of two spaces followed by \n protected function doHardBreaks($text) { return preg_replace_callback('/\n(?=[\[\]\(\)\w])/', [&$this, '_doHardBreaks_callback'], $text);