toc
Table of Contents Extension for Python-Markdown.
See https://pythonhosted.org/Markdown/extensions/toc.html for documentation.
Original code Copyright 2008 Jack Miller
All changes Copyright 2008-2014 The Python Markdown Project
License: BSD
Attributes
IDCOUNT_RE = re.compile('^(.*)_([0-9]+)$')
module-attribute
Classes
TocTreeprocessor(md, config)
Bases: Treeprocessor
TOC Tree processor.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
Attributes
markdown = markdown_instance
instance-attribute
marker = config['marker']
instance-attribute
title = config['title']
instance-attribute
base_level = int(config['baselevel']) - 1
instance-attribute
slugify = config['slugify']
instance-attribute
sep = config['separator']
instance-attribute
use_anchors = parseBoolValue(config['anchorlink'])
instance-attribute
use_permalinks = parseBoolValue(config['permalink'], False)
instance-attribute
header_rgx = re.compile('[Hh][123456]')
instance-attribute
Functions
iterparent(root)
replace_marker(root, elem)
Replace marker with elem.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
set_level(elem)
Adjust header level according to base level.
add_anchor(c, elem_id)
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
add_permalink(c, elem_id)
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
build_toc_div(toc_list)
Return a string div given a toc list.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
run(doc)
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
TocExtension(*args, **kwargs)
Bases: Extension
TOC Markdown extension.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
Attributes
TreeProcessorClass = TocTreeprocessor
class-attribute
instance-attribute
config = {'marker': ['[TOC]', 'Text to find and replace with Table of Contents - Set to an empty string to disable. Defaults to "[TOC]"'], 'title': ['', 'Title to insert into TOC <div> - Defaults to an empty string'], 'anchorlink': [False, 'True if header should be a self link - Defaults to False'], 'permalink': [0, 'True or link text if a Sphinx-style permalink should be added - Defaults to False'], 'baselevel': ['1', 'Base level for headers.'], 'slugify': [slugify, "Function to generate anchors based on header text - Defaults to the headerid ext's slugify function."], 'separator': ['-', 'Word separator. Defaults to "-".']}
instance-attribute
Functions
getConfig(key, default='')
Return a setting for the given key or an empty string.
getConfigs()
getConfigInfo()
setConfig(key, value)
Set a config setting for key
with the given value
.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/__init__.py
setConfigs(items)
Set multiple config settings given a dict or list of tuples.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/__init__.py
extendMarkdown(md, md_globals)
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
Functions
slugify(value, separator)
Slugify a string, to make it URL friendly.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
unique(id, ids)
Ensure id is unique in set of ids. Append '_1', '_2'... if not.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
stashedHTML2text(text, md)
Extract raw HTML from stash, reduce to plain text and swap with placeholder.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/toc.py
nest_toc_tokens(toc_list)
Given an unsorted list with errors and skips, return a nested one.
Examples:
[{'level': 1}, {'level': 2}] => [{'level': 1, 'children': [{'level': 2, 'children': []}]}].
A wrong list is also converted: [{'level': 2}, {'level': 1}] => [{'level': 2, 'children': []}, {'level': 1, 'children': []}]