Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Michelf/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down Expand Up @@ -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 = "<h$level>".$this->runSpanGamut($matches[1])."</h$level>";
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 = "<h$level>".$this->runSpanGamut($matches[2])."</h$level>";
return "\n" . $this->hashBlock($block) . "\n\n";
}
Expand Down Expand Up @@ -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 = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>";
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 = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$level>";
return "\n" . $this->hashBlock($block) . "\n\n";
Expand Down