-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am 05.02.2010 23:09, schrieb Fernando Gómez:
> Hi,
>
> This is another issue motivated by my attempt at literate programming
> with noweb and sphinx.
>
> In a typical LP setting, any block of code may contain links to other
> locations in the document. In other words, within blocks of code one
> can find the markup :ref:`Link title <label-name>`. If we want that
> markup to be properly parsed, a code-block directive won't work, and
> so I'm putting the code in a parsed-literal directive (with a
> corresponding highlight directive to specify the language).
>
> There's a problem though: *all* the inline markup inside a
> parsed-literal directive is parsed, and unfortunately blocks of code
> may contain any of those special characters that will produce
> unintended reST inline markup ("*", "_", "`", "\", "|"). So, the
> solution would be to escape those characters with a backslash. I did
> it, and it seems to work ok. (Of course, those code blocks will look
> ugly, but since the escaped versions are generated automatically from
> clean sources, I don't suffer.)
>
> But... now the highlighting is gone! I guess that the escape sequences
> are interfering with the Pygments parser, and so it cannot highlight
> those code blocks.
Yes, there's this in sphinx.writers.html:
if node.rawsource != node.astext():
# most probably a parsed-literal block -- don't highlight
return BaseTranslator.visit_literal_block(self, node)
I've not thought about how to "fix" it, i.e. have some degree of
highlighting in parsed-literal blocks.
> How can this conflict be solved? How can one have both things: cross
> reference links within code blocks, and highlighted code? Ideally, I'd
> like to have a kind of "restricted parsed-literal" that only parses
> :ref: links and ignores other markup. Or perhaps there's a way to make
> Pygments see the clean, unescaped code so that its parser is not
> bothered by the escape sequences.
The problem is the question of what to feed to Pygments -- it doesn't
have a concept of markup other than what it uses to highlight.
A complete approach I can see right now would be to
* determine at which positions in the whole literal text reference nodes
begin (assuming that all other nodes are discarded)
* let Pygments highlight the whole text
* insert <a> tags at the right positions in the highlighted text
The concrete implementation will however be somewhat convoluted.
A different approach would be to let Pygments highlight the individual
nodes separately, saving the lexer state inbetween. However, that's not
possible without messing with some Pygments internals.
cheers,
Georg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
iEYEARECAAYFAkuBTWcACgkQN9GcIYhpnLAFQgCgk0MTm7XdCnnJ0y7p3bUEirBb
MWkAn3o5H5CoRN3nChZY0SIEZsXIijd/
=Gup3
-----END PGP SIGNATURE-----
--
You received this message because you are subscribed to the Google Groups
"sphinx-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sphinx-dev?hl=en.