From c316ac3d870854409f40f00de48a1ba6a1f9b382 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Thu, 6 Jun 2019 11:52:41 -0400 Subject: [PATCH 1/3] Add support for inline version of platform sections --- docdown/platform_section.py | 35 ++++++++++++++++++++---- tests/test_platform_section_extension.py | 31 +++++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/docdown/platform_section.py b/docdown/platform_section.py index 469516d..a14971e 100644 --- a/docdown/platform_section.py +++ b/docdown/platform_section.py @@ -17,32 +17,55 @@ class PlatformSectionPreprocessor(Preprocessor): - RE = re.compile(r''' + BLOCK_RE = re.compile(r''' ^@!\[(?P[\w, ]+)\]\W*\n (?P.*?)(?<=\n) !@\W*$''', re.MULTILINE | re.DOTALL | re.VERBOSE) + INLINE_RE = re.compile(r'''@!\[(?P[\w, ]+)\](?P.*?)!@''', re.DOTALL | re.VERBOSE) + def __init__(self, platform_section, **kwargs): self.platform_section = platform_section.lower().strip() super(PlatformSectionPreprocessor, self).__init__(**kwargs) def run(self, lines): text = "\n".join(lines) + text = self.process_inline(text) + text = self.process_block(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): while 1: - m = self.RE.search(text) + m = self.INLINE_RE.search(text) if m: - sections = [section.lower().strip() for section in m.group('sections').split(',')] + sections = self.split_sections(m.group('sections')) - content = m.group('content') + 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():]) + 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')) if self.platform_section in sections: + content = m.group('content') text = '%s\n%s\n%s' % (text[:m.start()], content, text[m.end():]) else: text = '%s\n%s' % (text[:m.start()], text[m.end():]) else: break - - return text.split("\n") + return text class PlatformSectionExtension(Extension): diff --git a/tests/test_platform_section_extension.py b/tests/test_platform_section_extension.py index 3c0c14f..c359796 100644 --- a/tests/test_platform_section_extension.py +++ b/tests/test_platform_section_extension.py @@ -183,3 +183,34 @@ def test_multiple_sections_with_code_snippet(self): ) expected_output = '

some Android content shown

\n

java\nString java = "asdf";

' self.assertEqual(expected_output, html) + + def test_inline_platform_section(self): + text = ('### 1. Creating an App Service Manifest\n' + 'The first step to publishing is to create an @![iOS]`SDLAppServiceManifest`!@ @![Android, JavaSE, JavaEE]`AppServiceManifest`!@ object.\n') + + html = markdown.markdown( + text, + extension_configs=self.build_config_for_platform_section('Android'), + extensions=self.MARKDOWN_EXTENSIONS, + output_format='html5' + ) + expected_output = '

1. Creating an App Service Manifest

\n

The first step to publishing is to create an AppServiceManifest object.

' + self.assertEqual(expected_output, html) + + html = markdown.markdown( + text, + extension_configs=self.build_config_for_platform_section('JavaEE'), + extensions=self.MARKDOWN_EXTENSIONS, + output_format='html5' + ) + expected_output = '

1. Creating an App Service Manifest

\n

The first step to publishing is to create an AppServiceManifest object.

' + self.assertEqual(expected_output, html) + + html = markdown.markdown( + text, + extension_configs=self.build_config_for_platform_section('iOS'), + extensions=self.MARKDOWN_EXTENSIONS, + output_format='html5' + ) + expected_output = '

1. Creating an App Service Manifest

\n

The first step to publishing is to create an SDLAppServiceManifest object.

' + self.assertEqual(expected_output, html) From 8ceacdd8c0a5ed3806b632a094ce97382f36c7d8 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Thu, 6 Jun 2019 11:55:10 -0400 Subject: [PATCH 2/3] update docs --- docs/extensions/platform_sections.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/extensions/platform_sections.rst b/docs/extensions/platform_sections.rst index 3845b64..d00eead 100644 --- a/docs/extensions/platform_sections.rst +++ b/docs/extensions/platform_sections.rst @@ -37,6 +37,13 @@ In documents This section will be displayed for Java SE and EE builds. !@ +Inline platform section tags are also supported: + +.. code-block:: html5 + + ### 1. Creating an App Service Manifest + The first step to publishing is to create an @![iOS]`SDLAppServiceManifest`!@ @![Android, JavaSE, JavaEE]`AppServiceManifest`!@ object. + Python -------------- From e30bb5c4a764e20b62c96a7ac747e5d06cb29089 Mon Sep 17 00:00:00 2001 From: Jason Emerick Date: Thu, 6 Jun 2019 11:56:38 -0400 Subject: [PATCH 3/3] bump version to 0.2.3 --- 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 dc24ebd..2197731 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,11 @@ History ======= +0.2.3 (2019-06-06) +------------------ + +* Add support for inline platform section tags + 0.2.2 (2019-06-05) ------------------ diff --git a/docdown/__init__.py b/docdown/__init__.py index cd85e6f..9850b71 100644 --- a/docdown/__init__.py +++ b/docdown/__init__.py @@ -2,4 +2,4 @@ __author__ = """Jason Emerick""" __email__ = 'jason@mobelux.com' -__version__ = '0.2.2' +__version__ = '0.2.3' diff --git a/setup.cfg b/setup.cfg index a927486..13ee55d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.2 +current_version = 0.2.3 commit = True tag = True diff --git a/setup.py b/setup.py index 2261821..033261e 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ setup( name='docdown', - version='0.2.2', + version='0.2.3', description="DocDown is a Markdown extension for source code documentation.", long_description=readme + '\n\n' + history, author="Jason Emerick, Justin Michalicek",