codehilite
CodeHilite Extension for Python-Markdown.
Adds code/syntax highlighting to standard Python-Markdown code blocks.
See https://pythonhosted.org/Markdown/extensions/code_hilite.html for documentation.
Original code Copyright 2006-2008 Waylan Limberg.
All changes Copyright 2008-2014 The Python Markdown Project
License: BSD
Attributes
pygments = True
module-attribute
Classes
CodeHilite(src=None, linenums=None, guess_lang=True, css_class='codehilite', lang=None, style='default', noclasses=False, tab_length=4, hl_lines=None, use_pygments=True)
Bases: object
Determine language of source code, and pass it into pygments hilighter.
-
src: Source string or any object with a .readline attribute.
-
linenums: (Boolean) Set line numbering to 'on' (True), 'off' (False) or 'auto'(None). Set to 'auto' by default.
-
guess_lang: (Boolean) Turn language auto-detection 'on' or 'off' (on by default).
-
css_class: Set class name of wrapper div ('codehilite' by default).
-
hl_lines: (List of integers) Lines to emphasize, 1-indexed.
Low Level Usage
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/codehilite.py
Attributes
src = src
instance-attribute
lang = lang
instance-attribute
linenums = linenums
instance-attribute
guess_lang = guess_lang
instance-attribute
css_class = css_class
instance-attribute
style = style
instance-attribute
noclasses = noclasses
instance-attribute
tab_length = tab_length
instance-attribute
hl_lines = hl_lines or []
instance-attribute
use_pygments = use_pygments
instance-attribute
Functions
hilite()
Highlites the code.
Pass code to the Pygments highliter with optional line numbers. The output should then be styled with css to your liking. No styles are applied by default - only styling hooks (i.e.: ).
Returns:
Type | Description |
---|---|
str
|
html text of the highlighted code. |
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/codehilite.py
HiliteTreeprocessor(markdown_instance=None)
Bases: Treeprocessor
Hilight source code in code blocks.
Source code in pyrevitlib/pyrevit/coreutils/markdown/util.py
Attributes
markdown = markdown_instance
instance-attribute
Functions
run(root)
Find code blocks and store in htmlStash.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/codehilite.py
CodeHiliteExtension(*args, **kwargs)
Bases: Extension
Add source code hilighting to markdown codeblocks.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/codehilite.py
Attributes
config = {'linenums': [None, 'Use lines numbers. True=yes, False=no, None=auto'], 'guess_lang': [True, 'Automatic language detection - Default: True'], 'css_class': ['codehilite', 'Set class name for wrapper <div> - Default: codehilite'], 'pygments_style': ['default', 'Pygments HTML Formatter Style (Colorscheme) - Default: default'], 'noclasses': [False, 'Use inline styles instead of CSS classes - Default false'], 'use_pygments': [True, 'Use Pygments to Highlight code blocks. Disable if using a JavaScript library. Default: True']}
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)
Add HilitePostprocessor to Markdown instance.
Source code in pyrevitlib/pyrevit/coreutils/markdown/extensions/codehilite.py
Functions
parse_hl_lines(expr)
Support our syntax for emphasizing certain lines of code.
expr should be like '1 2' to emphasize lines 1 and 2 of a code block. Returns a list of ints, the line numbers to emphasize.