Skip to content

Commit b7ec40e

Browse files
authored
Merge pull request #19 from livio/inline-platform-sections
Add Inline platform sections
2 parents e7c7507 + e30bb5c commit b7ec40e

File tree

7 files changed

+75
-9
lines changed

7 files changed

+75
-9
lines changed

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.3 (2019-06-06)
6+
------------------
7+
8+
* Add support for inline platform section tags
9+
510
0.2.2 (2019-06-05)
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.2'
5+
__version__ = '0.2.3'

docdown/platform_section.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,55 @@
1717

1818
class PlatformSectionPreprocessor(Preprocessor):
1919

20-
RE = re.compile(r'''
20+
BLOCK_RE = re.compile(r'''
2121
^@!\[(?P<sections>[\w, ]+)\]\W*\n
2222
(?P<content>.*?)(?<=\n)
2323
!@\W*$''', re.MULTILINE | re.DOTALL | re.VERBOSE)
2424

25+
INLINE_RE = re.compile(r'''@!\[(?P<sections>[\w, ]+)\](?P<content>.*?)!@''', re.DOTALL | re.VERBOSE)
26+
2527
def __init__(self, platform_section, **kwargs):
2628
self.platform_section = platform_section.lower().strip()
2729
super(PlatformSectionPreprocessor, self).__init__(**kwargs)
2830

2931
def run(self, lines):
3032
text = "\n".join(lines)
33+
text = self.process_inline(text)
34+
text = self.process_block(text)
35+
return text.split("\n")
36+
37+
def split_sections(self, sections_group):
38+
return [section.lower().strip() for section in sections_group.split(',')]
39+
40+
def process_inline(self, text):
3141
while 1:
32-
m = self.RE.search(text)
42+
m = self.INLINE_RE.search(text)
3343
if m:
34-
sections = [section.lower().strip() for section in m.group('sections').split(',')]
44+
sections = self.split_sections(m.group('sections'))
3545

36-
content = m.group('content')
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():])
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'))
3760

3861
if self.platform_section in sections:
62+
content = m.group('content')
3963
text = '%s\n%s\n%s' % (text[:m.start()], content, text[m.end():])
4064
else:
4165
text = '%s\n%s' % (text[:m.start()], text[m.end():])
4266
else:
4367
break
44-
45-
return text.split("\n")
68+
return text
4669

4770

4871
class PlatformSectionExtension(Extension):

docs/extensions/platform_sections.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ In documents
3737
This section will be displayed for Java SE and EE builds.
3838
!@
3939

40+
Inline platform section tags are also supported:
41+
42+
.. code-block:: html5
43+
44+
### 1. Creating an App Service Manifest
45+
The first step to publishing is to create an @![iOS]`SDLAppServiceManifest`!@ @![Android, JavaSE, JavaEE]`AppServiceManifest`!@ object.
46+
4047
Python
4148
--------------
4249

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.2
2+
current_version = 0.2.3
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.2',
23+
version='0.2.3',
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,34 @@ def test_multiple_sections_with_code_snippet(self):
183183
)
184184
expected_output = '<p>some Android content shown</p>\n<p><code>java\nString java = "asdf";</code></p>'
185185
self.assertEqual(expected_output, html)
186+
187+
def test_inline_platform_section(self):
188+
text = ('### 1. Creating an App Service Manifest\n'
189+
'The first step to publishing is to create an @![iOS]`SDLAppServiceManifest`!@ @![Android, JavaSE, JavaEE]`AppServiceManifest`!@ object.\n')
190+
191+
html = markdown.markdown(
192+
text,
193+
extension_configs=self.build_config_for_platform_section('Android'),
194+
extensions=self.MARKDOWN_EXTENSIONS,
195+
output_format='html5'
196+
)
197+
expected_output = '<h3>1. Creating an App Service Manifest</h3>\n<p>The first step to publishing is to create an <code>AppServiceManifest</code> object.</p>'
198+
self.assertEqual(expected_output, html)
199+
200+
html = markdown.markdown(
201+
text,
202+
extension_configs=self.build_config_for_platform_section('JavaEE'),
203+
extensions=self.MARKDOWN_EXTENSIONS,
204+
output_format='html5'
205+
)
206+
expected_output = '<h3>1. Creating an App Service Manifest</h3>\n<p>The first step to publishing is to create an <code>AppServiceManifest</code> object.</p>'
207+
self.assertEqual(expected_output, html)
208+
209+
html = markdown.markdown(
210+
text,
211+
extension_configs=self.build_config_for_platform_section('iOS'),
212+
extensions=self.MARKDOWN_EXTENSIONS,
213+
output_format='html5'
214+
)
215+
expected_output = '<h3>1. Creating an App Service Manifest</h3>\n<p>The first step to publishing is to create an <code>SDLAppServiceManifest</code> object.</p>'
216+
self.assertEqual(expected_output, html)

0 commit comments

Comments
 (0)