markdown_to_rst

pyhelpers.store.markdown_to_rst(path_to_md, path_to_rst, reverse=False, engine=None, pandoc_exe=None, verbose=False, **kwargs)[source]

Convert a Markdown (.md) file to a reStructuredText (.rst) file.

This function relies on Pandoc or pypandoc, given the specified engine.

Parameters:
  • path_to_md (str | os.PathLike) – The path where the Markdown file is saved.

  • path_to_rst (str | os.PathLike) – The path where the reStructuredText file will be saved.

  • reverse (bool) – Specifies whether to convert an .rst file to a .md file; defaults to False.

  • engine (None | str) –

    The engine/module used for performing the conversion; if engine=None (default), the function utilises Pandoc, 'pypandoc' otherwise.

  • pandoc_exe (str | None) – The path to the executable “pandoc.exe”; If pandoc_exe=None (default), the default installation path will be used, e.g. “C:\Program Files\Pandoc\pandoc.exe” (on Windows).

  • verbose (bool | int) – Whether to print relevant information to the console; defaults to False.

  • kwargs – [Optional] Additional parameters for the function subprocess.run() (if engine=None) or pypandoc.convert_file() (if engine='pypandoc').

Examples:

>>> from pyhelpers.store import markdown_to_rst
>>> from pyhelpers.dirs import cd
>>> dat_dir = cd("tests\documents")
>>> path_to_md_file = cd(dat_dir, "readme.md")
>>> path_to_rst_file = cd(dat_dir, "readme.rst")
>>> markdown_to_rst(path_to_md_file, path_to_rst_file, verbose=True)
Converting "tests\data\markdown.md" to "tests\data\markdown.rst" ... Done.
>>> markdown_to_rst(path_to_md_file, path_to_rst_file, engine='pypandoc', verbose=True)
Updating "readme.rst" at "tests\documents\" ... Done.