mirror of
https://github.com/vale981/recommonmark
synced 2025-03-06 02:21:38 -05:00
Merge pull request #48 from pfultz2/master
Transform files with other endings besides .md
This commit is contained in:
commit
e81b0a0de1
4 changed files with 60 additions and 3 deletions
|
@ -26,6 +26,7 @@ class AutoStructify(transforms.Transform):
|
||||||
'enable_eval_rst': True,
|
'enable_eval_rst': True,
|
||||||
'enable_math': True,
|
'enable_math': True,
|
||||||
'enable_inline_math': True,
|
'enable_inline_math': True,
|
||||||
|
'commonmark_suffixes': ['.md'],
|
||||||
'url_resolver': lambda x: x,
|
'url_resolver': lambda x: x,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,10 +314,7 @@ class AutoStructify(transforms.Transform):
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
"""Apply the transformation by configuration."""
|
"""Apply the transformation by configuration."""
|
||||||
# only transform markdowns
|
|
||||||
source = self.document['source']
|
source = self.document['source']
|
||||||
if not source.endswith('.md'):
|
|
||||||
return
|
|
||||||
|
|
||||||
self.reporter = self.document.reporter
|
self.reporter = self.document.reporter
|
||||||
self.reporter.info('AutoStructify: %s' % source)
|
self.reporter.info('AutoStructify: %s' % source)
|
||||||
|
@ -328,6 +326,11 @@ class AutoStructify(transforms.Transform):
|
||||||
except:
|
except:
|
||||||
self.reporter.warning('recommonmark_config not setted,'
|
self.reporter.warning('recommonmark_config not setted,'
|
||||||
' proceed default setting')
|
' proceed default setting')
|
||||||
|
|
||||||
|
# only transform markdowns
|
||||||
|
if not source.endswith(tuple(config['commonmark_suffixes'])):
|
||||||
|
return
|
||||||
|
|
||||||
self.url_resolver = config['url_resolver']
|
self.url_resolver = config['url_resolver']
|
||||||
assert callable(self.url_resolver)
|
assert callable(self.url_resolver)
|
||||||
|
|
||||||
|
|
30
tests/sphinx_custom_md/conf.py
Normal file
30
tests/sphinx_custom_md/conf.py
Normal file
|
@ -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)
|
15
tests/sphinx_custom_md/index.markdown
Normal file
15
tests/sphinx_custom_md/index.markdown
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Header
|
||||||
|
======
|
||||||
|
|
||||||
|
A paragraph
|
||||||
|
|
||||||
|
```eval_rst
|
||||||
|
+-----+------+
|
||||||
|
| abc | data |
|
||||||
|
+=====+======+
|
||||||
|
| a | 1 |
|
||||||
|
+-----+------+
|
||||||
|
```
|
||||||
|
|
||||||
|
Another paragraph
|
||||||
|
|
|
@ -46,3 +46,12 @@ class IndentedCodeTests(SphinxIntegrationTests):
|
||||||
'_build/text/index.html',
|
'_build/text/index.html',
|
||||||
'<div class="highlight">'
|
'<div class="highlight">'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class CustomExtensionTests(SphinxIntegrationTests):
|
||||||
|
|
||||||
|
def test_integration(self):
|
||||||
|
self._run_test(
|
||||||
|
'sphinx_custom_md',
|
||||||
|
'_build/text/index.html',
|
||||||
|
'</table>'
|
||||||
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue