readthedocs / recommonmark

A markdown parser for docutils
https://recommonmark.readthedocs.io/
MIT License
340 stars 252 forks source link

`url_resolver` not working for github code links #137

Closed leckie-chn closed 2 years ago

leckie-chn commented 5 years ago

Hi, I am using the https://recommonmark.readthedocs.io/en/latest/auto_structify.html#url-resolver feature for referencing source code for our repos.

I appended the following code at the end of conf.py:

github_doc_root = 'https://github.com/Microsoft/nni/tree/master/doc/'
def setup(app):
    app.add_config_value('recommonmark_config', {
        'url_resolver': lambda url: github_doc_root + url if url.startswith('..') else url,
        'enable_auto_toc_tree': False,
    }, True)
    app.add_transform(AutoStructify)

But sphinx still cannot transform source code url properly, and give warnings like:

/mnt/c/Users/yann/Desktop/code/nni/docs/KubeflowMode.md:181: WARNING: None:any reference target not found: ../deployment/Dockerfile.build.base
/mnt/c/Users/yann/Desktop/code/nni/docs/PAIMode.md:53: WARNING: None:any reference target not found: ../deployment/Dockerfile.build.base
/mnt/c/Users/yann/Desktop/code/nni/docs/QuickStart.md:43: WARNING: None:any reference target not found: ../examples/trials/mnist/mnist_before.py
/mnt/c/Users/yann/Desktop/code/nni/docs/QuickStart.md:80: WARNING: None:any reference target not found: ../examples/trials/mnist/search_space.json
/mnt/c/Users/yann/Desktop/code/nni/docs/QuickStart.md:105: WARNING: None:any reference target not found: ../examples/trials/mnist/mnist.py
/mnt/c/Users/yann/Desktop/code/nni/docs/QuickStart.md:128: WARNING: None:any reference target not found: ../examples/trials/mnist/config.yml
/mnt/c/Users/yann/Desktop/code/nni/docs/QuickStart.md:130: WARNING: None:any reference target not found: ../examples/trials/mnist

BTW, the example given in https://recommonmark.readthedocs.io/en/latest/auto_structify.html#url-resolver also failed, which renders an invalid url: https://recommonmark.readthedocs.io/en/recommonmark/parser.py

pawamoy commented 5 years ago

Not sure if this is related, but it seems URL resolution does not work as expected for me either, see this comment.

If I use url_resolver like described in the docs/README, my markdown files are not parsed and transformed to rst, and sphinx/recommonmark tries to resolve them to GitHub URLs instead.

ppwwyyxx commented 4 years ago

Also found that "url_resolver" is just broken since 0.5.0. It is removed in this commit: https://github.com/readthedocs/recommonmark/commit/8baf238562c2f7c9bea603e352c3a94f51905a3e

ppwwyyxx commented 4 years ago

url_resolver was deprecated by recommonmark but I found an alternative way to implement it using Sphinx (https://github.com/tensorpack/tensorpack/blob/94600659794542e456bfdb9f90f944518a7b860e/docs/conf.py#L18-L44)