Non-italic references

33 views
Skip to first unread message

Ignacio Fernández Galván

unread,
Feb 13, 2015, 10:58:50 AM2/13/15
to sphin...@googlegroups.com
Hello,

I'd like to have the option not to have all references in italics. I can
get that by modifying sphinx/domains/std.py:

innernode = nodes.emphasis(sectname, sectname)

into:

innernode = nodes.inline(sectname, sectname)

but I'd rather keep the modifications local to the project. Is this
possible?

A related is that, if I wanted to keep the references in italic, I don't
know how to fix the numsec extension
(https://github.com/jterrace/sphinxtr/blob/master/extensions/numsec.py).
It seems it's replacing the emphasis node with the text:

node.replace(emphnode, nodes.Text(linktext))

and this puts the reference always in non-italics. I'd like the
references created by numsec to be in the same style (italics or not) as
the rest.

Thanks,
Ignacio

Guenter Milde

unread,
Feb 15, 2015, 11:36:21 AM2/15/15
to sphin...@googlegroups.com
On 2015-02-13, Ignacio Fernández Galván wrote:
> Hello,

> I'd like to have the option not to have all references in italics. I can
> get that by modifying sphinx/domains/std.py:

> innernode = nodes.emphasis(sectname, sectname)

> into:

> innernode = nodes.inline(sectname, sectname)

> but I'd rather keep the modifications local to the project. Is this
> possible?

If you want just HTML output, you can style the node with a custom CSS style
sheet.

> A related is that, if I wanted to keep the references in italic, I don't
> know how to fix the numsec extension
> (https://github.com/jterrace/sphinxtr/blob/master/extensions/numsec.py).
> It seems it's replacing the emphasis node with the text:

> node.replace(emphnode, nodes.Text(linktext))

> and this puts the reference always in non-italics. I'd like the
> references created by numsec to be in the same style (italics or not) as
> the rest.

Again, have a look at the HTML for item hierarchy and classe and add a
custom CSS rule.

Günter

Ignacio Fernández Galván

unread,
Feb 16, 2015, 5:04:58 AM2/16/15
to sphin...@googlegroups.com, mi...@users.sf.net

On Sunday, February 15, 2015 at 5:36:21 PM UTC+1, Guenter Milde wrote:

> innernode = nodes.emphasis(sectname, sectname)

> into:

> innernode = nodes.inline(sectname, sectname)

> but I'd rather keep the modifications local to the project. Is this
> possible?

If you want just HTML output, you can style the node with a custom CSS style
sheet.

Sure, but I'd prefer the emphasis node not to be there at all. In CSS terms, I think it's more logical to say that I want "references in italics", rather than "em tags within references not in italics"
 
> A related is that, if I wanted to keep the references in italic, I don't
> know how to fix the numsec extension
> (https://github.com/jterrace/sphinxtr/blob/master/extensions/numsec.py).
> It seems it's replacing the emphasis node with the text:

> node.replace(emphnode, nodes.Text(linktext))

> and this puts the reference always in non-italics. I'd like the
> references created by numsec to be in the same style (italics or not) as
> the rest.

Again, have a look at the HTML for item hierarchy and classe and add a
custom CSS rule.

Now I'm not talking about the style, but about the structure itself. I'd like the numsec to modify only the text of the reference and not the style/structure. As it is now, it replaces the whole emphasis node with something else. If I try to just replace "textnode" instead of "emphnode", I get this error:

Exception occurred:
  File "/home/ignacio/.local/lib/python2.7/site-packages/docutils/nodes.py", line 689, in index
    return self.children.index(item)
ValueError: <#text: 'Test'> is not in list

where "Test" is the heading pointed to by the label. So, I'm asking for help on how to modify secnum to make it work with or without the emphasis node.

Thanks,
Ignacio

Ignacio Fernández Galván

unread,
Feb 17, 2015, 3:47:39 AM2/17/15
to sphin...@googlegroups.com, mi...@users.sf.net


On Monday, February 16, 2015 at 11:04:58 AM UTC+1, Ignacio Fernández Galván wrote:

Now I'm not talking about the style, but about the structure itself. I'd like the numsec to modify only the text of the reference and not the style/structure. As it is now, it replaces the whole emphasis node with something else. If I try to just replace "textnode" instead of "emphnode", I get this error:

Exception occurred:
  File "/home/ignacio/.local/lib/python2.7/site-packages/docutils/nodes.py", line 689, in index
    return self.children.index(item)
ValueError: <#text: 'Test'> is not in list

where "Test" is the heading pointed to by the label. So, I'm asking for help on how to modify secnum to make it work with or without the emphasis node.

Doh! I was misinterpreting the code... I can fix numsec with this: https://github.com/jterrace/sphinxtr/issues/31 Now at least the structure is consistent.

Takayuki Shimizukawa

unread,
Feb 20, 2015, 6:07:47 PM2/20/15
to sphin...@googlegroups.com, mi...@users.sf.net
Hi,

You can replace a node before rendering by using transform.
IMO, in this case you can write transform in your conf.py as:

```
from docutils.transforms import Transform

class EmphasisTransform(Transform):
    default_priority = 210

    def apply(self):
        for node in self.document.traverse(nodes.emphasis):
             new_node = nodes.inline(rawsource='', *node.children)
             node.replace_self(new_node)

def setup(app):
    app.add_transform(EmphasisTransform)
```
(not tested, it'll probably work.. )

Regards,
--
Takayuki SHIMIZUKAWA

--
You received this message because you are subscribed to the Google Groups "sphinx-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ignacio Fernández Galván

unread,
Feb 25, 2015, 8:50:01 AM2/25/15
to sphin...@googlegroups.com, mi...@users.sf.net
Thanks.

Note that I don't want to replace all emphasis nodes, only those that have been added (unnecessarily, I'd say) in references. Anyway, I tried this in conf.py:

from docutils import nodes
from docutils.transforms import Transform

class EmphasisTransform(Transform):

    default_priority
= 999

   
def apply(self):
       
for node in self.document.traverse(nodes.paragraph):
             
print node

def setup(app):
    app
.add_transform(EmphasisTransform)

and what I get is something like:

<paragraph ids="index-1">Lorem ipsum dolor <pending_xref refdoc="doc" refdomain="std" refexplicit="False" reftarget="label" reftype="numref" refwarn="True"><literal classes="xref std std-numref">label</literal></pending_xref> ...</paragraph>

What's important: no emphasis node, no reference node, so there's nothing to replace. I tried different values of default_priority, and it doesn't seem to change.

Takayuki Shimizukawa

unread,
Feb 25, 2015, 9:17:49 AM2/25/15
to sphin...@googlegroups.com, mi...@users.sf.net
Hi,

Your code just traverse nodes.paragraph.
If you want to traverse all nodes, you should call .traverse() without argument.

FYI.
This is a reference of the traverse api.

Regards,
--
Takayuki SHIMIZUKAWA

--

Robert Lehmann

unread,
Feb 25, 2015, 9:29:37 AM2/25/15
to sphin...@googlegroups.com, mi...@users.sf.net
I think the problem Ignacio was pointing at is that there are no emphasis or reference nodes in that doctree.  As far as I understand, the problem is that Transforms are applied on a per-document basis and thus pending_xref is only replaced very late in the build, not by a transform.

I'd personally vote for fixing this in Sphinx because I consider it a bug.  References should not dictate their styling, which emphasis is very much used for.  Obviously, we'd need to augment all themes to restore the default italic style.

Georg Brandl

unread,
Feb 25, 2015, 9:53:49 AM2/25/15
to sphin...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I just fixed this. I don't think the themes need to be changed; I consider the
styling to be a bit ugly anyway (in HTML; things are different for Latex and
text writers where there is (often) no coloring and underlines possible to
mark links).

Georg

On 02/25/2015 03:29 PM, Robert Lehmann wrote:
> I think the problem Ignacio was pointing at is that there /are no/ emphasis
> or reference nodes in that doctree. As far as I understand, the problem is
> that Transforms are applied on a per-document basis and thus pending_xref
> <http://sphinx-doc.org/extdev/nodes.html#sphinx.addnodes.pending_xref> is
> only replaced very late in the build, not by a transform.
>
> I'd personally vote for fixing this in Sphinx because I consider it a bug.
> References should not dictate their styling, which emphasis is very much
> used for. Obviously, we'd need to augment all themes to restore the
> default italic style.
>
>
> On Wed, Feb 25, 2015 at 3:17 PM, Takayuki Shimizukawa
> <shimi...@gmail.com <mailto:shimi...@gmail.com>> wrote:
>
> Hi,
>
> Your code just traverse nodes.paragraph. If you want to traverse all nodes,
> you should call .traverse() without argument.
>
> FYI. This is a reference of the traverse api.
> http://code.nabla.net/doc/docutils/api/docutils/nodes/docutils.nodes.Node.html#docutils.nodes.Node.traverse
>
> This is sphinx code for example:
> https://github.com/sphinx-doc/sphinx/blob/master/sphinx/transforms.py
>
> Regards, -- Takayuki SHIMIZUKAWA http://about.me/shimizukawa
>
> On Wed Feb 25 2015 at 22:50:03 Ignacio Fernández Galván <jel...@gmail.com
> <mailto:jel...@gmail.com>> wrote:
>
> Thanks.
>
> Note that I don't want to replace all emphasis nodes, only those that have
> been added (unnecessarily, I'd say) in references. Anyway, I tried this in
> conf.py:
>
> | fromdocutils importnodes | | fromdocutils.transforms importTransform
>
> classEmphasisTransform(Transform): | |
>
> default_priority =999
>
> defapply(self): fornode inself.document.traverse(nodes.paragraph):
> printnode
>
> defsetup(app): app.add_transform(EmphasisTransform) |
>
> and what I get is something like:
>
> <paragraph ids="index-1">Lorem ipsum dolor <pending_xref refdoc="doc"
> refdomain="std" refexplicit="False" reftarget="label" reftype="numref"
> refwarn="True"><literal classes="xref std
> std-numref">label</literal></pending_xref> ...</paragraph>
>
> What's important: no emphasis node, no reference node, so there's nothing
> to replace. I tried different values of default_priority, and it doesn't
> seem to change.
>
>
>
> On Saturday, February 21, 2015 at 12:07:47 AM UTC+1, Takayuki SHIMIZUKAWA
> wrote:
>
> Hi,
>
> You can replace a node before rendering by using transform. IMO, in this
> case you can write transform in your conf.py as:
>
> ``` from docutils.transforms import Transform
>
> class EmphasisTransform(Transform): default_priority = 210
>
> def apply(self): for node in self.document.traverse(nodes.__emphasis):
> new_node = nodes.inline(rawsource='', *node.children)
> node.replace_self(new_node)
>
> def setup(app): app.add_transform(__EmphasisTransform) ``` (not tested,
> it'll probably work.. )
>
> -- You received this message because you are subscribed to the Google
> Groups "sphinx-dev" group. To unsubscribe from this group and stop
> receiving emails from it, send an email to
> sphinx-dev+...@googlegroups.com
> <mailto:sphinx-dev+...@googlegroups.com>. For more options, visit
> https://groups.google.com/d/optout.
>
> -- You received this message because you are subscribed to the Google
> Groups "sphinx-dev" group. To unsubscribe from this group and stop
> receiving emails from it, send an email to
> sphinx-dev+...@googlegroups.com
> <mailto:sphinx-dev+...@googlegroups.com>. For more options, visit
> https://groups.google.com/d/optout.
>
>
> -- You received this message because you are subscribed to the Google
> Groups "sphinx-dev" group. To unsubscribe from this group and stop
> receiving emails from it, send an email to
> sphinx-dev+...@googlegroups.com
> <mailto:sphinx-dev+...@googlegroups.com>. For more options, visit
> https://groups.google.com/d/optout.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlTt4fEACgkQN9GcIYhpnLC/IgCfWc6hZHtJuWRX/1f1UjWRs2LI
lBsAmwYIyjtB8+u74TZsh+y/vpRhDEuH
=xKK3
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages