Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
miyakogi committed Aug 13, 2018
2 parents b77c275 + f6ed15d commit e88a711
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ matrix:
- python: 3.5
env: TOXENV=py
- python: 3.6
env: TOXENV=py,codecov
env: TOXENV=py,sphinx-dev,codecov
- python: 3.7-dev
env: TOXENV=py
- python: pypy
env: TOXENV=py
- python: pypy3
Expand Down
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Version 0.2
## Version 0.2.0 (2018-08-13)

(next version)
* Add `start-line` and `end-line` option to `mdinclude` directive
* Add `anonymous_references` option ([#26](https://github.com/miyakogi/m2r/pull/26))

### Version 0.1.15 (2018-06-30)

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ flake8: ## run flake8 syntax check

.PHONY: docs
docs: ## build document
@sphinx-build -E -W -n -j 4 -b html docs docs/_build/html
@sphinx-build -E -W -n -j auto -b html docs docs/_build/html

.PHONY: sphinx
sphinx: ## run document build server
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
# built documents.
#
# The short X.Y version.
version = '0.1.15'
version = '0.2.0'
# The full version, including alpha/beta/rc tags.
release = '0.1.15'
release = '0.2.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -145,7 +145,7 @@

# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
#html_title = 'M2R v0.1.15'
#html_title = 'M2R v0.2.0'

# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
Expand Down
34 changes: 34 additions & 0 deletions docs/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,40 @@ The below is reST-style math-block.

E = mc^2


### Include Markdown file

To include markdown file:

```rest
.. mdinclude:: path-to-flie.md
```

To include markdown file with specific lines:

```rest
.. mdinclude:: included.md
:start-line: 2
:end-line: -2
```

Original ``included.md`` file is:

.. include:: included.md
:code: md

This file included as:

```md
#### Includs this line
```

and results in HTML as below:

.. mdinclude:: included.md
:start-line: 2
:end-line: -2

### Footnote

Footnote[^1] and footnote[^key] with markdown.
Expand Down
5 changes: 5 additions & 0 deletions docs/included.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NOT-INCLUDED

#### Includs this line

NOT-INCLUDED
17 changes: 15 additions & 2 deletions m2r.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
_open = open
from urllib.parse import urlparse

__version__ = '0.1.15'
__version__ = '0.2.0'
_is_sphinx = False
prolog = '''\
.. role:: raw-html-m2r(raw)
Expand Down Expand Up @@ -535,6 +535,9 @@ def post_process(self, text):


class M2RParser(rst.Parser, object):
# Explicitly tell supported formats to sphinx
supported = ('markdown', 'md', 'mkd')

def parse(self, inputstrings, document):
if isinstance(inputstrings, statemachine.StringList):
inputstring = '\n'.join(inputstrings)
Expand All @@ -557,6 +560,10 @@ class MdInclude(rst.Directive):
"""
required_arguments = 1
optional_arguments = 0
option_spec = {
'start-line': int,
'end-line': int,
}

def run(self):
"""Most of this method is from ``docutils.parser.rst.Directive``.
Expand Down Expand Up @@ -596,8 +603,14 @@ def run(self):
(self.name, ErrorString(error)))

# read from the file
startline = self.options.get('start-line', None)
endline = self.options.get('end-line', None)
try:
rawtext = include_file.read()
if startline or (endline is not None):
lines = include_file.readlines()
rawtext = ''.join(lines[startline:endline])
else:
rawtext = include_file.read()
except UnicodeError as error:
raise self.severe('Problem with "%s" directive:\n%s' %
(self.name, ErrorString(error)))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

setup(
name='m2r',
version='0.1.15',
version='0.2.0',
description='Markdown and reStructuredText in a single file.',
long_description=readme,
author='Hiroyuki Takagi',
Expand Down
12 changes: 10 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,34,35,36,py,py3}
envlist = py{27,34,35,36,37,py,py3},sphinx-dev

[testenv]
whitelist_externals =
Expand All @@ -9,10 +9,18 @@ deps =
commands =
flake8 m2r.py setup.py tests
coverage run -m unittest discover tests
coverage run -a -m sphinx -b html -d docs/_build/toctree -E -W -n -j 4 -q docs docs/_build/html
coverage run -a -m sphinx -b html -d docs/_build/toctree -E -W -n -j auto -q docs docs/_build/html
coverage report
make clean

[testenv:sphinx-dev]
recreate = true
deps =
git+https://github.com/sphinx-doc/sphinx
commands =
sphinx-build -b html -d docs/_build/toctree -E -W -n -j auto docs docs/_build/html
make clean

[testenv:codecov]
passenv = CI TRAVIS TRAVIS_*
deps = codecov
Expand Down

0 comments on commit e88a711

Please sign in to comment.