Following up on my own post. So I've now developed a simple literaldiff 
Sphinx extension to the point where it's basically doing what I need: using 
Pygments to format (in my case Python) code in the usual way, but 
highlighting sections which have changed compared to a previous version. 
Since I only have one kind of highlighting, I'm inserting commented text to 
indicate where something has been deleted.

You can see the extension (basically cloned from literalinclude and 
tweaked) here:

  
https://github.com/westpark/wallball/blob/master/docs/sphinx_ext/literaldiff.py

and an example of the result here:

  http://wall-ball.readthedocs.io/en/latest/steps/step03.html

Hope it's helpful to someone!

TJG

On Tuesday, 8 November 2016 09:12:01 UTC, Tim Golden wrote:
>
> [not sure if this a Sphinx or a Pygments question; I'll start here]
>
> I'm trying to find a good approach to worksheets for beginner-friendly 
> [mostly kid-friendly] Coding Dojos. I'm using Sphinx with some 
> literalincludes interspersed to show the code the participants should be 
> writing / working from. Example here:
>
>   http://wall-ball.readthedocs.io/en/latest/steps/step01.html
>
> Obviously I'm trying for a progressive-enhancement approach: each step or 
> sub-step builds on the previous one and produces a visible result with not 
> too many lines of code.
>
> What I want is something like literalinclude diff option but highlighting 
> the changed lines rather than rendering a unified diff. I've cloned the 
> literalinclude logic to produce a literaldiff extension directive and the 
> approach looks like it's going to work: tweak the "diff" logic to return 
> the raw Differ.compare output and then build the "emphasize-lines" lineset 
> from that. 
>
> At this point I seem to be at the point where Sphinx & Pygments touch. At 
> present, Sphinx simply hands off to Pygments and says "highlight those 
> lines". I'm using a customised theme so I can tweak the CSS for the 
> highlighted lines. But what I'd like is to have removed lines highlighted 
> in one way (say: strikeout) with added lines highlighted another way, and 
> updated differently again.
>
> So... should I be trying to implement a Pygments lexer to render my 
> mini-language how I want? Or is there some way from within Sphinx that I 
> can tweak the output directly to add the highlights I want? I'm aware that 
> Pygments has a lexer for the diff format; what I really want, though, is 
> some way to have Python syntax rendering with additional highlighting for 
> the diffed elements.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to