diff options
author | A. Jesse Jiryu Davis <jesse@10gen.com> | 2014-01-06 22:10:51 -0500 |
---|---|---|
committer | A. Jesse Jiryu Davis <jesse@10gen.com> | 2014-01-06 22:10:51 -0500 |
commit | 436b420c1c6bb9db569d6ce4be2d06cff829aea9 (patch) | |
tree | bb15cbf1a860b9e161a290d782e358725eb3a25c /markdown | |
parent | c18ce238e39c2ccac92da25a6429bdade0db4dff (diff) | |
download | markdown-436b420c1c6bb9db569d6ce4be2d06cff829aea9.tar.gz markdown-436b420c1c6bb9db569d6ce4be2d06cff829aea9.tar.bz2 markdown-436b420c1c6bb9db569d6ce4be2d06cff829aea9.zip |
Support syntax for highlighted lines like: ```python hl_lines=“1 3”
Diffstat (limited to 'markdown')
-rw-r--r-- | markdown/extensions/codehilite.py | 11 | ||||
-rw-r--r-- | markdown/extensions/fenced_code.py | 7 |
2 files changed, 12 insertions, 6 deletions
diff --git a/markdown/extensions/codehilite.py b/markdown/extensions/codehilite.py index d05d495..7f20efe 100644 --- a/markdown/extensions/codehilite.py +++ b/markdown/extensions/codehilite.py @@ -35,14 +35,14 @@ except ImportError: def parse_hl_lines(expr): """Support our syntax for emphasizing certain lines of code. - expr should be like '{1,2}' to emphasize lines 1 and 2 of a code block. + expr should be like '1 2' to emphasize lines 1 and 2 of a code block. Returns a list of ints, the line numbers to emphasize. """ if not expr: return [] try: - return map(int, expr.strip('{}').split(',')) + return map(int, expr.split()) except ValueError: return [] @@ -151,7 +151,9 @@ class CodeHilite(object): (e.i.: :::python), line numbering is left in the current state - off by default. - Also parses optional list of highlight lines, like :::python{1,3} + Also parses optional list of highlight lines, like: + + :::python hl_lines="1 3" """ import re @@ -165,7 +167,8 @@ class CodeHilite(object): (?:(?:^::+)|(?P<shebang>^[#]!)) # Shebang or 2 or more colons (?P<path>(?:/\w+)*[/ ])? # Zero or 1 path (?P<lang>[\w+-]*) # The language - (?P<hl_lines>\{.*?})? # Maybe hl_lines + \s* # Arbitrary whitespace + (hl_lines="(?P<hl_lines>.*?)")? # Maybe highlight lines ''', re.VERBOSE) # search first line for shebang m = c.search(fl) diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index 64ff769..6ee6759 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -62,7 +62,7 @@ Optionally backticks instead of tildes as per how github's code block markdown i If the codehighlite extension and Pygments are installed, lines can be highlighted: >>> text = ''' - ... ```{1,3} + ... ```hl_lines="1 3" ... line 1 ... line 2 ... line 3 @@ -108,7 +108,10 @@ class FencedCodeExtension(Extension): class FencedBlockPreprocessor(Preprocessor): FENCED_BLOCK_RE = re.compile(r''' -(?P<fence>^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P<lang>[a-zA-Z0-9_+-]*)\}?)?[ ]*(?P<hl_lines>\{.*?})?[ ]*\n +(?P<fence>^(?:~{3,}|`{3,}))[ ]* # Opening ``` or ~~~ +(\{?\.?(?P<lang>[a-zA-Z0-9_+-]*))?[ ]* # Optional {, and lang +(hl_lines="(?P<hl_lines>.*?)")?[ ]* # Optional highlight lines +}?[ ]*\n # Optional closing } (?P<code>.*?)(?<=\n) (?P=fence)[ ]*$''', re.MULTILINE | re.DOTALL | re.VERBOSE) CODE_WRAP = '<pre><code%s>%s</code></pre>' |