Hi,
To registeri custom node is a standard way to do that.
If added, you can add handlers for each builders::
from docutils import node
class sidenote(nodes.Inline):
pass
def sidenote_role(...):
""" Generate sidenote node from role definition """
role = sidenote()
role['tag'] = user_tag
role['message'] = user_message
return [role], []
def html_visit_sidenote(self, node):
""" Generate HTML for sidenote """
self.body.append('<label /><span>' + node['message'])
def html_depart_sidenote(self, node):
""" Generate HTML for sidenote """
self.body.append('</span>')
def latex_visit_sidenote(self, node):
""" Generate LaTeX code for sidenote """
def latex_depart_sidenote(self, node):
""" Generate LaTeX code for sidenote """
def setup(app):
app.add_node(sidenote,
html=(html_visit_sidenote, html_depart_sidenote),
latex=(latex_visit_sidenote, latex_depart_sidenote))
app.add_role('sidenote', sidenote_role)
Thanks,
Takeshi KOMIYA
2016年8月15日月曜日 11時40分18秒 UTC+9 Ganesh Vijayakumar:
>
> Hello,
>
> I wrote a simple extension to include a html tag for a role I wanted.
> Could you please tell me how I can customize this role for latex build vs
> html build?
>
> # Tufte style side note for Sphinx
> from docutils import nodes
> import string
>
> def sideNote_html(tagName,message):
> return '<label for="sn-{0}" class="margin-toggle
> sidenote-number"></label><\
> /span><input type="checkbox" id="sn-{0}" class="margin-toggle"/><span
> class="si\
> denote">{1}</span>'.format(tagName, message)
>
> def sidenote_role(typ, rawtext, text, lineno, inliner, options={},
> content=[]):
> """
> Role to include Tufte style side note
> """
> text = text.decode('utf-8').encode('utf-8')
> # Handle sidenotes of the form "<tagName> SideNoteMessage"
> if '<' in text and '>' in text:
> tagName, sideNoteMessage = text.split('>')
> tagName = tagName.split('<')[1]
> else:
> tagName=''
> sideNoteMessage=''
>
> sideNoteHTML = sideNote_html(tagName, sideNoteMessage)
> node = nodes.raw('', sideNoteHTML, format='html')
> return [node], []
>
> def setup(app):
> app.add_role('sidenote', sidenote_role)
>
>
> ganesh
>
>
--
You received this message because you are subscribed to the Google Groups
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.