[WIP] Extended support for highlighting#109
Conversation
| [first (if escapes? | ||
| (syntax-case c (code:line) | ||
| [(code:line e . rest) #'e] | ||
| [(code:line . rest) #'rest] |
There was a problem hiding this comment.
I think this case only matches (code:line), so it shouldn't hurt but also shouldn't change how anything looks.
There was a problem hiding this comment.
With the patch which I added, you can now write (code:line . foo) which renders as . foo (but previously it was not possible).
Also, technically, we could have a first element which is (code:line (code:line something)), should the code above be called recursively as long as code:line is the first element? (I can amend the patch to include that, if you think it's the right thing to do).
|
Note to self: The problem when making sure that I would therefore either have to "fix" |
This patch:
(code:hilite code style-name)@racket[(a . (b c))]so that the dot is indeed shown if it were present in the source[(code:line . rest) #'rest]. I'm not sure it's correct, though.(foo bar code:hilite baz)renders as(foo bar . baz), with thebazhighlighted.(foo bar code:hilite baz style-name)should also work, and take into account the style name.code:line, so that(code:line a b . c)renders asa b . c, just as(code:line a b c)renders asa b c.code:hiliteis misused (previously:"bad code:redex: ~.s", now:"bad code:hilite: ~.s").(set! src-col (add1 src-col))forcode:hilitewhen thesyntax-spanof the whole form is0. This allows tools to wrap elements withcode:hiliteforms, without having an extra space. The tool needs to give the whole(code:hilite e)form the same srcloc ase, except for thesyntax-spanwhich is overridden with0.These features / changes allow tools to highlight parts of the code, for example
sexp-diffcould be used to generate pretty diffs (such a tool would need to take care of srclocs, though), or to show before/after steps in literate programming. I wrote a small utility which does this:The bulk of the diff comes from moving
lloopout of its formercondcase, so that it can be used both by the[(or (pair? (syntax-e c)) …case and by thecode:linecase.Issues to solve before merging:
[(code:line . rest) #'rest]is correct (first line of the diff). I think it won't cause any harm, but I'd like one of the scribble devs to double-check it.css-additionsoutside of the code. I'm not sure how to embed a style without resorting to 3D syntax, or performing a dynamic-require of some sort. Ideas welcome!