pax_global_header00006660000000000000000000000064143353653550014526gustar00rootroot0000000000000052 comment=b49e3363eaa0a2ea9d2c26a53c30cd06969c7833 m2r-0.3.1/000077500000000000000000000000001433536535500122275ustar00rootroot00000000000000m2r-0.3.1/.coveragerc000066400000000000000000000000451433536535500143470ustar00rootroot00000000000000[run] include=m2r.py,tests/test_*.py m2r-0.3.1/.gitignore000066400000000000000000000020531433536535500142170ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # Virtualenv bin/ lib/ lib64 pyvenv.cfg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache .mypy_cache nosetests.xml coverage.xml *,cover .hypothesis/ # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/ # pyenv python configuration file .python-version ###### direnv ###### .direnv .envrc ###### zsh-autoenv ###### .autoenv.zsh .autoenv_leave.zsh ### project specific ignore files wiki tmp .bumpversion.cfg pytest.xml chromedriver # node files node_modules # phantomjs ghostdriver.log m2r-0.3.1/.travis.yml000066400000000000000000000007531433536535500143450ustar00rootroot00000000000000language: python dist: xenial matrix: include: - python: 3.7 env: TOXENV=py,flake8,sphinx-dev,codecov - python: 3.8 env: TOXENV=py,flake8,sphinx-dev,codecov - python: 3.9 env: TOXENV=py,flake8,sphinx-dev,codecov - python: 3.10 env: TOXENV=py,flake8,sphinx-dev,codecov - python: pypy env: TOXENV=py,flake8,sphinx-dev,codecov - python: pypy3 env: TOXENV=py,flake8,sphinx-dev,codecov install: - pip install tox script: - tox m2r-0.3.1/CHANGES.md000066400000000000000000000040531433536535500136230ustar00rootroot00000000000000## Version 0.3.0 * Drop support for Python 2.7, 3.4, 3.5, and 3.6 * Add compatibility with docutils 0.19 * Sync up assertion with changes in argparse * Limit mistune dependency version range ### Version 0.2.1 (2018-10-12) * Add `--disable-inline-math` and `m2r_disable_inline_math` sphinx option ## Version 0.2.0 (2018-08-13) * 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) * Support Sphinx's doc/ref directives for relative links ([#16](https://github.com/miyakogi/m2r/pull/16)) ### Version 0.1.14 (2018-03-22) * Implement markdown link with title ### Version 0.1.13 (2018-02-14) * Catch up sphinx updates ### Version 0.1.12 (2017-09-11) * Support multi byte characters for heading ### Version 0.1.11 (2017-08-30) * Add metadata for sphinx * Add `convert(src)` function, which is shortcut of `m2r.M2R()(src)` ### Version 0.1.10 (2017-08-15) * Include CHANGES and test files in source distribution ### Version 0.1.9 (2017-08-12) * Print help when input_file is not specified on command-line ### Version 0.1.8 (2017-08-11) * Update metadata on setup.py ### Version 0.1.7 (2017-07-20) * Fix undefined name error (PR #5). ### Version 0.1.6 (2017-05-31) * Drop python 3.3 support * Improve image_link regex (PR #3) ### Version 0.1.5 (2016-06-21) * Support multiple backticks in inline code, like: ```backticks (``) in code``` ### Version 0.1.4 (2016-06-08) * Support indented directives/reST-comments * Support role-name after backticks (`` `text`:role: style``) ### Version 0.1.3 (2016-06-02) * Remove extra escaped-spaces ('\ ') * before and after normal spaces * at the beginning of lines * before dots ### Version 0.1.2 (2016-06-01) * Add reST's `::` marker support * Add options to disable emphasis by underscore (`_` or `__`) ### Version 0.1.1 (2016-05-30) * Fix Bug: when code or link is placed at the end of line, spaces to the next word is disappeared ## Version 0.1 (2016-05-30) First public release. m2r-0.3.1/LICENSE000066400000000000000000000020721433536535500132350ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2016 Hitoruki Takagi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. m2r-0.3.1/MANIFEST.in000066400000000000000000000002411433536535500137620ustar00rootroot00000000000000include README.md include LICENSE include CHANGES.md recursive-include tests *.py test.md test.rst recursive-exclude * __pycache__ recursive-exclude * *.py[co] m2r-0.3.1/Makefile000066400000000000000000000045161433536535500136750ustar00rootroot00000000000000.PHONY: release release-pypi release-github clean clean-test clean-pyc clean-build help .DEFAULT_GOAL := help define BROWSER_PYSCRIPT import os, webbrowser, sys try: from urllib import pathname2url except: from urllib.request import pathname2url webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) endef export BROWSER_PYSCRIPT define PRINT_HELP_PYSCRIPT import re, sys for line in sys.stdin: match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) if match: target, help = match.groups() print("%-20s %s" % (target, help)) endef export PRINT_HELP_PYSCRIPT BROWSER := python -c "$$BROWSER_PYSCRIPT" help: @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) clean: clean-build clean-pyc clean-testdoc ## remove all build, test, coverage and Python artifacts clean-build: ## remove build artifacts @echo "Remove build files (build/, dist/, .egg*, ...)." @rm -fr build/ @rm -fr dist/ @rm -fr .eggs/ @find . -name '*.egg-info' -exec rm -fr {} + @find . -name '*.egg' -exec rm -fr {} + clean-pyc: ## remove Python file artifacts @echo "Remove python files (*.py[co], __pycache__, ...)." @find . -name '*.pyc' -exec rm -f {} + @find . -name '*.pyo' -exec rm -f {} + @find . -name '*~' -exec rm -f {} + @find . -name '__pycache__' -exec rm -fr {} + clean-testdoc: ## remove test and coverage artifacts @echo "Remove testdoc output files (testdo/_build/html)." @rm -rf testdoc/_build/html release: release-pypi release-github ## register PyPI and send tags to github release-pypi: ## register PyPI python setup.py sdist upload release-github: ## send tags to github git push origin --tags .PHONY: green green-cov green-single green: ## run green test @echo "Run green." @green tests green-single: ## run green with a single process @echo "Run green with a single process." @green -s 1 tests green-cov: # run green and calculate coverage @echo "Run green with coverage." @green -r -c tests .PHONY: flake8 flake8: ## run flake8 syntax check flake8 setup.py m2r.py tests .PHONY: docs docs: ## build document @sphinx-build -E -W -n -j auto -b html docs docs/_build/html .PHONY: sphinx sphinx: ## run document build server @echo "### Sphinx Build Server Start ###" @python docs/server.py .PHONY: check check: ## run flake8 and sphinx-build @doit .PHONY: test test: check green-cov ## run style check and test m2r-0.3.1/README.md000066400000000000000000000121561433536535500135130ustar00rootroot00000000000000# NO MORE UPDATES Feel free to fork and update. --- Old README M2R === [![PyPI](https://img.shields.io/pypi/v/m2r.svg)](https://pypi.python.org/pypi/m2r) [![PyPI version](https://img.shields.io/pypi/pyversions/m2r.svg)](https://pypi.python.org/pypi/m2r) [![Documentation](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://miyakogi.github.io/m2r) [![Build Status](https://travis-ci.org/miyakogi/m2r.svg?branch=master)](https://travis-ci.org/miyakogi/m2r) [![codecov](https://codecov.io/gh/miyakogi/m2r/branch/master/graph/badge.svg)](https://codecov.io/gh/miyakogi/m2r) -------------------------------------------------------------------------------- M2R converts a markdown file including reStructuredText (rst) markups to a valid rst format. ## Why another converter? I wanted to write sphinx document in markdown, since it's widely used now and easy to write code blocks and lists. However, converters using pandoc or recommonmark do not support many rst markups and sphinx extensions. For example, rst's reference link like ``see `ref`_`` (this is very convenient in long document in which same link appears multiple times) will be converted to a code block in HTML like `see ref_`, which is not expected. ## Features * Basic markdown and some extensions (see below) * inline/block-level raw html * fenced-code block * tables * footnotes (``[^1]``) * Inline- and Block-level rst markups * single- and multi-line directives (`.. directive::`) * inline-roles (``:code:`print(1)` ...``) * ref-link (``see `ref`_``) * footnotes (``[#fn]_``) * math extension inspired by [recommonmark](https://recommonmark.readthedocs.io/en/latest/index.html) * Sphinx extension * add markdown support for sphinx * ``mdinclude`` directive to include markdown from md or rst files * option to parse relative links into ref and doc directives (``m2r_parse_relative_links``) * Pure python implementation * pandoc is not required ## Installation Python 3.7+ is required. ``` pip install m2r ``` Or, ``` python3 -m pip install m2r ``` ## Usage ### Command Line `m2r` command converts markdown file to rst format. ``` m2r your_document.md [your_document2.md ...] ``` Then you will find `your_document.rst` in the same directory. ### Programmatic Use Import `m2r.convert` function and call it with markdown text. Then it will return converted text. ```python from m2r import convert rst = convert('# Title\n\nSentence.') print(rst) # Title # ===== # # Sentence. ``` Or, use `parse_from_file` function to load markdown file and obtain converted text. ```python from m2r import parse_from_file output = parse_from_file('markdown_file.md') ``` This is an example of setup.py to write README in markdown, and publish it to PyPI as rst format. ```python readme_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'README.md') try: from m2r import parse_from_file readme = parse_from_file(readme_file) except ImportError: # m2r may not be installed in user environment with open(readme_file) as f: readme = f.read() setup( ..., long_description=readme, ..., ) ``` ### Sphinx Integration In your conf.py, add the following lines. ```python extensions = [ ..., 'm2r', ] # source_suffix = '.rst' source_suffix = ['.rst', '.md'] ``` Write index.md and run `make html`. When `m2r` extension is enabled on sphinx and `.md` file is loaded, m2r converts to rst and pass to sphinx, not making new `.rst` file. #### mdinclude directive Like `.. include:: file` directive, `.. mdinclude:: file` directive inserts markdown file at the line. Note: do not use `.. include:: file` directive to include markdown file even if in the markdown file, please use `.. mdinclude:: file` instead. ## Restrictions * In the rst's directives, markdown is not available. Please write in rst. * Column alignment of tables is not supported. (rst does not support this feature) * Heading with overline-and-underline is not supported. * Heading with underline is OK * Rst heading marks are currently hard-coded and unchangeable. * H1: `=`, H2: `-`, H3: `^`, H4: `~`, H5: `"`, H6: `#` If you find any bug or unexpected behaviour, please report it to [Issues](https://github.com/miyakogi/m2r/issues). ## Example See [example document](https://miyakogi.github.io/m2r/example.html) and [its source code](https://github.com/miyakogi/m2r/blob/master/docs/example.md). I'm using m2r for writing user guide of [WDOM](https://github.com/miyakogi/wdom). So you can see it as another example. Its [HTML is here](http://wdom-py.readthedocs.io/en/latest/guide/index.html), and [its source code is here](https://github.com/miyakogi/wdom/tree/dev/docs/guide). ### Demo editor Demo editor of m2r is available. If you are interested in m2r, please try it. [https://github.com/miyakogi/m2rdemo](https://github.com/miyakogi/m2rdemo) ## Acknowledgement m2r is written as an extension of [mistune](http://mistune.readthedocs.io/en/latest/), which is highly extensible pure-python markdown parser. Without the mistune, I couldn't write this. Thank you! ## Licence [MIT](https://github.com/miyakogi/m2r/blob/master/LICENSE) m2r-0.3.1/docs/000077500000000000000000000000001433536535500131575ustar00rootroot00000000000000m2r-0.3.1/docs/Makefile000066400000000000000000000175641433536535500146340ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don\'t have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " applehelp to make an Apple Help Book" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " epub3 to make an epub3" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" @echo " coverage to run coverage check of the documentation (if enabled)" @echo " dummy to check syntax errors of document sources" .PHONY: clean clean: rm -rf $(BUILDDIR)/* .PHONY: html html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." .PHONY: dirhtml dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." .PHONY: singlehtml singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." .PHONY: pickle pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." .PHONY: json json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." .PHONY: htmlhelp htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." .PHONY: qthelp qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/M2R.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/M2R.qhc" .PHONY: applehelp applehelp: $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp @echo @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." @echo "N.B. You won't be able to view it unless you put it in" \ "~/Library/Documentation/Help or install it in your application" \ "bundle." .PHONY: devhelp devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/M2R" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/M2R" @echo "# devhelp" .PHONY: epub epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." .PHONY: epub3 epub3: $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 @echo @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." .PHONY: latex latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." .PHONY: latexpdf latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." .PHONY: latexpdfja latexpdfja: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." .PHONY: text text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." .PHONY: man man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." .PHONY: texinfo texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." .PHONY: info info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." .PHONY: gettext gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." .PHONY: changes changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." .PHONY: linkcheck linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." .PHONY: doctest doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." .PHONY: coverage coverage: $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage @echo "Testing of coverage in the sources finished, look at the " \ "results in $(BUILDDIR)/coverage/python.txt." .PHONY: xml xml: $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." .PHONY: pseudoxml pseudoxml: $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." .PHONY: dummy dummy: $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy @echo @echo "Build finished. Dummy builder generates no files." m2r-0.3.1/docs/_static/000077500000000000000000000000001433536535500146055ustar00rootroot00000000000000m2r-0.3.1/docs/_static/custom.css000066400000000000000000000003221433536535500166260ustar00rootroot00000000000000div.sphinxsidebarwrapper p.blurb { font-family: Lato, sans-serif; } h1.logo { font-family: Lato, sans-serif; font-weight: normal; } div.sphinxsidebar li.toctree-l1 { font-family: Lato, sans-serif; } m2r-0.3.1/docs/_templates/000077500000000000000000000000001433536535500153145ustar00rootroot00000000000000m2r-0.3.1/docs/_templates/layout.html000066400000000000000000000007511433536535500175220ustar00rootroot00000000000000{% extends 'alabaster/layout.html' %} {% block extrahead %} {{ super() }} {% endblock %} m2r-0.3.1/docs/changes.md000066400000000000000000000000641433536535500151110ustar00rootroot00000000000000Change Log ========== .. mdinclude:: ../CHANGES.md m2r-0.3.1/docs/conf.py000066400000000000000000000241511433536535500144610ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # M2R documentation build configuration file, created by # sphinx-quickstart on Sat May 28 09:30:21 2016. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.mathjax', 'sphinx.ext.viewcode', 'sphinx.ext.githubpages', 'm2r', ] suppress_warnings = ['image.nonlocal_uri'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # source_suffix = ['.rst', '.md'] source_suffix = '.md' no_underscore_emphasis = True m2r_parse_relative_links = True m2r_anonymous_references = False m2r_disable_inline_math = False # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = 'M2R' copyright = '2016, Hiroyuki Takagi' author = 'Hiroyuki Takagi' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '0.3.1' # The full version, including alpha/beta/rc tags. release = '0.3.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'alabaster' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. html_theme_options = { 'description': 'Markdown mixed to reST', 'github_user': 'miyakogi', 'github_repo': 'm2r', 'github_banner': True, 'github_type': 'mark', 'github_count': False, 'font_family': '"Charis SIL", "Noto Serif", serif', 'head_font_family': 'Lato, sans-serif', 'code_font_family': '"Code new roman", "Ubuntu Mono", monospace', 'code_font_size': '1rem', } # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. # " v documentation" by default. #html_title = 'M2R v0.3.1' # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. #html_extra_path = [] # If not None, a 'Last updated on:' timestamp is inserted at every page # bottom, using the given strftime format. # The empty string is equivalent to '%b %d, %Y'. #html_last_updated_fmt = None # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. html_sidebars = { '**': [ 'about.html', 'navigation.html', 'relations.html', 'searchbox.html', ] } # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Language to be used for generating the HTML full-text search index. # Sphinx supports the following languages: # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh' #html_search_language = 'en' # A dictionary with options for the search language support, empty by default. # 'ja' uses this config value. # 'zh' user can custom change `jieba` dictionary path. #html_search_options = {'type': 'default'} # The name of a javascript file (relative to the configuration directory) that # implements a search results scorer. If empty, the default will be used. #html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. htmlhelp_basename = 'M2Rdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', # Latex figure (float) alignment #'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'M2R.tex', 'M2R Documentation', 'Hiroyuki Takagi', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'm2r', 'M2R Documentation', [author], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'M2R', 'M2R Documentation', author, 'M2R', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'https://docs.python.org/': None} m2r-0.3.1/docs/example.md000066400000000000000000000061421433536535500151370ustar00rootroot00000000000000# Example This page is written in mixed markdown and reST. Source code is [here](https://github.com/miyakogi/m2r/blob/master/docs/example.md). ## Basic Markups (inline) A **strong**, *emphasis*, ~~deleted~~, `code with single-backtick`, ``code with two-backticks``, ```code can include multiple (``) backticks```, :code:`reST's code role`, and inline htmldelete. ### Link Auto link to http://example.com/. Link to [example.com](http://example.com/) in markdown. Link to [anchor](#testlabel) in markdown. Link to [document](example.md) in markdown. Link to [document with anchor](example.md#testlabel) in markdown (doc directive does not support anchors, so this links to the document only). Link to `example.com `_ in reST. Link to `example`_ in reST_ref. Link to [example.com](http://example.com/ "example") with title in markdown. .. _example: http://example.com .. _testlabel: ## Basic Markups (block) This is a simple sentence. | sentence with | newlines | (reST) Sentence with hard-wrap (markdown, trailing two spaces) > block quote > second line > > nested quote ---
This is a red, raw-html block.
> Block quote after raw-html directive ### List #### Unordered list * unordered list new line * next item * nested list with new line * nested list item 2 * original depth 1. ordered list item 2. second with new line * original depth again #### Ordered list 1. ordered list in new line 2. second item * nested unordered list * second item with new line 3. original depth 1. nested ordered list with new line 2. again 4. original depth again ### Code Block Simple, indented code block pip install sphinx Code block with triple backticks and language. ```python def a(n: int) -> None: for i in range(n): print(i) ``` Triple-tildes (`~~~`) are also available. ~~~ def a(n: int) -> None: for i in range(n): print(i) ~~~ Here is reST style code block. .. code-block:: python if True: print('\n') ## Extensions ### Table (Markdown-Style) (cell-alignment is not supported currently) | Table Header 1 | Table Header 2 | Table Header 3 | |----------------|----------------|----------------| | normal | *italic* | **bold** | | `code` | ~~deleted~~ | inline-html | ### Math This is `$E = mc^2$` inline math. The below is math-block (markdown-style). ```math E = mc^2 ``` The below is reST-style math-block. .. math:: E = mc^2 ### Include Markdown file To include markdown file: ```rest .. mdinclude:: path-to-file.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 #### Include 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. Footnote with reST\ [#a]_. [^1]: footnote 1 [^key]: footnote key .. [#a] reST footnote m2r-0.3.1/docs/included.md000066400000000000000000000000631433536535500152670ustar00rootroot00000000000000NOT-INCLUDED #### Include this line NOT-INCLUDED m2r-0.3.1/docs/index.md000066400000000000000000000003031433536535500146040ustar00rootroot00000000000000.. mdinclude:: ../README.md Contents -------- .. toctree:: :maxdepth: 1 example changes Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` m2r-0.3.1/docs/server.py000077500000000000000000000016611433536535500150460ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- from os import path import subprocess from livereload import Server docsdir = path.dirname(path.abspath(__file__)) builddir = path.join(docsdir, '_build') build_cmd = [ 'sphinx-build', '-b', 'html', '-E', '-q', '-d', path.join(builddir, 'doctrees'), docsdir, path.join(builddir, 'html'), ] def cmd() -> None: print('=== Sphinx Build Start ===') subprocess.run(build_cmd, cwd=docsdir) print('=== Sphinx Build done ===') def docs(p: str) -> str: return path.join(docsdir, p) # subprocess.run(['make', 'clean'], cwd=docsdir) cmd() # build once server = Server() server.watch(docs('*.py'), cmd) server.watch(docs('../*.py'), cmd) server.watch(docs('*.md'), cmd) server.watch(docs('../*.md'), cmd) server.watch(docs('_static/*.css'), cmd) server.watch(docs('_templates/*.html'), cmd) server.serve(port=8889, root=docs('_build/html'), debug=True, restart_delay=1) m2r-0.3.1/dodo.py000066400000000000000000000007001433536535500135230ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Doit task definitions.""" DOIT_CONFIG = { 'default_tasks': [ 'flake8', 'docs', ], 'continue': True, 'verbosity': 1, 'num_process': 2, 'par_type': 'thread', } def task_flake8(): return { 'actions': ['flake8 m2r tests'], } def task_docs(): return { 'actions': ['sphinx-build -q -W -E -n -b html docs docs/_build/html'], } m2r-0.3.1/m2r.py000066400000000000000000000556011433536535500133100ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- from __future__ import print_function, unicode_literals import os import os.path import re from argparse import ArgumentParser, Namespace from docutils import statemachine, nodes, io, utils from docutils.parsers import rst from docutils.utils import column_width import mistune from urllib.parse import urlparse __version__ = '0.3.1' _is_sphinx = False prolog = '''\ .. role:: raw-html-m2r(raw) :format: html ''' # for command-line use parser = ArgumentParser() options = Namespace() parser.add_argument('input_file', nargs='*', help='files to convert to reST format') parser.add_argument('--overwrite', action='store_true', default=False, help='overwrite output file without confirmaion') parser.add_argument('--dry-run', action='store_true', default=False, help='print conversion result and not save output file') parser.add_argument('--no-underscore-emphasis', action='store_true', default=False, help='do not use underscore (_) for emphasis') parser.add_argument('--parse-relative-links', action='store_true', default=False, help='parse relative links into ref or doc directives') parser.add_argument('--anonymous-references', action='store_true', default=False, help='use anonymous references in generated rst') parser.add_argument('--disable-inline-math', action='store_true', default=False, help='disable parsing inline math') def parse_options(): parser.parse_known_args(namespace=options) class RestBlockGrammar(mistune.BlockGrammar): directive = re.compile( r'^( *\.\..*?)\n(?=\S)', re.DOTALL | re.MULTILINE, ) oneline_directive = re.compile( r'^( *\.\..*?)$', re.DOTALL | re.MULTILINE, ) rest_code_block = re.compile( r'^::\s*$', re.DOTALL | re.MULTILINE, ) class RestBlockLexer(mistune.BlockLexer): grammar_class = RestBlockGrammar default_rules = [ 'directive', 'oneline_directive', 'rest_code_block', ] + mistune.BlockLexer.default_rules def parse_directive(self, m): self.tokens.append({ 'type': 'directive', 'text': m.group(1), }) def parse_oneline_directive(self, m): # reuse directive output self.tokens.append({ 'type': 'directive', 'text': m.group(1), }) def parse_rest_code_block(self, m): self.tokens.append({ 'type': 'rest_code_block', }) class RestInlineGrammar(mistune.InlineGrammar): image_link = re.compile( r'\[!\[(?P.*?)\]\((?P.*?)\).*?\]\((?P.*?)\)' ) rest_role = re.compile(r':.*?:`.*?`|`[^`]+`:.*?:') rest_link = re.compile(r'`[^`]*?`_') inline_math = re.compile(r'`\$(.*)?\$`') eol_literal_marker = re.compile(r'(\s+)?::\s*$') # add colon and space as special text text = re.compile(r'^[\s\S]+?(?=[\\[\s\S]+?)\1{2}(?!\1)' ) # _word_ or *word* emphasis = re.compile( r'^\b_((?:__|[^_])+?)_\b' # _word_ r'|' r'^\*(?P(?:\*\*|[^\*])+?)\*(?!\*)' # *word* ) def no_underscore_emphasis(self): self.double_emphasis = re.compile( r'^\*{2}(?P[\s\S]+?)\*{2}(?!\*)' # **word** ) self.emphasis = re.compile( r'^\*(?P(?:\*\*|[^\*])+?)\*(?!\*)' # *word* ) class RestInlineLexer(mistune.InlineLexer): grammar_class = RestInlineGrammar default_rules = [ 'image_link', 'rest_role', 'rest_link', 'eol_literal_marker', ] + mistune.InlineLexer.default_rules def __init__(self, *args, **kwargs): no_underscore_emphasis = kwargs.pop('no_underscore_emphasis', False) disable_inline_math = kwargs.pop('disable_inline_math', False) super(RestInlineLexer, self).__init__(*args, **kwargs) if not _is_sphinx: parse_options() if no_underscore_emphasis or getattr(options, 'no_underscore_emphasis', False): self.rules.no_underscore_emphasis() inline_maths = 'inline_math' in self.default_rules if disable_inline_math or getattr(options, 'disable_inline_math', False): if inline_maths: self.default_rules.remove('inline_math') elif not inline_maths: self.default_rules.insert(0, 'inline_math') def output_double_emphasis(self, m): # may include code span text = self.output(m.group('text')) return self.renderer.double_emphasis(text) def output_emphasis(self, m): # may include code span text = self.output(m.group('text') or m.group(1)) return self.renderer.emphasis(text) def output_image_link(self, m): """Pass through rest role.""" return self.renderer.image_link( m.group('url'), m.group('target'), m.group('alt')) def output_rest_role(self, m): """Pass through rest role.""" return self.renderer.rest_role(m.group(0)) def output_rest_link(self, m): """Pass through rest link.""" return self.renderer.rest_link(m.group(0)) def output_inline_math(self, m): """Pass through rest link.""" return self.renderer.inline_math(m.group(1)) def output_eol_literal_marker(self, m): """Pass through rest link.""" marker = ':' if m.group(1) is None else '' return self.renderer.eol_literal_marker(marker) class RestRenderer(mistune.Renderer): _include_raw_html = False list_indent_re = re.compile(r'^(\s*(#\.|\*)\s)') indent = ' ' * 3 list_marker = '{#__rest_list_mark__#}' hmarks = { 1: '=', 2: '-', 3: '^', 4: '~', 5: '"', 6: '#', } def __init__(self, *args, **kwargs): self.parse_relative_links = kwargs.pop('parse_relative_links', False) self.anonymous_references = kwargs.pop('anonymous_references', False) super(RestRenderer, self).__init__(*args, **kwargs) if not _is_sphinx: parse_options() if getattr(options, 'parse_relative_links', False): self.parse_relative_links = options.parse_relative_links if getattr(options, 'anonymous_references', False): self.anonymous_references = options.anonymous_references def _indent_block(self, block): return '\n'.join(self.indent + line if line else '' for line in block.splitlines()) def _raw_html(self, html): self._include_raw_html = True return r'\ :raw-html-m2r:`{}`\ '.format(html) def block_code(self, code, lang=None): if lang == 'math': first_line = '\n.. math::\n\n' elif lang: first_line = '\n.. code-block:: {}\n\n'.format(lang) elif _is_sphinx: first_line = '\n::\n\n' else: first_line = '\n.. code-block::\n\n' return first_line + self._indent_block(code) + '\n' def block_quote(self, text): # text includes some empty line return '\n..\n\n{}\n\n'.format(self._indent_block(text.strip('\n'))) def block_html(self, html): """Rendering block level pure html content. :param html: text content of the html snippet. """ return '\n\n.. raw:: html\n\n' + self._indent_block(html) + '\n\n' def header(self, text, level, raw=None): """Rendering header/heading tags like ``

`` ``

``. :param text: rendered text content for the header. :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] * column_width(text)) def hrule(self): """Rendering method for ``
`` tag.""" return '\n----\n' def list(self, body, ordered=True): """Rendering list tags like ``