-
Notifications
You must be signed in to change notification settings - Fork 252
Remove URL quoting from refs before passing to Sphinx #158
Conversation
Sphinx allows refs with spaces etc, and in fact autogenerates them with the command [`autosectionlabel`][]. So if you put a: ```markdown [Link 1](<some ref>) [Link 2](<https://foo.com/bar baz>) ``` Then the links will be `some%20ref` and `https://foo.com/bar%20baz`. We want to keep the URL quoting for external references, but if we're passing it as `:any:` to Sphinx we need to unquote so Sphinx can find the correct reference, the `<some ref>` should map to: ```rst :ref:`some ref` ``` [`autosectionlabel`](https://www.sphinx-doc.org/en/master/usage/extensions/autosectionlabel.html) Fixes: readthedocs#155
b26815c
to
ec0ada9
Compare
@@ -152,7 +152,7 @@ def visit_link(self, mdnode): | |||
url_check = urlparse(destination) | |||
if not url_check.scheme and not url_check.fragment: | |||
wrap_node = addnodes.pending_xref( | |||
reftarget=destination, | |||
reftarget=unquote(destination), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only actual change.
@ericholscher sorry for the direct ping, but would you mind taking a look at this? I think it should be uncontroversial. I've been using it (via a Full patch code in case anyone else needs to do the same: Patch script: # Generate patch with:
cp .venv/lib/python3.*/site-packages/recommonmark/parser.py parser.py
# Edit ./parser.py to apply the change here
# Generate patch
diff -u .venv/lib/python3.*/site-packages/recommonmark/parser.py parser.py > parser.py.patch
# Commit ./parser.py.patch, delete ./parser.py
# Apply patch as part of your Makefile/setup.py:
patch --forward \
.venv/lib/python3.*/site-packages/recommonmark/parser.py \
< parser.py.patch \
|| true Generated patch: --- .venv/lib/python3.7/site-packages/recommonmark/parser.py 2019-05-16 11:29:29.045060000 +0200
+++ parser.py 2019-05-23 16:21:31.172900496 +0200
@@ -11,9 +11,9 @@
from warnings import warn
if sys.version_info < (3, 0):
- from urlparse import urlparse
+ from urlparse import urlparse, unquote
else:
- from urllib.parse import urlparse
+ from urllib.parse import urlparse, unquote
__all__ = ['CommonMarkParser']
@@ -152,7 +152,7 @@
url_check = urlparse(destination)
if not url_check.scheme and not url_check.fragment:
wrap_node = addnodes.pending_xref(
- reftarget=destination,
+ reftarget=unquote(destination),
reftype='any',
refdomain=None, # Added to enable cross-linking
refexplicit=True,
|
Looks good, no worries on the direct ping 👍 |
I will try and get a release out here soon. |
Thank you! |
@ericholscher any chance of a release? If there's anything I could do to help with said release let me know. |
I just shipped 0.6.0 👍 |
Sphinx allows refs with spaces etc, and in fact autogenerates them with
the command
autosectionlabel
.So if you put a:
Then the links will be
some%20ref
andhttps://foo.com/bar%20baz
.We want to keep the URL quoting for external references, but if we're
passing it as
:any:
to Sphinx we need to unquote so Sphinx can findthe correct reference, the
<some ref>
should map to:Fixes: #155