1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
"""
Tooltip Sphinx extension
:copyright: Copyright 2010 by Christian S. Perone
:license: PSF, see LICENSE for details.
"""
from sphinx.util.compat import Directive
from docutils import nodes
import re
def tip_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
matches = re.match("\<(?P<word>\w+)\> (?P<tip>.*)", text)
matches_tuple = matches.group("tip"), matches.group("word")
template = """<span class="ttip" title="%s">%s</span>""" % matches_tuple
node = nodes.raw('', template, format='html')
return [node], []
def setup(app):
app.add_role('tip', tip_role)
|