[Feature/Bug] If a role content is empty, it's never called?

Anil Lakhman <[email protected]>
Newsgroups gmane.text.docutils.user
Message-ID <CALZVzqh+p+A5dVJmWkpBXRGOQTcDshFOd8t4+zyR9=cXWNG_VQ@mail.gmail.com>
Hi,

I'm not subscribed to the mailing list, please CC me if possible on the
issue.

I have filed a github issue here replicating the issue:

https://github.com/sphinx-doc/sphinx/issues/2562

Basically, If I add a custom role and pass an empty string within the
backticks, the role is never called, so I don't have a chance to show a
warning or error message. For example the :download: role shows a warning
message if we pass an empty string or space within the backticks.

Am I missing something or is this not possible? (I'm using sphinx)

Here it is in code:


Say I have the following role which converts an icon role into an inline
font awesome icon:

# e.g: Create an inline <span class="fa fa-rocket fa-2x"></span>def
icon_role(role, rawtext, text, lineno, inliner, options={},
content=[]):
    options.update({'classes': ["fa-" + x for x in text.split(",")]})
    options['classes'].append('fa')
    set_classes(options)
    node = nodes.inline(**options)
    return [node], []
# ... add it - Note i'm using sphinx hence `app`

app.add_role('icon', icon_role)

# Now I use it like so:
:icon:`rocket,2x`

#= <span class="fa fa-rocket"></span>

Issue

# Now say I forget to pass through some text or empty space
# (accidently deleted, forget I had it, etc..)
:icon:``    # No text
:icon:` `   # Space empty text

#= :icon:``
#= :icon:` `

# Notice how it just outputs the role raw, it doesn't seem to even
call `icon_role`
# so I don't have a chance to check the value (and throw a warning)

If the content with backticks is empty, I would like to decide what to do
with the role (output a empty node, throw a warning, place a default icon).

Am I missing something?

The :download: role does this, but I'm finding it confusing as to who it's
implemented. It throws the following error if you pass an empty string.

# Throws an error: WARNING: Inline literal start-string without end-string.
:download:``

# Just outputs the raw role text (I don't have a chance to do anything)
:icon:``

Any Ideas?


You can also reply to this github ticket on sphinx:


https://github.com/sphinx-doc/sphinx/issues/2562


Any help would be very much appreciated! - This could be an excellent
feature for validation, if it doesn't exist already.


Thanks!

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.