Skurhse Rage
Skurhse Rage

Reputation: 1020

Using <i> tags in reStructuredText

I know that the following syntaxes work for <em> tags:

:emphasis:`lorum ipsum`
*lorum ipsum*

How can I generate <i> tags instead? I can't seem to find any mention in the Markup Specification.

Upvotes: 4

Views: 145

Answers (3)

G. Milde
G. Milde

Reputation: 862

Since Docutils version 0.17 (rsp. the repository version 0.17dev), the "html5" writer will write <i> tags, if a matching class value is found in inline and literal elements::

.. role:: i

In the "html5" writer output,
:i:`this text is set in a <i> Element`.

This works also with other roles, 
if you give them the "i" class value, e.g.:

.. role:: alternative-voice
   :class: i, language-la

Lemonade consists primarily of :alternative-voice:`Citrus limon`.

Copy the example to a file "foo.txt", say and call rst2html5.py foo.txt foo.html to see the result.

Upvotes: 2

Kevin Horn
Kevin Horn

Reputation: 4295

Before we get into the guts of this, are you sure you really need <i> tags specifically? People often use <i> when they really mean <em>...and they almost always look the same by default...

No? You really need <i> tags>? Okay, then here we go.


In order to control the HTML tags emitted by docutils, you need to create a new "writer". These are the docutils components that generate output in whatever desired format (e.g. HTML, LateX, etc.).

You can find the various HTML writers included with docutils in the docutils source repo here.

This will require writing some Python code. Essentially up will need to provide a Python class which emits the HTML you want.

Looking briefly at the source, you can probably subclass whichever HTML writer best suits your needs (these days you probably want html5_polyglot) and override the visit_emphasis method.

You will then need to find a way to tell docutils to use your new writer. Check out the tools directory for some examples.

If you're using Sphinx I'm really not sure off hand how to get a different writer in there. You might have to modify (or monkeypatch) the Sphinx source.

Upvotes: 1

Jin Thakur
Jin Thakur

Reputation: 2773

Text enclosed by single asterisk characters is emphasized:

This is emphasized text. Emphasized text is typically displayed in italics.

Upvotes: -1

Related Questions