-
Notifications
You must be signed in to change notification settings - Fork 252
Support for ..include to parse Markdown files (README.md in parent dir) #191
Comments
There is a trick on how to use It's a code from m2r.py's |
A relevant sphinx issue for that: sphinx-doc/sphinx#2840 I have a proposed patch linked from that issue, that I used successfully in pygae/galgebra#413. |
Just a little plug 😬 https://myst-parser.readthedocs.io/ would allow you do this, by having all your documentation as markdown, and supports including markdown files into other markdown, as the this test project demonstrates: |
Use m2r for the mdinclude directive and recommonmark for everything else, per readthedocs/recommonmark#191 (comment). To make this work, I had to additionally: * Use HTML for any hyperlinks in bold/italics; * Relative link figures from docs directory, i.e. prepend ../../benchmarks/ecg_preprocessing to image paths; and * Remove line blank lines from references div.
Use m2r for the mdinclude directive and recommonmark for everything else, per readthedocs/recommonmark#191 (comment). To make this work, I had to additionally: * Use HTML for any hyperlinks in bold/italics; * Relative link figures from docs directory, i.e. prepend ../../benchmarks/ecg_preprocessing to image paths; and * Remove line blank lines from references div.
Use m2r for the mdinclude directive and recommonmark for everything else, per readthedocs/recommonmark#191 (comment). To make this work, I had to additionally: * Use HTML for any hyperlinks in bold/italics; * Relative link figures from docs directory, i.e. prepend ../../benchmarks/ecg_preprocessing to image paths; and * Remove line blank lines from references div.
A warning for all the people trying to get a snippet similar to below to work based on @orsinium 's advice. After research I found that all .md documents I noticed this because I put debug statements in trying to understand why recommonmark wasn't converting relative links in README.md's that were
|
Exactly, this is how this snippet is intended to work :)
|
I assumed from your wording that you meant to use m2r for only the ..mdinclude linkage....but process all md's with recommonmark. m2r for mdinclude only (linkage). |
```{include} ../../README.md
:relative-images:
``` Will now re-write local images to the correct path |
interestring that I found in recommonmark, it refers to ../README.md in it's index.md file. However, when I copied this, it doesn't work |
The workaround is described in readthedocs/recommonmark#191 It is not perfect, but it does the job
The approach used by recommonmark's own documentation is to include a symbolic link file inside the `docs` directory, instead of trying to do a `include`. References: readthedocs/recommonmark#191 sphinx-doc/sphinx#701 sphinx-doc/sphinx#7739
The workaround is described in readthedocs/recommonmark#191 It is not perfect, but it does the job
The approach used by recommonmark's own documentation is to include a symbolic link file inside the `docs` directory, instead of trying to do a `include`. References: readthedocs/recommonmark#191 sphinx-doc/sphinx#701 sphinx-doc/sphinx#7739
Docutils 0.17 added an experimental wrapper to integrate "recommonmark" To include a MarkDown (CommonMark) file, you just pass the new "parser" option to the "include" directive:
If there is interest and feedback, we can try to bring this into shape for Docutils 0.18. |
@gmilde recommonmark is already deprecated for myst-parser #221: myst-parser has already added support for the include (executablebooks/MyST-Parser#419) and there are plans to improve standalone docutils (as opposed to sphinx) support: executablebooks/MyST-Parser#426 |
Switching to myst-parser may be too late for 0.18 but an option for 1.0.
This would help users/projects that want to maintain the bulk of the documentation in rST but include a README.md or similar files that are in Markdown format for external reasons. |
Yep you can already do this with myst-parser:
|
Many Python repositories have a structure similar to:
There is no clear instruction on how to including this
README.md
formatted as Markdown as part of Sphinx, while this is a common occurrence. Online certain solutions can be found:.. include:: ../README.md
in areadme_link.rst
file.Problem: Parses the
.md
file as RSTsys.path
inconf.py
like:sys.path.insert(0, os.path.abspath('..'))
Problem: Somehow this doesn't work for me
README.md
Problem: Is not cross-platform (does not work on Windows)
make
time with a function.Problem: Far from ideal, needlessly making files.
.. mdinclude:: ../README.md
; Only option working for me.Problem: Using
extensions = ['m2r', 'recommonmark']
(or reversed list) gives the error:source_suffix '.md' is already registered
in them2r
library... mdinclude
like M2R?.. include::
first check the extension before parsing?README.md
from a parent directory?p.s. Relevant issue in Sphinx's repo: sphinx-doc/sphinx#701
The text was updated successfully, but these errors were encountered: