Download the PHP package keinos/parsedown-toc without Composer
On this page you can find all versions of the php package keinos/parsedown-toc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download keinos/parsedown-toc
More information about keinos/parsedown-toc
Files in keinos/parsedown-toc
Package parsedown-toc
Short Description Table of Contents Extension for Parsedown, the Parser for Markdown.
License MIT
Homepage https://github.com/KEINOS/parsedown-extension_table-of-contents/
Informations about the package parsedown-toc
Parsedown ToC Extension
Listing Table of Contents Extension for Parsedown.
This simple PHP file extends Parsedown Vanilla / Parsedown Extra to generate a list of header index (a.k.a. Table of Contents or ToC), from a markdown text given.
Basic Usage
- For more examples see the examples directory.
Installation
This extension, ParsedownToC
, is a single PHP file. Download and place it in the same directory as the Parsedown.php
file (optionally place the ParsedownExtra.php
file if you are using it).
Manual Install
You can download the latest '[Extension.php](https://github.com/KEINOS/parsedown-extension_table-of-contents/blob/master/Extension.php)' file from the below URL. Place it anywhere you like to include. > Since this is an extension of [Parsedown](https://parsedown.org/), you need to download and include `Parsedown.php` as well.Via Composer
We also support Composer for installation and convenience.
Basic Usage Using Composer
To use the extension via Composer, include the autoloader (`vendor/autoload.php` file) instead of the `Parsedown.php` and `Extension.php` file.
Requirements
[!NOTE] We will support PHP 8.4+ and Parsedown v2 after we finish refactoring the test scripts and the official release of Parsedown v2.
Class Info and Methods
For more details, please refer to the PHP Doc reference.
- Main Class:
ParsedownToC()
- Arguments: none
- Methods:
text(string $text)
:- Returns the parsed content and
[toc]
tag(s) parsed as well - Required argument:
$text
: Markdown string to be parsed
- Returns the parsed content and
body(string $text [, bool $omit_toc_tag=false])
:- Returns the parsed content WITHOUT parsing
[toc]
tag - Required argument:
$text
: Markdown string to be parsed- Optional argument:
$omit_toc_tag
: Iftrue
, the[toc]
tag will be excluded from the output- Default:
false
- Available since v1.3.0
- Returns the parsed content WITHOUT parsing
contentsList([string $type_return='string'])
:- Returns the ToC, the table of contents, in HTML or JSON.
- Optional argument:
$type_return
: Specifies the returned format"string"
or"json
" can be specified.string
=HTML,json
=JSON.- Default
"string"
setTagToc(string $tag='[tag]')
:- Sets user defined ToC markdown tag. Empty value sets the default tag
- Default:
"[toc]"
- Available since v1.1.2
- Note: Use this method before
text()
orbody()
method if you want to use the ToC tag rather than the "[toc]
"
- Other Methods:
- All the public methods of
Parsedown
and/orParsedown Extend
are available to use - Note: As of
ParsedownToC
v1.1.0 the old alias classExtension()
is deprecated
Online Demo
Advanced Usage (Using Parsedown Extra)
As of ParsedownToC v1.1.1, you can use the anchor identifiers for Parsedown Extra.
With this feature, you can specify the anchor name you like. Useful if the headings are in UTF-8 (not in ASCII) and to make it readable. Such as placing the "go back" links in a page.
With the above markdown the generated ToC will be as below. Note that the anchor is changed to the specified one.
- Note that you need to require/include the Parsedown Extra as well.
Testing
Eventhough we are migraing the tests to PHPUnit, currently we use hand-made test scripts to run the unit tests via bash.
Testing using docker (docker compose)
Testing locally
To run the tests:
[!IMPORTANT] This test will download/install dependencies such as:
Parsedown.php
,ParsedownExtra.php
,git
,jq
,curl
andbash
if not installed. So please run this test in a safe environment (docker for example).
References
- Repo:
- Source Code: https://github.com/KEINOS/parsedown-extension_table-of-contents @ GitHub
- Archived Package: https://packagist.org/packages/keinos/parsedown-toc @ Packagist
- Support:
- Parsedown's Wiki @ GitHub
- Issues of this extension @ GitHub
- Issues of Parsedown @ GitHub
- Issues of Parsedown Extra @ GitHub
- Authors:
- KEINOS and the contributors @ GitHub
- Licence: