blockprocessors
CORE MARKDOWN BLOCKPARSER.
This parser handles basic parsing of Markdown blocks. It doesn't concern itself with inline elements such as bold or italics, but rather just catches blocks, lists, quotes, etc.
The BlockParser is made up of a bunch of BlockProssors, each handling a different type of block. Extensions may add/replace/remove BlockProcessors as they need to alter how markdown blocks are parsed.
Attributes
logger = logging.getLogger('MARKDOWN')
module-attribute
Classes
BlockProcessor(parser)
Bases: object
Base class for block processors.
Each subclass will provide the methods below to work with the source and
tree. Each processor will need to define it's own test
and run
methods. The test
method should return True or False, to indicate
whether the current block should be processed by this processor. If the
test passes, the parser will call the processors run
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parser |
BlockParser
|
BlockParser instance |
required |
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
Test for block type. Must be overridden by subclasses.
As the parser loops through processors, it will call the test
method on each to determine if the given block of text is of that
type. This method must return a boolean True
or False
. The
actual method of testing is left to the needs of that particular
block type. It could be as simple as block.startswith(some_string)
or a complex regular expression. As the block type may be different
depending on the parent of the block (i.e. inside a list), the parent
etree element is also provided and may be used as part of the test.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
Element
|
A etree element which will be the parent of the block. |
required |
block |
list[Element]
|
A block of text from the source which has been split at blank lines. |
required |
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
run(parent, blocks)
Run processor. Must be overridden by subclasses.
When the parser determines the appropriate type of a block, the parser
will call the corresponding processor's run
method. This method
should parse the individual lines of the block and append them to
the etree.
Note that both the parent
and etree
keywords are pointers
to instances of the objects which should be edited in place. Each
processor must make changes to the existing objects as there is no
mechanism to return new/different objects to replace them.
This means that this method should be adding SubElements or adding text
to the parent, and should remove (pop
) or add (insert
) items to
the list of blocks.
Other Parameters:
Name | Type | Description |
---|---|---|
parent |
Element
|
A etree element which is the parent of the current block. |
blocks |
list[Element]
|
A list of all remaining blocks of the document. |
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
ListIndentProcessor(*args)
Bases: BlockProcessor
Process children of list items.
Examples:
-
a list item process this part
or this part
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
ITEM_TYPES = ['li']
class-attribute
instance-attribute
LIST_TYPES = ['ul', 'ol']
class-attribute
instance-attribute
INDENT_RE = re.compile('^(([ ]{%s})+)' % self.tab_length)
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
create_item(parent, block)
Create a new li and parse the block with it as the parent.
get_level(parent, block)
Get level of indent based on list level.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
CodeBlockProcessor(parser)
Bases: BlockProcessor
Process code blocks.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
BlockQuoteProcessor(parser)
Bases: BlockProcessor
Blockquote processor.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
RE = re.compile('(^|\\n)[ ]{0,3}>[ ]?(.*)')
class-attribute
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
clean(line)
Remove >
from beginning of a line.
OListProcessor(parser)
Bases: BlockProcessor
Process ordered list blocks.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
TAG = 'ol'
class-attribute
instance-attribute
STARTSWITH = '1'
class-attribute
instance-attribute
SIBLING_TAGS = ['ol', 'ul']
class-attribute
instance-attribute
RE = re.compile('^[ ]{0,%d}\\d+\\.[ ]+(.*)' % self.tab_length - 1)
instance-attribute
CHILD_RE = re.compile('^[ ]{0,%d}((\\d+\\.)|[*+-])[ ]+(.*)' % self.tab_length - 1)
instance-attribute
INDENT_RE = re.compile('^[ ]{%d,%d}((\\d+\\.)|[*+-])[ ]+.*' % (self.tab_length, self.tab_length * 2 - 1))
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
get_items(block)
Break a block into list items.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
UListProcessor(parser)
Bases: OListProcessor
Process unordered list blocks.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
STARTSWITH = '1'
class-attribute
instance-attribute
SIBLING_TAGS = ['ol', 'ul']
class-attribute
instance-attribute
CHILD_RE = re.compile('^[ ]{0,%d}((\\d+\\.)|[*+-])[ ]+(.*)' % self.tab_length - 1)
instance-attribute
INDENT_RE = re.compile('^[ ]{%d,%d}((\\d+\\.)|[*+-])[ ]+.*' % (self.tab_length, self.tab_length * 2 - 1))
instance-attribute
TAG = 'ul'
class-attribute
instance-attribute
RE = re.compile('^[ ]{0,%d}[*+-][ ]+(.*)' % self.tab_length - 1)
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
get_items(block)
Break a block into list items.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
HashHeaderProcessor(parser)
Bases: BlockProcessor
Process Hash Headers.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
RE = re.compile('(^|\\n)(?P<level>#{1,6})(?P<header>.*?)#*(\\n|$)')
class-attribute
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
SetextHeaderProcessor(parser)
Bases: BlockProcessor
Process Setext-style Headers.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
RE = re.compile('^.*?\\n[=-]+[ ]*(\\n|$)', re.MULTILINE)
class-attribute
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
HRProcessor(parser)
Bases: BlockProcessor
Process Horizontal Rules.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
RE = '^[ ]{0,3}((-+[ ]{0,2}){3,}|(_+[ ]{0,2}){3,}|(\\*+[ ]{0,2}){3,})[ ]*'
class-attribute
instance-attribute
SEARCH_RE = re.compile(RE, re.MULTILINE)
class-attribute
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
EmptyBlockProcessor(parser)
Bases: BlockProcessor
Process blocks that are empty or start with an empty line.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
ParagraphProcessor(parser)
Bases: BlockProcessor
Process Paragraph blocks.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Attributes
parser = parser
instance-attribute
tab_length = parser.markdown.tab_length
instance-attribute
Functions
lastChild(parent)
detab(text)
Remove a tab from the front of each line of the given text.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
looseDetab(text, level=1)
Remove a tab from front of lines but allowing dedented lines.
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
test(parent, block)
run(parent, blocks)
Source code in pyrevitlib/pyrevit/coreutils/markdown/blockprocessors.py
Functions
build_block_parser(md_instance, **kwargs)
Build the default block parser used by Markdown.