ParsedownToC

ParsedownToC extends DynamicParent
in package

Table of Contents

Constants

ID_ATTRIBUTE_DEFAULT  = 'toc'
Default ID attribute for ToC (only for ParsedownExtra)
TAG_TOC_DEFAULT  = '[toc]'
Default ToC tag
VERSION  = '1.3.1'
Version of this extension
VERSION_PARSEDOWN_REQUIRED  = '1.7.4'
Version of Parsedown required

Properties

$contentsListArray  : array<string|int, mixed>
$contentsListString  : string
$firstHeadLevel  : int
$tag_toc  : string

Methods

__construct()  : void
Version requirement check and parent constructor call.
body()  : string
Parses the given markdown string to an HTML string but it leaves the ToC tag as is. It's an alias of the parent method "\DynamicParent::text()".
contentsList()  : string
Returns the parsed ToC.
setTagToc()  : void
Sets the user defined ToC markdown tag.
text()  : void
Parses markdown string to HTML and also the "[toc]" tag as well.
blockHeader()  : void|array<string|int, mixed>
Heading process. It retruns the heading block element if the given $Line is a heading element.
createAnchorID()  : string
Generates an anchor text that are link-able even the heading is not in ASCII.
decodeTagFromHash()  : string
Decodes the hashed ToC tag to an original tag and replaces.
encodeTagToHash()  : string
Encodes the ToC tag to a hashed tag and replace.
fetchText()  : string
[Deprecated] Superseded by "getTextOnly()".
getIdAttributeToC()  : string
Gets the ID attribute of the ToC for HTML tags.
getSalt()  : string
Unique string to use as a salt value.
getTagToC()  : string
Gets the markdown tag for ToC.
getTextOnly()  : string
Get only the text from a markdown string.
setContentsList()  : void
Set/stores the heading block to ToC list in a string and array format.
setContentsListAsArray()  : void
Sets/stores the heading block info as an array.
setContentsListAsString()  : void
Sets/stores the heading block info as a list in markdown format.

Constants

ID_ATTRIBUTE_DEFAULT

Default ID attribute for ToC (only for ParsedownExtra)

public mixed ID_ATTRIBUTE_DEFAULT = 'toc'

TAG_TOC_DEFAULT

Default ToC tag

public mixed TAG_TOC_DEFAULT = '[toc]'

VERSION

Version of this extension

public mixed VERSION = '1.3.1'

VERSION_PARSEDOWN_REQUIRED

Version of Parsedown required

public mixed VERSION_PARSEDOWN_REQUIRED = '1.7.4'

Properties

$contentsListArray

protected array<string|int, mixed> $contentsListArray = array()

It holds the heading blocks of the content in array form.

$contentsListString

protected string $contentsListString = ''

It holds the headings in markdown format string.

$firstHeadLevel

protected int $firstHeadLevel = 0

It holds the initial heading level of the content.

$tag_toc

protected string $tag_toc = ''

It holds the user defined ToC tag.

Methods

__construct()

Version requirement check and parent constructor call.

public __construct() : void
Tags
throws
Exception

body()

Parses the given markdown string to an HTML string but it leaves the ToC tag as is. It's an alias of the parent method "\DynamicParent::text()".

public body(string $text[, bool $omit_toc_tag = false ]) : string
Parameters
$text : string

Markdown string to be parsed.

$omit_toc_tag : bool = false

(Optional) If true, the ToC tag will be excluded from the result. Default is false.

Return values
string

Parsed HTML string.

contentsList()

Returns the parsed ToC.

public contentsList([string $type_return = 'string' ]) : string

If the arg is "string" then it returns the ToC in HTML string.

Parameters
$type_return : string = 'string'

Type of the return format. "string" or "json".

Return values
string

HTML/JSON string of ToC.

setTagToc()

Sets the user defined ToC markdown tag.

public setTagToc(string $tag) : void
Parameters
$tag : string

text()

Parses markdown string to HTML and also the "[toc]" tag as well.

public text(string $text) : void

It overrides the parent method: \Parsedown::text().

Parameters
$text : string

blockHeader()

Heading process. It retruns the heading block element if the given $Line is a heading element.

protected blockHeader(array<string|int, mixed> $Line) : void|array<string|int, mixed>

It extends the parent method: \Parsedown::blockHeader() and creates a ToC list from the heading blocks and stores them. Use "contentsList()" to retrieve the ToC list.

Parameters
$Line : array<string|int, mixed>

Array that Parsedown detected as a block type element.

Tags
see
contentsList()
Return values
void|array<string|int, mixed>

Array of Heading Block.

createAnchorID()

Generates an anchor text that are link-able even the heading is not in ASCII.

protected createAnchorID(string $text) : string
Parameters
$text : string
Return values
string

decodeTagFromHash()

Decodes the hashed ToC tag to an original tag and replaces.

protected decodeTagFromHash(string $text) : string

This is used to avoid parsing user defined ToC tag which includes "_" in their tag such as "[[toc]]". Unless it will be parsed as: "

[[TOC]]

"

Parameters
$text : string
Return values
string

encodeTagToHash()

Encodes the ToC tag to a hashed tag and replace.

protected encodeTagToHash(string $text) : string

This is used to avoid parsing user defined ToC tag which includes "_" in their tag such as "[[toc]]". Unless it will be parsed as: "

[[TOC]]

"

Parameters
$text : string
Return values
string

fetchText()

[Deprecated] Superseded by "getTextOnly()".

protected fetchText(string $text) : string

It will be removed in the near future. Currently it is an alias of "getTextOnly()".

Get only the text from a markdown string. It parses to HTML once then trims the tags to get the text. It's been replaced by "getTextOnly()".

Parameters
$text : string

Markdown text.

Tags
see
getTextOnly()
Return values
string

getIdAttributeToC()

Gets the ID attribute of the ToC for HTML tags.

protected getIdAttributeToC() : string
Return values
string

getSalt()

Unique string to use as a salt value.

protected getSalt() : string
Return values
string

getTagToC()

Gets the markdown tag for ToC.

protected getTagToC() : string
Return values
string

getTextOnly()

Get only the text from a markdown string.

protected getTextOnly(string $text) : string

It parses to HTML once then trims the tags to get the text.

Parameters
$text : string

Markdown text.

Return values
string

setContentsList()

Set/stores the heading block to ToC list in a string and array format.

protected setContentsList(array<string|int, mixed> $Content) : void
Parameters
$Content : array<string|int, mixed>

Heading info such as "level","id" and "text".

setContentsListAsArray()

Sets/stores the heading block info as an array.

protected setContentsListAsArray(array<string|int, mixed> $Content) : void
Parameters
$Content : array<string|int, mixed>

setContentsListAsString()

Sets/stores the heading block info as a list in markdown format.

protected setContentsListAsString(array<string|int, mixed> $Content) : void
Parameters
$Content : array<string|int, mixed>

Heading info such as "level","id" and "text".


        
On this page

Search results