diff options
author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2019-04-15 10:23:34 +0000 |
---|---|---|
committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2019-04-15 10:23:34 +0000 |
commit | 2cfe5d2be20c69bf11f8188a481be4e809f76117 (patch) | |
tree | 8d10e45110fec1138d7e6cc3063d060ee01b1e33 | |
parent | 9b638dcd81e4fc9a9bd09ad17f08710f0f5dfe29 (diff) | |
download | docutils-2cfe5d2be20c69bf11f8188a481be4e809f76117.tar.gz |
Apply feature request 63 (support anchors in rfc role).
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8254 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r-- | docutils/docs/ref/rst/roles.txt | 3 | ||||
-rw-r--r-- | docutils/docutils/parsers/rst/roles.py | 10 | ||||
-rwxr-xr-x | docutils/test/test_parsers/test_rst/test_interpreted.py | 9 |
3 files changed, 20 insertions, 2 deletions
diff --git a/docutils/docs/ref/rst/roles.txt b/docutils/docs/ref/rst/roles.txt index e59605a56..8097fc447 100644 --- a/docutils/docs/ref/rst/roles.txt +++ b/docutils/docs/ref/rst/roles.txt @@ -209,6 +209,9 @@ This is equivalent to:: __ http://www.faqs.org/rfcs/rfc2822.html +You can link to a specific section by saying :rfc:`number#anchor` (new in +Docutils 0.15). + ``:strong:`` ============ diff --git a/docutils/docutils/parsers/rst/roles.py b/docutils/docutils/parsers/rst/roles.py index 35227e6d1..0537e7872 100644 --- a/docutils/docutils/parsers/rst/roles.py +++ b/docutils/docutils/parsers/rst/roles.py @@ -276,7 +276,11 @@ register_canonical_role('pep-reference', pep_reference_role) def rfc_reference_role(role, rawtext, text, lineno, inliner, options={}, content=[]): try: - rfcnum = int(text) + if "#" in text: + rfcnum, section = text.split("#", 1) + else: + rfcnum, section = text, None + rfcnum = int(rfcnum) if rfcnum <= 0: raise ValueError except ValueError: @@ -287,8 +291,10 @@ def rfc_reference_role(role, rawtext, text, lineno, inliner, return [prb], [msg] # Base URL mainly used by inliner.rfc_reference, so this is correct: ref = inliner.document.settings.rfc_base_url + inliner.rfc_url % rfcnum + if section is not None: + ref += "#"+section set_classes(options) - node = nodes.reference(rawtext, 'RFC ' + utils.unescape(text), refuri=ref, + node = nodes.reference(rawtext, 'RFC ' + utils.unescape(str(rfcnum)), refuri=ref, **options) return [node], [] diff --git a/docutils/test/test_parsers/test_rst/test_interpreted.py b/docutils/test/test_parsers/test_rst/test_interpreted.py index 87d0a77e0..2a14c0553 100755 --- a/docutils/test/test_parsers/test_rst/test_interpreted.py +++ b/docutils/test/test_parsers/test_rst/test_interpreted.py @@ -334,6 +334,15 @@ totest['references'] = [ <paragraph> RFC number must be a number greater than or equal to 1; "0" is invalid. """], +["""\ +:RFC:`2822#section1` +""", +"""\ +<document source="test data"> + <paragraph> + <reference refuri="http://tools.ietf.org/html/rfc2822.html#section1"> + RFC 2822 +"""], ] totest['unknown_roles'] = [ |