[WIP] Extended support for highlighting
This patch:
- Adds support for custom CSS styles for
(code:hilite code style-name) - Fixes rendering of
@racket[(a . (b c))]so that the dot is indeed shown if it were present in the source - I tentatively added a case when determining the first element
[(code:line . rest) #'rest]. I'm not sure it's correct, though. - Adds support for code:hilite in a dotted tail position:
(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. - Adds support for dotted tail elements to
code:line, so that(code:line a b . c)renders asa b . c, just as(code:line a b c)renders asa b c. - Fixes the error message given when a
code:hiliteis misused (previously:"bad code:redex: ~.s", now:"bad code:hilite: ~.s"). - Disabled the spurious
(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-diff could 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 lloop out of its former cond case, so that it can be used both by the [(or (pair? (syntax-e c)) … case and by the code:line case.
Issues to solve before merging:
- [ ] I'm not sure if the
[(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. - [ ] Documentation
- [ ] It would be nice to be able to specify a highlight style, instead of specifying a style name. Currently, it is necessary to manually inject the
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!
Note to self: The problem when making sure that @racket[(a . (b c))] gets rendered as (a . (b c)) instead of (a b c), i.e. the second point of the PR, is that scribble's @defform produces nested syntax pairs, instead of producing a syntax list.
I would therefore either have to "fix" defform (and test the other forms, @defproc works fine but others may exhibit similar problems), or remove this part of the patch, or make it an option, e.g. accessible via @racket/dots[(a . (b c))].