diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 1dea9813..a5684a58 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -58,6 +58,10 @@ public static function defaultTransform($text) { # Predefined urls and titles for reference links and images. public $predef_urls = array(); public $predef_titles = array(); + + # Offset for header levels, i.e., if you want the first heading to be H2, + # make the offset 1 + public $header_offset = 0; ### Parser Implementation ### @@ -769,12 +773,12 @@ protected function _doHeaders_callback_setext($matches) { if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) return $matches[0]; - $level = $matches[2]{0} == '=' ? 1 : 2; + $level = $matches[2]{0} == '=' ? 1 : 2 + $this->header_offset; $block = "".$this->runSpanGamut($matches[1]).""; return "\n" . $this->hashBlock($block) . "\n\n"; } protected function _doHeaders_callback_atx($matches) { - $level = strlen($matches[1]); + $level = strlen($matches[1]) + $this->header_offset; $block = "".$this->runSpanGamut($matches[2]).""; return "\n" . $this->hashBlock($block) . "\n\n"; } @@ -2471,13 +2475,13 @@ protected function doHeaders($text) { protected function _doHeaders_callback_setext($matches) { if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) return $matches[0]; - $level = $matches[3]{0} == '=' ? 1 : 2; + $level = $matches[3]{0} == '=' ? 1 : 2 + $this->header_offset; $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]); $block = "".$this->runSpanGamut($matches[1]).""; return "\n" . $this->hashBlock($block) . "\n\n"; } protected function _doHeaders_callback_atx($matches) { - $level = strlen($matches[1]); + $level = strlen($matches[1]) + $this->header_offset; $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]); $block = "".$this->runSpanGamut($matches[2]).""; return "\n" . $this->hashBlock($block) . "\n\n";