Skip to content

Commit

Permalink
allow whitespace before code attributes
Browse files Browse the repository at this point in the history
fixes #29
  • Loading branch information
aaren committed Sep 22, 2015
1 parent d45bc0b commit ed15ed7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions notedown/notedown.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ class MarkdownReader(NotebookReader):
fenced_regex = r"""
^(?P<raw>
(?P<fence>`{3,}|~{3,}) # a line starting with a fence of 3 or more ` or ~
(?P<attributes>.*) # followed by the group 'attributes'
\n # followed by a newline
(?P<content> # start a group 'content'
[ \t]* # followed by any amount of whitespace,
(?P<attributes>.*) # the group 'attributes',
\n # a newline,
(?P<content> # the 'content' group,
[\s\S]*?) # that includes anything
\n(?P=fence)$\n) # up until the same fence that we started with
"""
Expand Down
25 changes: 25 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@
```
"""

attribute_markdown = u"""Attribute test
```lang
code1
```
```{.attr}
code2
```
``` {.attr}
code3
```
"""

ref_attributes = ['lang', r'{.attr}', r'{.attr}']


def create_json_notebook(markdown):
reader = notedown.MarkdownReader()
Expand Down Expand Up @@ -280,6 +297,14 @@ def test_format_agnostic():
assert(fenced_markdown_cells == indented_markdown_cells)


def test_attributes():
"""Are code block attributes correctly parsed?"""
cells = parse_cells(attribute_markdown)
attributes = [cell['attributes'] for cell in cells if cell['type'] == 'code']
for attr, ref in zip(attributes, ref_attributes):
assert attr == ref


def test_pre_process_text():
"""test the stripping of blank lines"""
block = {}
Expand Down

0 comments on commit ed15ed7

Please sign in to comment.