-1

I am using Sphinx to build a documentation out of Markdown files. The documentation is pretty clear that myst-parser should handle markdown links in the typical [some text](www.example.com) manner.

Subsequently I installed myst-parser, set the extension extensions = ['myst_parser'] and specified the source_suffix:

source_suffix = {
    '.rst': 'restructuredtext',
    '.txt': 'markdown',
    '.md': 'markdown',
}

Unfortunately the links did not get converted correctly and are just displayed written out as the following HTML:

[some text](<a class="reference external" href="www.example.com">www.example.com</a>)

This is then displayed in the following manner [some text](www.example.com) in the browser, which is clearly not the intended link.

I also tried to use Recommonmark in the following manner:

from recommonmark.parser import CommonMarkParser

source_parsers = {
    '.md': CommonMarkParser,
}

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

As explained here and here, but ended up with the same output. How can this rather simple issue be fixed?

Versions being used: recommonmark 0.7.1 myst-parser 0.13.6 sphinx 3.5.4 python 3.9.2

EDIT Find here the updated conf.py file

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------
import sphinx_rtd_theme
import sys
import os

print("CURRENT WORKING DIRECTORY")
print(os.getcwd())
print('adding path')
sys.path.insert(0, r'path_to_repo')
print(sys.path)

# At top on conf.py (with other import statements)
import recommonmark
from recommonmark.transform import AutoStructify
from recommonmark.parser import CommonMarkParser

# -- Project information -----------------------------------------------------
project = 'py_neuromodulation'
copyright = '2021, John Doe'
author = 'John Doe'

source_parsers = {
    '.md': 'recommonmark.parser.CommonMarkParser',
}
source_suffix = ['.rst', '.md']
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.autosummary',
    'sphinx.ext.doctest',
    'sphinx.ext.intersphinx',
    'sphinx.ext.viewcode',
    'numpydoc',
    'sphinx_rtd_theme',
    'sphinx.ext.napoleon',
    'recommonmark'
]

autosummary_generate = True
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']

# At the bottom of conf.py
def setup(app):
    app.add_config_value('recommonmark_config', {
            'url_resolver': lambda url: github_doc_root + url,
            'auto_toc_tree_section': 'Contents',
            }, True)
    app.add_transform(AutoStructify)
Merk
  • 101
  • 7
  • If the answer solved your problem please don't forget to upvote and [accept it by clicking the green check mark](https://i.stack.imgur.com/LkiIZ.png) on the left side of the answer. – bad_coder Apr 20 '21 at 08:54
  • Unfortunately it did not solve the problem, I added the conf.py for more details – Merk Apr 20 '21 at 10:00
  • Notice that recommonmark is deprecated in favor of myst-parser https://github.com/readthedocs/recommonmark/issues/221 – astrojuanlu May 06 '21 at 19:39

1 Answers1

0

By default, you must include a protocol for external links.

However if you want to use bare links without the protocol, then use Linkify:

Adding "linkify" to myst_enable_extensions (in the sphinx conf.py configuration file) will automatically identify “bare” web URLs and add hyperlinks:

www.example.com -> www.example.com

This extension requires that linkify-it-py is installed. Either directly; pip install linkify-it-py or via pip install myst-parser[linkify].

Steve Piercy
  • 10,144
  • 1
  • 31
  • 49
  • This is unfortunately not solving the mentioned problem that markdown links are not supported in the [text](link) manner. I tried to outline above that recommonmark should in theory fix this, but also the AutoStructify [url resolver](https://recommonmark.readthedocs.io/en/latest/auto_structify.html#url-resolver) leads to the same result – Merk Apr 20 '21 at 09:54
  • Your `conf.py` does not show that you have added `linkify`. Did you try it, as described in MyST's documentation? – Steve Piercy Apr 20 '21 at 10:50