Anil Lakhman
2016-05-20 16:51:39 UTC
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!
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!