Skip to content

Commit

Permalink
Simplifying code and dealing with double #
Browse files Browse the repository at this point in the history
  • Loading branch information
chdemko committed Apr 15, 2016
1 parent a900c42 commit 4d954da
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pandoc_numbering.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def numbering(key, value, format, meta):
for index in range(level, 6):
headers[index] = 0
elif key == 'Para':
length = len(value)
if length >= 3 and value[-2] == Space() and value[-1]['t'] == 'Str':
if len(value) >= 3 and value[-2] == Space() and value[-1]['t'] == 'Str':
last = value[-1]['c']

match = re.match('^' + headerRegex + '#(?P<prefix>[a-zA-Z][\w.-]*:)?(?P<name>[a-zA-Z][\w:.-]*)?$', last)
Expand All @@ -57,8 +56,7 @@ def numbering(key, value, format, meta):
for (i, item) in enumerate(value):
if item['t'] == 'Str' and item['c'][0] == '(':
title = Emph(value[i:-2])
value = value[:i - 1] + value[length - 2:]
length = i + 1
value = value[:i - 1] + value[-2:]
break

# Compute the basicCategory and the category
Expand Down Expand Up @@ -121,8 +119,8 @@ def numbering(key, value, format, meta):

# Return the contents in a Para element
return Para(contents)
elif re.match('^##([a-zA-Z][\w:.-]*)?$', last):
# Special case where the last element is '##...'
elif re.match('^' + headerRegex + '##(?P<prefix>[a-zA-Z][\w.-]*:)?(?P<name>[a-zA-Z][\w:.-]*)?$', last):
# Special case where the last element is '...##...'
value[-1]['c'] = value[-1]['c'].replace('##', '#', 1)
return Para(value)

Expand Down

0 comments on commit 4d954da

Please sign in to comment.