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.1.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
miyakogi committed Sep 11, 2017
2 parents 38933ce + 21aef13 commit 9e0e563
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ script:
- coverage report --include="*m2r.py,*m2r/tests*"
- cp -f .coverage ../
after_success:
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then codecov && coveralls; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then codecov -b $TRAVIS_BRANCH && coveralls; fi
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

(next version)

### Version 0.1.12 (2017-09-11)

* Support multi byte characters for heading

### Version 0.1.11 (2017-08-30)

* Add metadata for sphinx
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
# built documents.
#
# The short X.Y version.
version = '0.1.11'
version = '0.1.12'
# The full version, including alpha/beta/rc tags.
release = '0.1.11'
release = '0.1.12'

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

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

# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
Expand Down
21 changes: 14 additions & 7 deletions m2r.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
from __future__ import print_function, unicode_literals
import os
import re
import sys
from argparse import ArgumentParser, Namespace

from docutils import statemachine, nodes, io, utils
from docutils.parsers import rst
from docutils.core import ErrorString
from docutils.utils import SafeString
from docutils.utils import SafeString, column_width
import mistune

__version__ = '0.1.11'
if sys.version_info < (3, ):
from codecs import open as _open
else:
_open = open

__version__ = '0.1.12'
_is_sphinx = False
prolog = '''\
.. role:: raw-html-m2r(raw)
Expand Down Expand Up @@ -214,7 +220,8 @@ def header(self, text, level, raw=None):
:param level: a number for the header level, for example: 1.
:param raw: raw text content of the header.
"""
return '\n{0}\n{1}\n'.format(text, self.hmarks[level] * len(text))
return '\n{0}\n{1}\n'.format(text,
self.hmarks[level] * column_width(text))

def hrule(self):
"""Rendering method for ``<hr>`` tag."""
Expand Down Expand Up @@ -552,24 +559,24 @@ def convert(text, **kwargs):
return M2R(**kwargs)(text)


def parse_from_file(file, **kwargs):
def parse_from_file(file, encoding='utf-8', **kwargs):
if not os.path.exists(file):
raise OSError('No such file exists: {}'.format(file))
with open(file) as f:
with _open(file, encoding=encoding) as f:
src = f.read()
output = convert(src, **kwargs)
return output


def save_to_file(file, src):
def save_to_file(file, src, encoding='utf-8', **kwargs):
target = os.path.splitext(file)[0] + '.rst'
if not options.overwrite and os.path.exists(target):
confirm = input('{} already exists. overwrite it? [y/n]: '.format(
target))
if confirm.upper() not in ('Y', 'YES'):
print('skip {}'.format(file))
return
with open(target, 'w') as f:
with _open(target, 'w', encoding=encoding) as f:
f.write(src)


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.11',
version='0.1.12',
description='Markdown and reStructuredText in a single file.',
long_description=readme,
author='Hiroyuki Takagi',
Expand Down
2 changes: 2 additions & 0 deletions tests/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
## SubTitle

__content__

## サブタイトル
3 changes: 3 additions & 0 deletions tests/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ SubTitle
--------

**content**

サブタイトル
------------
5 changes: 5 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals

import sys
import os
from os import path
Expand All @@ -13,6 +15,9 @@
if sys.version_info < (3, ):
from mock import patch
_builtin = '__builtin__'
from codecs import open as _open
from functools import partial
open = partial(_open, encoding='utf-8')
else:
from unittest.mock import patch
_builtin = 'builtins'
Expand Down
7 changes: 7 additions & 0 deletions tests/test_renderer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals

from unittest import TestCase, skip

from docutils.core import Publisher
Expand Down Expand Up @@ -338,6 +340,11 @@ def test_heading(self):
out = self.conv(src)
self.assertEqual(out, '\nhead 1\n' + '=' * 6 + '\n')

def test_heading_multibyte(self):
src = '# マルチバイト文字\n'
out = self.conv(src)
self.assertEqual(out, '\nマルチバイト文字\n' + '=' * 16 + '\n')


class TestList(RendererTestBase):
def test_ul(self):
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ commands =
flake8 {toxinidir}/m2r.py {toxinidir}/setup.py {toxinidir}/tests
coverage run -m unittest discover {toxinidir}/tests
make -C {toxinidir} clean-testdoc
coverage run -a -m sphinx -b html -d {toxinidir}/docs/_build/toctree -E -W -n -j 4 -q {toxinidir}/docs {toxinidir}/docs/_build/html
# only python 3.5 fails `-j 4`, why?
py35: coverage run -a -m sphinx -b html -d {toxinidir}/docs/_build/toctree -E -W -n -q {toxinidir}/docs {toxinidir}/docs/_build/html
pypy,py{27,34,36}: coverage run -a -m sphinx -b html -d {toxinidir}/docs/_build/toctree -E -W -n -j 4 -q {toxinidir}/docs {toxinidir}/docs/_build/html
coverage report --include "*m2r.py,*m2r/tests*"
make -C {toxinidir} clean

Expand Down

0 comments on commit 9e0e563

Please sign in to comment.