Skip to content

Commit

Permalink
fix: Parsedown 1.7.1
Browse files Browse the repository at this point in the history
Parsedown 1.7.1 の仕様変更(ブロック要素のエレメント $Block['element']['text'] が $Block['element']['handler']['argument'] に変わったこと)に対する修正。
  • Loading branch information
KEINOS committed Apr 7, 2018
1 parent 097a0e5 commit 920daa5
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*
* It creates a list of contents table from headings.
*
* @version 20180122-1859
* @author KEINOS (https://github.com/KEINOS/)
* @package Parsedown (https://github.com/erusev/parsedown)
* @see How to: https://github.com/KEINOS/parsedown-extension_table-of-contents/
* @version 20180407-2203
* @author KEINOS (https://github.com/KEINOS/)
* @package Parsedown 1.7.1 (https://github.com/erusev/parsedown)
* @see Howto: https://github.com/KEINOS/parsedown-extension_table-of-contents/
* @license https://github.com/KEINOS/parsedown-extension_table-of-contents/LICENSE
*/
class Extension extends Parsedown
Expand All @@ -23,33 +23,44 @@ protected function createAnchorID($Text)
}

#
# Setters
# contents list
#
function setContentsListAsArray(bool $outListAsArray)
function contentsList($Return_as = 'string')
{
$this->contentsListAsArray = $outListAsArray;

return $this;
if ('string' === strtolower($Return_as)) {
$result = '';
if (! empty($this->contentsListString)) {
$result = $this->text($this->contentsListString);
}
return $result;
} elseif ('json' === strtolower($Return_as)) {
return json_encode($this->contentsListArray);
} else {
return $this->contentsListArray;
}
}

protected $contentsListAsArray = false;

#
# contents list
# Setters
#
function contentsList()
protected function setContentsList($Content)
{
if(! empty($this->contentsListString)){
return $this->text( $this->contentsListString );
}
$this->setContentsListAsArray($Content);
$this->setContentsListAsString($Content);
}

protected function setContentsList($Content)
protected function setContentsListAsArray($Content)
{
$this->contentsListArray[] = $Content;
}
protected $contentsListArray = array();

protected function setContentsListAsString($Content)
{
$id = $Content['id'];
$text = $this->fetchText($Content['text']);
$link = "[${text}](#${id})";
$level = (integer) trim($Content['level'],'h');
$text = $this->fetchText($Content['text']);
$id = $Content['id'];
$level = (integer) trim($Content['level'], 'h');
$link = "[${text}](#${id})";

if ($this->firstHeadLevel === 0) {
$this->firstHeadLevel = $level;
Expand All @@ -74,10 +85,9 @@ protected function setContentsList($Content)
protected function blockHeader($Line)
{
if (isset($Line['text'][1])) {

$Block = Parsedown::blockHeader($Line);

$text = $Block['element']['text'];
$text = $Block['element']['handler']['argument'];
$level = $Block['element']['name']; //h1,h2..h6
$id = $this->createAnchorID($text);

Expand All @@ -96,5 +106,4 @@ protected function blockHeader($Line)
return $Block;
}
}

}

0 comments on commit 920daa5

Please sign in to comment.