Define role for the whole project?

148 views
Skip to first unread message

Boris Kheyfets

unread,
Nov 13, 2012, 4:58:01 AM11/13/12
to sphinx...@googlegroups.com

Some times I use roles, for example to include an empty line between paragraphs I add:

.. only:: html

   :raw-html:` `

for this one has to define role:

.. role:: raw-html(raw)
   :format: html

So I have to duplicate these two lines in all rst files within a project.

Can I somehow make the role global for a project -- for example I'd set this in index.rst, and that will be all: I'll be able to use &nbsp in all rst files.

Martin Bless

unread,
Nov 13, 2012, 6:55:47 AM11/13/12
to sphinx...@googlegroups.com
Hi Boris Kheyfets,

> Can I somehow make the role global for a project -- for example I'd
> set this in index.rst, and that will be all: I'll be able to use &nbsp
> in all rst files.

we are using a single "includes.txt" which we then include in each ReST
document at the top. Could then look like

.. include:: includes.txt

or

.. include:: ../../../../includes.txt

Martin

Takayuki Shimizukawa

unread,
Nov 13, 2012, 9:37:16 AM11/13/12
to sphinx...@googlegroups.com
Hi Boris,

I'd like to introduce other two methods.

1. rst_prolog setting in conf.py::

rst_prolog = """
.. role:: raw-html(raw)
:format: html
"""

.. seealso:: http://sphinx-doc.org/config.html#confval-rst_prolog


2. call app.add_role() in conf.py::

## append these code to conf.py

from docutils.parsers.rst.roles import code_role

def raw_html_role(role, rawtext, text, lineno, inliner,
options={}, content=[]):
options['format'] = ['html']
return code_role(
role, rawtext, text, lineno, inliner,
options=options, content=content)

def setup(app):
app.add_role('raw-html', raw_html_role)

.. seealso::
http://sphinx-doc.org/ext/appapi.html#sphinx.application.Sphinx.add_role

Best regards,
--
Takayuki SHIMIZUKAWA
http://about.me/shimizukawa


2012/11/13 Martin Bless <martin...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "sphinx-users" group.
> To post to this group, send email to sphinx...@googlegroups.com.
> To unsubscribe from this group, send email to sphinx-users...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sphinx-users?hl=en.
>
>

Boris Kheyfets

unread,
Dec 12, 2012, 2:15:46 AM12/12/12
to sphinx...@googlegroups.com
Thank You both, I'll use rst_prolog.

--
Boris.

Boris Kheyfets

unread,
Dec 12, 2012, 2:16:42 AM12/12/12
to sphinx...@googlegroups.com
Good solution. I forgot about include.

--
Boris.
Reply all
Reply to author
Forward
0 new messages