Skip to content

Commit

Permalink
Improve robustness of Increase/Decrease Heading Level
Browse files Browse the repository at this point in the history
Whitespace after the leading hashes should be optional. Though when we output the version with heading level increased or decreased, we put a space after the hashes.

Fixes #12
  • Loading branch information
sorbits committed Jan 18, 2013
1 parent 838bf3c commit f1ff9ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
4 changes: 1 addition & 3 deletions Commands/Decrease Heading Level.tmCommand
Expand Up @@ -13,12 +13,10 @@ import re
hashes = ''
line = os.environ['TM_CURRENT_LINE']
m = re.match(r'(#{1,6})\s+(.+?)\s*(#*)$', line)
m = re.match(r'(#{2,6})\s*(.+?)\s*(#*)$', line)
if m:
hashes = m.group(1)
if len(hashes) > 1:
hashes = '#' * (len(hashes) - 1)
heading = m.group(2).strip()
sys.stdout.write('%s %s' % (hashes, heading))
Expand Down
8 changes: 2 additions & 6 deletions Commands/Increase Heading Level.tmCommand
Expand Up @@ -11,15 +11,11 @@ import os
import sys
import re
hashes = ''
line = os.environ['TM_CURRENT_LINE']
m = re.match(r'(#{1,6})\s+(.+?)\s*(#*)$', line)
m = re.match(r'(#{1,5}(?!#))\s*(.+?)\s*(#*)$', line)
if m:
hashes = m.group(1)
if len(hashes) < 6:
hashes = '#' * (len(hashes) + 1)
hashes = m.group(1) + '#'
heading = m.group(2).strip()
sys.stdout.write('%s %s' % (hashes, heading))
if m.group(3) != '':
Expand Down

0 comments on commit f1ff9ac

Please sign in to comment.