Avoiding rest_code_...
on code-blocks
#3816
-
Hi! The listings that Nikola generates are full of import wx is converted into something like: <a id="rest_code_a9db4fab05f54d7fa2fde251e00b63c2-6" name="rest_code_a9db4fab05f54d7fa2fde251e00b63c2-6" href="index.html#rest_code_a9db4fab05f54d7fa2fde251e00b63c2-6"></a>
<span class="kn">import</span> <span class="nn">wx</span> This causes problems for people using screen readers like NVDA. The relevant Nikola code seems to be this, but I could not see any configuration option:
# A sanitized version of docutils.parsers.rst.directives.body.CodeBlock.
class CodeBlock(Directive):
...
def run(self):
"""Run code block directive."""
....
if self.site.invariant: # for testing purposes
anchor_ref = 'rest_code_' + 'fixedvaluethatisnotauuid'
else:
anchor_ref = 'rest_code_' + uuid.uuid4().hex
...
formatter = utils.NikolaPygmentsHTML(
anchor_ref=anchor_ref,
classes=classes,
linenos=linenos,
linenostart=linenostart,
**extra_kwargs
)
out = pygments.highlight(code, lexer, formatter)
.... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
P.S.: I would suggest to avoid these tags by default and enable them only on request. |
Beta Was this translation helpful? Give feedback.
-
This enables linking to specific lines of a listing. This is a useful feature. I don't think we're going to disable it or make it configurable. It might be worth checking if the screen reader issues occur with plain pygments (there are some customisations of ours in use), and if it does, maybe upstream could find a better implementation. That said, good looking code blocks tend to involve HTML and CSS hacks. |
Beta Was this translation helpful? Give feedback.
For wxWidgets we will continue with a local copy of the
listing.py
plugin atwxPyWeb\plugins\compile\rest
.You should think about better accessibility support, though.