Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx and Markdown .md links

I'm trying to convert Markdown files to html using Sphinx but am having trouble getting [links](another.md) to be translated to <a href="another.html">links</a>, rather the extension of the target remains the original .md and appears as <a href="another.md">links</a>.

I've created a simple example...

test.md

[Test link](https://www.stackoverflow.com)

[Another Markdown doc](another.md)

another.md

# Another test markdown

Both files reside in the top level directory and I run sphinx-quickstart to create conf.py, accepting the defaults. I then modify conf.py to have...

from recommonmark.parser import CommonMarkParser
extensions = [
    'sphinx.ext.autodoc',
]
source_suffix = ['.rst', '.md']
source_parsers = {
    '.md': CommonMarkParser,
}

The resulting html files are produced but the link from test.html to another.html is not correct and appears as...

test.html

...
<p><a class="reference external" href="https://thefloow.com">Test link</a></p>
<p><a class="reference external" href="another.md">A real test</a></p>
...

...and points to another.md rather than another.html. I asked a few days ago and was pointed towards using recommonmark's AutoStructify (see thread here) but that didn't work and on further digging/reading it turns out that enable_auto_doc_ref is now deprecated and .md links are added as :any: and should be handled by Sphinx.

But I don't understand why this isn't working or what I should do to resolve it. Any suggestions would be very much appreciated.

EDIT

Versions are as follows

  • Sphinx 1.8.0
  • recommonmark 0.4.0
like image 448
slackline Avatar asked Sep 25 '18 10:09

slackline


People also ask

Can you use Markdown with Sphinx?

Markdown and reStructuredText can be used in the same Sphinx project. Markdown doesn't support a lot of the features of Sphinx, like inline markup and directives. However, it works for basic prose content.

Can HTML read Markdown?

A Markdown file on its own is just code. In fact, it's called a markup language. To view the document the way the Markdown formatting intended, it has to be in HTML.


1 Answers

recommonmark==0.5.0.dev0 solves this problem.

conf.py configuration

extensions = [
    # other
    'recommonmark',
]

source_suffix = ['.rst', '.md']

pip configuration (requirements.txt)

sphinx==1.8.2
# recommonmark==0.5.0.dev0
git+https://github.com/rtfd/recommonmark

Please refer to https://www.sphinx-doc.org/en/master/usage/markdown.html if you need more details.

like image 94
Dmytro Serdiuk Avatar answered Nov 27 '22 05:11

Dmytro Serdiuk