From 74e0566dbf527bbbc4844a3682afd33c0dbf6847 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 6 Jun 2016 21:39:21 -0500 Subject: [PATCH 1/3] Transform files with other endings besides .md --- recommonmark/transform.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/recommonmark/transform.py b/recommonmark/transform.py index c762653..fde861d 100644 --- a/recommonmark/transform.py +++ b/recommonmark/transform.py @@ -26,6 +26,7 @@ class AutoStructify(transforms.Transform): 'enable_eval_rst': True, 'enable_math': True, 'enable_inline_math': True, + 'commonmark_suffixes': ['.md'], 'url_resolver': lambda x: x, } @@ -313,10 +314,7 @@ class AutoStructify(transforms.Transform): def apply(self): """Apply the transformation by configuration.""" - # only transform markdowns source = self.document['source'] - if not source.endswith('.md'): - return self.reporter = self.document.reporter self.reporter.info('AutoStructify: %s' % source) @@ -328,6 +326,11 @@ class AutoStructify(transforms.Transform): except: self.reporter.warning('recommonmark_config not setted,' ' proceed default setting') + + # only transform markdowns + if not source.endswith(tuple(config['commonmark_suffixes'])): + return + self.url_resolver = config['url_resolver'] assert callable(self.url_resolver) From 391bbe4e687c261d089088af1f1cd801b4f23a2a Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 6 Jun 2016 23:56:37 -0500 Subject: [PATCH 2/3] Remove pep8 whitespace --- recommonmark/transform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recommonmark/transform.py b/recommonmark/transform.py index fde861d..6b3d0b4 100644 --- a/recommonmark/transform.py +++ b/recommonmark/transform.py @@ -326,7 +326,7 @@ class AutoStructify(transforms.Transform): except: self.reporter.warning('recommonmark_config not setted,' ' proceed default setting') - + # only transform markdowns if not source.endswith(tuple(config['commonmark_suffixes'])): return From 0ff83a9091dfa6b858c3951b1461965075fa8407 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 12 Jun 2016 03:12:15 -0500 Subject: [PATCH 3/3] Add tests for checking custom file extensions --- tests/sphinx_custom_md/conf.py | 30 +++++++++++++++++++++++++++ tests/sphinx_custom_md/index.markdown | 15 ++++++++++++++ tests/test_sphinx.py | 9 ++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/sphinx_custom_md/conf.py create mode 100644 tests/sphinx_custom_md/index.markdown diff --git a/tests/sphinx_custom_md/conf.py b/tests/sphinx_custom_md/conf.py new file mode 100644 index 0000000..b29157b --- /dev/null +++ b/tests/sphinx_custom_md/conf.py @@ -0,0 +1,30 @@ + +# -*- coding: utf-8 -*- + +from recommonmark.parser import CommonMarkParser +from recommonmark.transform import AutoStructify + +templates_path = ['_templates'] +source_suffix = '.markdown' +source_parsers = { '.markdown': CommonMarkParser } +master_doc = 'index' +project = u'sphinxproj' +copyright = u'2015, rtfd' +author = u'rtfd' +version = '0.1' +release = '0.1' +language = None +exclude_patterns = ['_build'] +highlight_language = 'python' +pygments_style = 'sphinx' +todo_include_todos = False +html_theme = 'alabaster' +html_static_path = ['_static'] +htmlhelp_basename = 'sphinxproj' + +def setup(app): + app.add_config_value('recommonmark_config', { + 'enable_eval_rst': True, + 'commonmark_suffixes': ['.markdown', '.hpp'], + }, True) + app.add_transform(AutoStructify) diff --git a/tests/sphinx_custom_md/index.markdown b/tests/sphinx_custom_md/index.markdown new file mode 100644 index 0000000..e65f3b6 --- /dev/null +++ b/tests/sphinx_custom_md/index.markdown @@ -0,0 +1,15 @@ +Header +====== + +A paragraph + +```eval_rst ++-----+------+ +| abc | data | ++=====+======+ +| a | 1 | ++-----+------+ +``` + +Another paragraph + diff --git a/tests/test_sphinx.py b/tests/test_sphinx.py index 892568f..d261239 100644 --- a/tests/test_sphinx.py +++ b/tests/test_sphinx.py @@ -46,3 +46,12 @@ class IndentedCodeTests(SphinxIntegrationTests): '_build/text/index.html', '
' ) + +class CustomExtensionTests(SphinxIntegrationTests): + + def test_integration(self): + self._run_test( + 'sphinx_custom_md', + '_build/text/index.html', + '' + )