Skip to content

Commit ac868c3

Browse files
authored
Merge pull request #21 from livio/0.2.5
Fix whitespace issues with back to back tags
2 parents f3df9d4 + 7230b79 commit ac868c3

6 files changed

Lines changed: 43 additions & 32 deletions

File tree

HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
History
33
=======
44

5+
0.2.5 (2019-06-12)
6+
------------------
7+
8+
* Fix whitespace issues with back to back tags
9+
510
0.2.4 (2019-06-11)
611
------------------
712

docdown/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = """Jason Emerick"""
44
__email__ = 'jason@mobelux.com'
5-
__version__ = '0.2.4'
5+
__version__ = '0.2.5'

docdown/platform_section.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,38 @@
1717

1818
class PlatformSectionPreprocessor(Preprocessor):
1919

20-
BLOCK_RE = re.compile(r'''
21-
^@!\[(?P<sections>[\w, ]+)\]\W*\n
22-
(?P<content>.*?)(?<=\n)
23-
!@\W*$''', re.MULTILINE | re.DOTALL | re.VERBOSE)
20+
PLATFORM_SECTION_RE = re.compile(r'''@!\[(?P<sections>[\w, ]+)\](?P<content>.*?)!@''', re.DOTALL | re.VERBOSE)
2421

25-
INLINE_RE = re.compile(r'''@!\[(?P<sections>[\w, ]+)\](?P<content>.*?)!@''', re.DOTALL | re.VERBOSE)
22+
STARTSWITH_WHITESPACE_RE = re.compile(r'^\W+(@!\[|\n)')
2623

2724
def __init__(self, platform_section, **kwargs):
2825
self.platform_section = platform_section.lower().strip()
2926
super(PlatformSectionPreprocessor, self).__init__(**kwargs)
3027

3128
def run(self, lines):
3229
text = "\n".join(lines)
33-
text = self.process_inline(text)
34-
text = self.process_block(text)
30+
text = self.process_platform_sections(text)
3531
return text.split("\n")
3632

3733
def split_sections(self, sections_group):
3834
return [section.lower().strip() for section in sections_group.split(',')]
3935

40-
def process_inline(self, text):
36+
def process_platform_sections(self, text):
4137
while 1:
42-
m = self.INLINE_RE.search(text)
38+
m = self.PLATFORM_SECTION_RE.search(text)
4339
if m:
4440
sections = self.split_sections(m.group('sections'))
4541

46-
if self.platform_section in sections:
47-
content = m.group('content')
48-
text = '%s%s%s' % (text[:m.start()], content, text[m.end():])
49-
else:
50-
text = '%s%s' % (text[:m.start()], text[m.end():].lstrip())
51-
else:
52-
break
53-
return text
54-
55-
def process_block(self, text):
56-
while 1:
57-
m = self.BLOCK_RE.search(text)
58-
if m:
59-
sections = self.split_sections(m.group('sections'))
42+
start = text[:m.start()]
43+
end = text[m.end():]
44+
if self.STARTSWITH_WHITESPACE_RE.match(end):
45+
end = end.lstrip()
6046

6147
if self.platform_section in sections:
6248
content = m.group('content')
63-
text = '%s\n%s\n%s' % (text[:m.start()], content, text[m.end():])
49+
text = '%s%s%s' % (start, content, end)
6450
else:
65-
text = '%s\n%s' % (text[:m.start()], text[m.end():])
51+
text = '%s%s' % (start, end)
6652
else:
6753
break
6854
return text

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.2.4
2+
current_version = 0.2.5
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name='docdown',
23-
version='0.2.4',
23+
version='0.2.5',
2424
description="DocDown is a Markdown extension for source code documentation.",
2525
long_description=readme + '\n\n' + history,
2626
author="Jason Emerick, Justin Michalicek",

tests/test_platform_section_extension.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_section_with_code_snippet(self):
160160
extensions=self.MARKDOWN_EXTENSIONS,
161161
output_format='html5'
162162
)
163-
expected_output = '<p>some Android content shown</p>\n<p><code>java\nString java = "asdf";</code></p>'
163+
expected_output = '<p>some Android content shown</p>\n<p><code>java\nString java = "asdf";</code>\n</p>'
164164
self.assertEqual(expected_output, html)
165165

166166
def test_multiple_sections_with_code_snippet(self):
@@ -181,7 +181,7 @@ def test_multiple_sections_with_code_snippet(self):
181181
extensions=self.MARKDOWN_EXTENSIONS,
182182
output_format='html5'
183183
)
184-
expected_output = '<p>some Android content shown</p>\n<p><code>java\nString java = "asdf";</code></p>'
184+
expected_output = '<p>some Android content shown</p>\n<p><code>java\nString java = "asdf";</code>\n</p>'
185185
self.assertEqual(expected_output, html)
186186

187187
def test_inline_platform_section(self):
@@ -232,7 +232,7 @@ def test_inline_platform_section(self):
232232
output_format='html5'
233233
)
234234
expected_output = '<p>This is just some inline text for the Android platform.</p>'
235-
print(html)
235+
236236
self.assertEqual(expected_output, html)
237237

238238
def test_table_row_platform_section(self):
@@ -286,4 +286,24 @@ def test_table_row_platform_section(self):
286286
)
287287

288288
self.assertEqual(expected_output, html)
289-
print(html)
289+
290+
def test_back_to_back_platform_section_tags(self):
291+
text = 'Back to back @![ios]iOS!@@![android]Android!@ tags!'
292+
html = markdown.markdown(
293+
text,
294+
extension_configs=self.build_config_for_platform_section('iOS'),
295+
extensions=['markdown.extensions.tables'] + self.MARKDOWN_EXTENSIONS,
296+
output_format='html5'
297+
)
298+
299+
expected_output = '<p>Back to back iOS tags!</p>'
300+
self.assertEqual(expected_output, html)
301+
302+
html = markdown.markdown(
303+
text,
304+
extension_configs=self.build_config_for_platform_section('Android'),
305+
extensions=['markdown.extensions.tables'] + self.MARKDOWN_EXTENSIONS,
306+
output_format='html5'
307+
)
308+
expected_output = '<p>Back to back Android tags!</p>'
309+
self.assertEqual(expected_output, html)

0 commit comments

Comments
 (0)