Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self, *args, **kwargs):
for c, arg in enumerate(args):
if pos[c] not in kwargs:
kwargs[pos[c]] = arg
if c+1 == len(pos): # pragma: no cover
if c + 1 == len(pos): # pragma: no cover
# ignore any additional args
break
if len(args):
Expand Down Expand Up @@ -209,7 +209,7 @@ def build_extension(self, ext_name, configs):
# Parse extensions config params (ignore the order)
pos = ext_name.find("(") # find the first "("
if pos > 0:
ext_args = ext_name[pos+1:-1]
ext_args = ext_name[pos + 1:-1]
ext_name = ext_name[:pos]
pairs = [x.split("=") for x in ext_args.split(",")]
configs.update([(x.strip(), y.strip()) for (x, y) in pairs])
Expand All @@ -235,7 +235,7 @@ def build_extension(self, ext_name, configs):
# For backward compat (until deprecation)
# check that this is an extension.
if ('.' not in ext_name and not (hasattr(module, 'makeExtension') or
(class_name and hasattr(module, class_name)))):
(class_name and hasattr(module, class_name)))):
# We have a name conflict
# eg: extensions=['tables'] and PyTables is installed
raise ImportError
Expand Down
2 changes: 1 addition & 1 deletion markdown/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def parse_options(args=None, values=None):
"`--extension` option.",
metavar="CONFIG_FILE")
parser.add_option("-q", "--quiet", default=CRITICAL,
action="store_const", const=CRITICAL+10, dest="verbose",
action="store_const", const=CRITICAL + 10, dest="verbose",
help="Suppress all warnings.")
parser.add_option("-v", "--verbose",
action="store_const", const=WARNING, dest="verbose",
Expand Down
28 changes: 15 additions & 13 deletions markdown/blockprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def detab(self, text):
newtext = []
lines = text.split('\n')
for line in lines:
if line.startswith(' '*self.tab_length):
if line.startswith(' ' * self.tab_length):
newtext.append(line[self.tab_length:])
elif not line.strip():
newtext.append('')
Expand All @@ -77,8 +77,8 @@ def looseDetab(self, text, level=1):
""" Remove a tab from front of lines but allowing dedented lines. """
lines = text.split('\n')
for i in range(len(lines)):
if lines[i].startswith(' '*self.tab_length*level):
lines[i] = lines[i][self.tab_length*level:]
if lines[i].startswith(' ' * self.tab_length * level):
lines[i] = lines[i][self.tab_length * level:]
return '\n'.join(lines)

def test(self, parent, block):
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(self, *args):
self.INDENT_RE = re.compile(r'^(([ ]{%s})+)' % self.tab_length)

def test(self, parent, block):
return block.startswith(' '*self.tab_length) and \
return block.startswith(' ' * self.tab_length) and \
not self.parser.state.isstate('detabbed') and \
(parent.tag in self.ITEM_TYPES or
(len(parent) and parent[-1] is not None and
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_level(self, parent, block):
# Get indent level
m = self.INDENT_RE.match(block)
if m:
indent_level = len(m.group(1))/self.tab_length
indent_level = len(m.group(1)) / self.tab_length
else:
indent_level = 0
if self.parser.state.isstate('list'):
Expand All @@ -210,7 +210,7 @@ def get_level(self, parent, block):
while indent_level > level:
child = self.lastChild(parent)
if (child is not None and
(child.tag in self.LIST_TYPES or child.tag in self.ITEM_TYPES)):
(child.tag in self.LIST_TYPES or child.tag in self.ITEM_TYPES)):
if child.tag in self.LIST_TYPES:
level += 1
parent = child
Expand All @@ -225,14 +225,14 @@ class CodeBlockProcessor(BlockProcessor):
""" Process code blocks. """

def test(self, parent, block):
return block.startswith(' '*self.tab_length)
return block.startswith(' ' * self.tab_length)

def run(self, parent, blocks):
sibling = self.lastChild(parent)
block = blocks.pop(0)
theRest = ''
if (sibling is not None and sibling.tag == "pre" and
len(sibling) and sibling[0].tag == "code"):
len(sibling) and sibling[0].tag == "code"):
# The previous block was a code block. As blank lines do not start
# new code blocks, append this block to the previous, adding back
# linebreaks removed from the split into a list.
Expand Down Expand Up @@ -311,7 +311,8 @@ class OListProcessor(BlockProcessor):
def __init__(self, parser):
super(OListProcessor, self).__init__(parser)
# Detect an item (``1. item``). ``group(1)`` contains contents of item.
self.RE = re.compile(r'^[ ]{0,%d}\d+\.[ ]+(.*)' % (self.tab_length - 1))
self.RE = re.compile(r'^[ ]{0,%d}\d+\.[ ]+(.*)' %
(self.tab_length - 1))
# Detect items on secondary lines. they can be of either list type.
self.CHILD_RE = re.compile(r'^[ ]{0,%d}((\d+\.)|[*+-])[ ]+(.*)' %
(self.tab_length - 1))
Expand Down Expand Up @@ -372,7 +373,7 @@ def run(self, parent, blocks):
# Loop through items in block, recursively parsing each with the
# appropriate parent.
for item in items:
if item.startswith(' '*self.tab_length):
if item.startswith(' ' * self.tab_length):
# Item is indented. Parse with last item as parent
self.parser.parseBlocks(lst[-1], [item])
else:
Expand All @@ -397,7 +398,7 @@ def get_items(self, block):
items.append(m.group(3))
elif self.INDENT_RE.match(line):
# This is an indented (possibly nested) item.
if items[-1].startswith(' '*self.tab_length):
if items[-1].startswith(' ' * self.tab_length):
# Previous item was indented. Append to that item.
items[-1] = '%s\n%s' % (items[-1], line)
else:
Expand All @@ -416,7 +417,8 @@ class UListProcessor(OListProcessor):
def __init__(self, parser):
super(UListProcessor, self).__init__(parser)
# Detect an item (``1. item``). ``group(1)`` contains contents of item.
self.RE = re.compile(r'^[ ]{0,%d}[*+-][ ]+(.*)' % (self.tab_length - 1))
self.RE = re.compile(r'^[ ]{0,%d}[*+-][ ]+(.*)' %
(self.tab_length - 1))


class HashHeaderProcessor(BlockProcessor):
Expand Down Expand Up @@ -527,7 +529,7 @@ def run(self, parent, blocks):
blocks.insert(0, theRest)
sibling = self.lastChild(parent)
if (sibling is not None and sibling.tag == 'pre' and
len(sibling) and sibling[0].tag == 'code'):
len(sibling) and sibling[0].tag == 'code'):
# Last block is a codeblock. Append to preserve whitespace.
sibling[0].text = util.AtomicString(
'%s%s' % (sibling[0].text, filler)
Expand Down
7 changes: 4 additions & 3 deletions markdown/extensions/attr_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ def run(self, doc):
if m:
self.assign_attrs(elem, m.group(1))
elem[-1].tail = elem[-1].tail[:m.start()]
elif pos is not None and pos > 0 and elem[pos-1].tail:
elif pos is not None and pos > 0 and elem[pos - 1].tail:
# use tail of last child before ul or ol
m = RE.search(elem[pos-1].tail)
m = RE.search(elem[pos - 1].tail)
if m:
self.assign_attrs(elem, m.group(1))
elem[pos-1].tail = elem[pos-1].tail[:m.start()]
elem[pos - 1].tail = elem[pos - 1].tail[:m.start()]
elif elem.text:
# use text. ul is first child.
m = RE.search(elem.text)
Expand Down Expand Up @@ -167,6 +167,7 @@ def sanitize_name(self, name):


class AttrListExtension(Extension):

def extendMarkdown(self, md, md_globals):
md.treeprocessors.add(
'attr_list', AttrListTreeprocessor(md), '>prettify'
Expand Down
2 changes: 1 addition & 1 deletion markdown/extensions/codehilite.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def __init__(self, *args, **kwargs):
'Use Pygments to Highlight code blocks. '
'Disable if using a JavaScript library. '
'Default: True']
}
}

super(CodeHiliteExtension, self).__init__(*args, **kwargs)

Expand Down
1 change: 1 addition & 0 deletions markdown/extensions/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def makeExtension(*args, **kwargs):

class MarkdownInHtmlProcessor(BlockProcessor):
"""Process Markdown Inside HTML Blocks."""

def test(self, parent, block):
return block == util.TAG_PLACEHOLDER % \
str(self.parser.blockprocessors.tag_counter + 1)
Expand Down
11 changes: 6 additions & 5 deletions markdown/extensions/footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def makeFootnotesDiv(self, root):
backlink.set(
"title",
"Jump back to footnote %d in the text" %
(self.footnotes.index(id)+1)
(self.footnotes.index(id) + 1)
)
backlink.text = FN_BACKLINK_TEXT

Expand Down Expand Up @@ -188,13 +188,13 @@ def run(self, lines):
while True:
m = DEF_RE.match(lines[i])
if m:
fn, _i = self.detectTabbed(lines[i+1:])
fn, _i = self.detectTabbed(lines[i + 1:])
fn.insert(0, m.group(2))
i += _i-1 # skip past footnote
i += _i - 1 # skip past footnote
self.footnotes.setFootnote(m.group(1), "\n".join(fn))
else:
newlines.append(lines[i])
if len(lines) > i+1:
if len(lines) > i + 1:
i += 1
else:
break
Expand Down Expand Up @@ -232,7 +232,7 @@ def detab(line):
i += 1
continue
else:
return items, i+1
return items, i + 1

else: # Blank line: _maybe_ we are done.
blank_line = True
Expand Down Expand Up @@ -306,6 +306,7 @@ def run(self, root):

class FootnotePostprocessor(Postprocessor):
""" Replace placeholders with html entities. """

def __init__(self, footnotes):
self.footnotes = footnotes

Expand Down
4 changes: 3 additions & 1 deletion markdown/extensions/headerid.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def run(self, doc):
if "id" in elem.attrib:
id = elem.get('id')
else:
id = stashedHTML2text(''.join(elem.itertext()), self.md)
id = stashedHTML2text(
''.join(elem.itertext()), self.md)
id = slugify(id, sep)
elem.set('id', unique(id, self.IDs))
if start_level:
Expand All @@ -61,6 +62,7 @@ def _get_meta(self):


class HeaderIdExtension(Extension):

def __init__(self, *args, **kwargs):
# set defaults
self.config = {
Expand Down
2 changes: 2 additions & 0 deletions markdown/extensions/smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@


class SubstituteTextPattern(HtmlPattern):

def __init__(self, pattern, replace, markdown_instance):
""" Replaces matches with some text. """
HtmlPattern.__init__(self, pattern)
Expand All @@ -168,6 +169,7 @@ def handleMatch(self, m):


class SmartyExtension(Extension):

def __init__(self, *args, **kwargs):
self.config = {
'smart_quotes': [True, 'Educate quotes'],
Expand Down
16 changes: 11 additions & 5 deletions markdown/extensions/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def _split(self, row, marker):
if self._row_has_unpaired_backticks(row):
# fallback on old behaviour
return row.split(marker)
# modify the backtick pattern to only match at the beginning of the search string
# modify the backtick pattern to only match at the beginning of the
# search string
backtick_pattern = BacktickPattern('^' + BACKTICK_RE)
elements = []
current = ''
Expand All @@ -108,7 +109,8 @@ def _split(self, row, marker):
if current != '' or len(elements) == 0:
# Don't append empty string unless it is the first element
# The border is already removed when we get the row, then the line is strip()'d
# If the first element is a marker, then we have an empty first cell
# If the first element is a marker, then we have an empty
# first cell
elements.append(current)
current = ''
else:
Expand All @@ -117,9 +119,13 @@ def _split(self, row, marker):
current += letter
else:
groups = match.groups()
delim = groups[1] # the code block delimeter (ie 1 or more backticks)
row_contents = groups[2] # the text contained inside the code block
i += match.start(4) - 1 # jump pointer to the beginning of the rest of the text (group #4)
# the code block delimeter (ie 1 or more backticks)
delim = groups[1]
# the text contained inside the code block
row_contents = groups[2]
# jump pointer to the beginning of the rest of the text
# (group #4)
i += match.start(4) - 1
element = delim + row_contents + delim # reinstert backticks
current += element
i += 1
Expand Down
6 changes: 4 additions & 2 deletions markdown/extensions/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def unique(id, ids):
while id in ids or not id:
m = IDCOUNT_RE.match(id)
if m:
id = '%s_%d' % (m.group(1), int(m.group(2))+1)
id = '%s_%d' % (m.group(1), int(m.group(2)) + 1)
else:
id = '%s_%d' % (id, 1)
ids.add(id)
Expand Down Expand Up @@ -124,6 +124,7 @@ def nest_toc_tokens(toc_list):


class TocTreeprocessor(Treeprocessor):

def __init__(self, md, config):
super(TocTreeprocessor, self).__init__(md)

Expand Down Expand Up @@ -239,7 +240,8 @@ def run(self, doc):
# Do not override pre-existing ids
if "id" not in el.attrib:
innertext = stashedHTML2text(text, self.markdown)
el.attrib["id"] = unique(self.slugify(innertext, self.sep), used_ids)
el.attrib["id"] = unique(
self.slugify(innertext, self.sep), used_ids)

toc_tokens.append({
'level': int(el.tag[-1]),
Expand Down
1 change: 1 addition & 0 deletions markdown/extensions/wikilinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def extendMarkdown(self, md, md_globals):


class WikiLinks(Pattern):

def __init__(self, pattern, config):
super(WikiLinks, self).__init__(pattern)
self.config = config
Expand Down
Loading