Fwd: Extension - custom role - emit HTML with an 'a' tag wrapped in 'em' tag

22 views
Skip to first unread message

Darren Ng

unread,
Jul 29, 2021, 1:13:08 PM7/29/21
to sphinx...@googlegroups.com
---------- Forwarded message ---------
From: Darren Ng <un1...@gmail.com>
Date: Fri, Jul 30, 2021 at 12:45 AM
Subject: Extension - custom role - emit HTML with an 'a' tag wrapped in 'em' tag
To: <docutils...@lists.sourceforge.net>


Title: Extension - custom role - emit HTML with an 'a' tag wrapped in 'em' tag

With the following extension, I get
'<p><strong><em>asdf</em><sup>2</sup></strong></p>'
from ':emlink:`whatsoever`' successfully.

def emlink_fn(name, rawtext, text, lineno, inliner, options={}, content=[]):
...
root = docutils.nodes.strong()
root += docutils.nodes.emphasis(text='asdf')
root += docutils.nodes.superscript(text='2')
return [root], []
...
def setup(app):
...
app.add_role(name='emlink',
role=emlink_fn,
override=False)
...

Now I want '<p><em><a href="https://example.org">an example</a></em></p>'.

...
root = docutils.nodes.emphasis()
root += docutils.nodes.<I_HAVE_NO_IDEA>(<I_HAVE_NO_IDEA>)
...

What should I do?

Jul 30, 2021
Darren Ng
Reply all
Reply to author
Forward
0 new messages