Skip to content

Commit

Permalink
Expose default_features as class-level attributes
Browse files Browse the repository at this point in the history
This makes it possible to add feature types to BlockLexer and
InlineLexer without having to copy-paste the methods where their default
feature orders are defined.
  • Loading branch information
takluyver authored and lepture committed Jun 22, 2014
1 parent b78bcbd commit 70490b6
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions mistune.py
Expand Up @@ -155,6 +155,13 @@ class BlockGrammar(object):
class BlockLexer(object):
"""Block level lexer for block grammars."""

default_features = [
'newline', 'block_code', 'fences', 'heading',
'nptable', 'lheading', 'hrule', 'block_quote',
'list_block', 'block_html', 'def_links',
'def_footnotes', 'table', 'paragraph', 'text'
]

def __init__(self, rules=None, **kwargs):
self.options = kwargs

Expand All @@ -174,12 +181,7 @@ def parse(self, src, features=None):
src = src.rstrip('\n')

if not features:
features = (
'newline', 'block_code', 'fences', 'heading',
'nptable', 'lheading', 'hrule', 'block_quote',
'list_block', 'block_html', 'def_links',
'def_footnotes', 'table', 'paragraph', 'text'
)
features = self.default_features

def manipulate(src):
for key in features:
Expand Down Expand Up @@ -461,6 +463,13 @@ class InlineGrammar(object):
class InlineLexer(object):
"""Inline level lexer for inline grammars."""

default_features = [
'escape', 'autolink', 'url', 'tag',
'footnote', 'link', 'reflink', 'nolink',
'double_emphasis', 'emphasis', 'code',
'linebreak', 'strikethrough', 'text',
]

def __init__(self, renderer, rules=None, **kwargs):
self.options = kwargs

Expand Down Expand Up @@ -497,12 +506,7 @@ def output(self, src, features=None):
src = escape(src)

if not features:
features = [
'escape', 'autolink', 'url', 'tag',
'footnote', 'link', 'reflink', 'nolink',
'double_emphasis', 'emphasis', 'code',
'linebreak', 'strikethrough', 'text',
]
features = list(self.default_features)

if self._in_footnote and 'footnote' in features:
features.remove('footnote')
Expand Down

0 comments on commit 70490b6

Please sign in to comment.