Skip to content

Commit

Permalink
Added IDs for title in markdown parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom32i committed Nov 14, 2015
1 parent 85e7e81 commit 5262003
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Service/Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ protected function inlineLink($Excerpt)
return $data;
}

/**
* {@inheritdoc}
*/
protected function blockHeader($Line)
{
$Block = parent::blockHeader($Line);

$Block['element']['attributes']['id'] = $this->getId($Block);

return $Block;
}

/**
* Process code content
*
Expand Down Expand Up @@ -98,4 +110,16 @@ protected function getLanguage($Block)

return substr($Block['element']['text']['attributes']['class'], strlen('language-'));
}

/**
* Get ID for the given block
*
* @param array $Block
*
* @return string
*/
protected function getId($Block)
{
return preg_replace('#[^a-z]+#i', '-', strtolower($Block['element']['text']));
}
}

0 comments on commit 5262003

Please sign in to comment.