File Description
No documentation found for this sectionImports
Standard Packages
External Packages
If you don't have them, you can install these packages running pip :$ pip install marko
Functions & Classes
def get_href(heading, hrefs=[])
Description
Get the markdown href from a heading string.Parameters
heading : str Heading string content
hrefs: list of str List containing the hrefs that are already in the ToC (to avoid dupicates)
Returns
href: str href pointing to the heading
Examples
>>> get_href("This is My Heading !")
'#this-is-my-heading-'
'#this-is-my-heading-'
>>> get_href("This is My Heading with an emoji ! :fire:")
'#this-is-my-heading-with-an-emoji-'
'#this-is-my-heading-with-an-emoji-'
def get_toc(markdown_content, min_depth=None, max_depth=None)
Description
Return the table of contents in markdown format, from markdown content.Parameters
markdown_content: str Markdown content. Is typically the content of a readme.md file. It can contain a table of contents.
min_depth: int or None Minimum heading level. If this is set to `None`, there is no minimum depth applied. For example, if you set min_depth to `2`, all the headings with level < 2 will be ignored (such as "# Dummy Heading").
Defaults to `None`
max_depth: int or NoneDefaults to `None`
Maximum heading level. If this is set to `None`, there is no maximum depth applied. For example, if you set max_depth to `3`, all the headings with level > 3 will be ignored (such as "#### Dummy Heading").
Defaults to `None`
Defaults to `None`
Returns
toc : str String content of the table of contents, in markdown format
def generate_toc(markdown_content, toc_title="TableofContents", toc_level=1, min_depth=None, max_depth=None)
Description
Generate a table of contents for the markdown content, replacing the old table of contents if it exists.Parameters
markdown_content: str Markdown content. Is typically the content of a readme.md file. It can contain a table of contents between the placeholder "[](mdtoc)" and "[](/mdtoc)".
toc_title : str Table of content heading name.
Defaults to "Table of Contents"
toc_level : intDefaults to "Table of Contents"
Heading level of the table of content section.
Defaults to 1.
min_depth: int or NoneDefaults to 1.
Minimum heading level. If this is set to `None`, there is no minimum depth applied. For example, if you set min_depth to `2`, all the headings with level < 2 will be ignored (such as "# Dummy Heading").
Defaults to `None`
max_depth: int or NoneDefaults to `None`
Maximum heading level. If this is set to `None`, there is no maximum depth applied. For example, if you set max_depth to `3`, all the headings with level > 3 will be ignored (such as "#### Dummy Heading").
Defaults to `None`
Defaults to `None`
Returns
md_with_toc : str String content of the markdown, with the table of contents