scribble icon indicating copy to clipboard operation
scribble copied to clipboard

[WIP] Extended support for highlighting

Open SuzanneSoy opened this issue 8 years ago • 1 comments

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 the baz highlighted. (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 as a b . c, just as (code:line a b c) renders as a b c.
  • Fixes the error message given when a code:hilite is misused (previously: "bad code:redex: ~.s", now: "bad code:hilite: ~.s").
  • Disabled the spurious (set! src-col (add1 src-col)) for code:hilite when the syntax-span of the whole form is 0. This allows tools to wrap elements with code:hilite forms, without having an extra space. The tool needs to give the whole (code:hilite e) form the same srcloc as e, except for the syntax-span which is overridden with 0.

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:

Screenshot showing removed parts in red, added parts in green, existing parts dimmed

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-additions outside 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!

SuzanneSoy avatar May 15 '17 19:05 SuzanneSoy

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))].

SuzanneSoy avatar May 18 '17 13:05 SuzanneSoy