openstack-doc-tools/os_doc_tools/sphinx/hotref.py
Gauvain Pocentek f24863cf4d dn2osdbk: handle internal references
The internal references were not properly created. This patches make the
:ref: inline markup create a <xref> tag when the reference is internal.

This patch also reworks the sphinx extension to handle the URLs that
will be generated in the hot-reference with the new :ref: behavior.

Closes-Bug: #1378073
Change-Id: I84bf268dc1055dc6b39f23c4415734184ec57eec
2014-10-11 07:58:38 +02:00

47 lines
1.7 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Sphinx extension to create references to the HOT reference resources.
This extension provides some inline markup to automatically generate links
to the OpenStack HOT reference resources.
Usage examples:
The :hotref:`OS::Nova::Server` resource creates a new instance.
To use this extension, add 'os_doc_tools.sphinx.hotref' in the `extensions`
list of your conf.py file."""
from docutils import nodes
from docutils import utils
def hotref_os_role(name, rawtext, text, lineno, inliner, options={},
content=[]):
app = inliner.document.settings.env.app
link = text.replace(':', '_')
base = app.config.hotref_base_url
ref = "%(base)s/%(name)s.html" % {'base': base, 'name': link}
literal = nodes.literal('')
ref_node = nodes.reference(rawtext, utils.unescape(text),
refuri=ref, **options)
literal.append(ref_node)
return [literal], []
def setup(app):
app.add_role('hotref', hotref_os_role)
app.add_config_value('hotref_base_url',
'http://docs.openstack.org/hot-reference/content',
'env')