From 65616be08df5cfc5c29ff734ac3410c5ee105cc0 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Wed, 12 Jun 2019 15:45:46 -0400 Subject: [PATCH 1/4] add whitespace test for left strip --- docdown/platform_section.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docdown/platform_section.py b/docdown/platform_section.py index 5ab25d4..11c920b 100644 --- a/docdown/platform_section.py +++ b/docdown/platform_section.py @@ -23,6 +23,7 @@ class PlatformSectionPreprocessor(Preprocessor): !@\W*$''', re.MULTILINE | re.DOTALL | re.VERBOSE) INLINE_RE = re.compile(r'''@!\[(?P[\w, ]+)\](?P.*?)!@''', re.DOTALL | re.VERBOSE) + STARTSWITH_WHITESPACE_RE = re.compile(r'^\W+(@!\[|\n)') def __init__(self, platform_section, **kwargs): self.platform_section = platform_section.lower().strip() @@ -57,12 +58,16 @@ def process_block(self, text): m = self.BLOCK_RE.search(text) if m: sections = self.split_sections(m.group('sections')) + start = text[:m.start()] + end = text[m.end():] + if self.STARTSWITH_WHITESPACE_RE.match(end): + end = end.lstrip() if self.platform_section in sections: content = m.group('content') - text = '%s\n%s\n%s' % (text[:m.start()], content, text[m.end():]) + text = '%s%s%s' % (start, content, end) else: - text = '%s\n%s' % (text[:m.start()], text[m.end():]) + text = '%s%s' % (start, end) else: break return text From fcfce426af1828808ce34a0418ea0f40b0d26949 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Wed, 12 Jun 2019 15:46:17 -0400 Subject: [PATCH 2/4] remove unused block re --- docdown/platform_section.py | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/docdown/platform_section.py b/docdown/platform_section.py index 11c920b..dd4f28e 100644 --- a/docdown/platform_section.py +++ b/docdown/platform_section.py @@ -17,12 +17,8 @@ class PlatformSectionPreprocessor(Preprocessor): - BLOCK_RE = re.compile(r''' -^@!\[(?P[\w, ]+)\]\W*\n -(?P.*?)(?<=\n) -!@\W*$''', re.MULTILINE | re.DOTALL | re.VERBOSE) + PLATFORM_SECTION_RE = re.compile(r'''@!\[(?P[\w, ]+)\](?P.*?)!@''', re.DOTALL | re.VERBOSE) - INLINE_RE = re.compile(r'''@!\[(?P[\w, ]+)\](?P.*?)!@''', re.DOTALL | re.VERBOSE) STARTSWITH_WHITESPACE_RE = re.compile(r'^\W+(@!\[|\n)') def __init__(self, platform_section, **kwargs): @@ -31,33 +27,18 @@ def __init__(self, platform_section, **kwargs): def run(self, lines): text = "\n".join(lines) - text = self.process_inline(text) - text = self.process_block(text) + text = self.process_platform_sections(text) return text.split("\n") def split_sections(self, sections_group): return [section.lower().strip() for section in sections_group.split(',')] - def process_inline(self, text): + def process_platform_sections(self, text): while 1: - m = self.INLINE_RE.search(text) + m = self.PLATFORM_SECTION_RE.search(text) if m: sections = self.split_sections(m.group('sections')) - if self.platform_section in sections: - content = m.group('content') - text = '%s%s%s' % (text[:m.start()], content, text[m.end():]) - else: - text = '%s%s' % (text[:m.start()], text[m.end():].lstrip()) - else: - break - return text - - def process_block(self, text): - while 1: - m = self.BLOCK_RE.search(text) - if m: - sections = self.split_sections(m.group('sections')) start = text[:m.start()] end = text[m.end():] if self.STARTSWITH_WHITESPACE_RE.match(end): From 66cb1b49b4f36ad3fe7c9d7551932b8ec6dcaf13 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Wed, 12 Jun 2019 15:46:44 -0400 Subject: [PATCH 3/4] update tests --- tests/test_platform_section_extension.py | 28 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/test_platform_section_extension.py b/tests/test_platform_section_extension.py index be19130..7a9c9f0 100644 --- a/tests/test_platform_section_extension.py +++ b/tests/test_platform_section_extension.py @@ -160,7 +160,7 @@ def test_section_with_code_snippet(self): extensions=self.MARKDOWN_EXTENSIONS, output_format='html5' ) - expected_output = '

some Android content shown

\n

java\nString java = "asdf";

' + expected_output = '

some Android content shown

\n

java\nString java = "asdf";\n

' self.assertEqual(expected_output, html) def test_multiple_sections_with_code_snippet(self): @@ -181,7 +181,7 @@ def test_multiple_sections_with_code_snippet(self): extensions=self.MARKDOWN_EXTENSIONS, output_format='html5' ) - expected_output = '

some Android content shown

\n

java\nString java = "asdf";

' + expected_output = '

some Android content shown

\n

java\nString java = "asdf";\n

' self.assertEqual(expected_output, html) def test_inline_platform_section(self): @@ -232,7 +232,7 @@ def test_inline_platform_section(self): output_format='html5' ) expected_output = '

This is just some inline text for the Android platform.

' - print(html) + self.assertEqual(expected_output, html) def test_table_row_platform_section(self): @@ -286,4 +286,24 @@ def test_table_row_platform_section(self): ) self.assertEqual(expected_output, html) - print(html) + + def test_back_to_back_platform_section_tags(self): + text = 'Back to back @![ios]iOS!@@![android]Android!@ tags!' + html = markdown.markdown( + text, + extension_configs=self.build_config_for_platform_section('iOS'), + extensions=['markdown.extensions.tables'] + self.MARKDOWN_EXTENSIONS, + output_format='html5' + ) + + expected_output = '

Back to back iOS tags!

' + self.assertEqual(expected_output, html) + + html = markdown.markdown( + text, + extension_configs=self.build_config_for_platform_section('Android'), + extensions=['markdown.extensions.tables'] + self.MARKDOWN_EXTENSIONS, + output_format='html5' + ) + expected_output = '

Back to back Android tags!

' + self.assertEqual(expected_output, html) From 7230b793fde7098e3802ee01de6f14f326392051 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Wed, 12 Jun 2019 15:47:45 -0400 Subject: [PATCH 4/4] bump version to 0.2.5 --- HISTORY.rst | 5 +++++ docdown/__init__.py | 2 +- setup.cfg | 2 +- setup.py | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index c9326e0..25d7f24 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,11 @@ History ======= +0.2.5 (2019-06-12) +------------------ + +* Fix whitespace issues with back to back tags + 0.2.4 (2019-06-11) ------------------ diff --git a/docdown/__init__.py b/docdown/__init__.py index 6b1281d..25ecc88 100644 --- a/docdown/__init__.py +++ b/docdown/__init__.py @@ -2,4 +2,4 @@ __author__ = """Jason Emerick""" __email__ = 'jason@mobelux.com' -__version__ = '0.2.4' +__version__ = '0.2.5' diff --git a/setup.cfg b/setup.cfg index aeeb061..ae465d8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.4 +current_version = 0.2.5 commit = True tag = True diff --git a/setup.py b/setup.py index 2e725c1..71350e6 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ setup( name='docdown', - version='0.2.4', + version='0.2.5', description="DocDown is a Markdown extension for source code documentation.", long_description=readme + '\n\n' + history, author="Jason Emerick, Justin Michalicek",