Commit graph

21 commits

Author SHA1 Message Date
Vincent Ambo
082ed2a74f chore(cheddar): Clean up all clippy lints
Change-Id: I5544c10e964b57891fce6ea01f09eeec406e9bef
Reviewed-on: https://cl.tvl.fyi/c/depot/+/510
Reviewed-by: lukegb <lukegb@tvl.fyi>
2020-06-20 03:00:46 +00:00
Vincent Ambo
e27b0a3013 feat(cheddar): Add Sourcegraph-compatible highlighting server
Sourcegraph uses a component called syntect_server to syntax-highlight
source files.

Since we already have custom syntaxes, overrides and configuration we
might as well use them with Sourcegraph!

This implements the syntect_server "protocol" (it's just a single
endpoint) so that we can swap out the syntect_server component with
cheddar.

Note: There's a few clippy lints here, but they're being solved in a
followup commit because I wanted to take care of all of them at
once (not just the ones introduced in this change).

Change-Id: Ib518a2fa1b9fee299fe599482403599583cac479
Reviewed-on: https://cl.tvl.fyi/c/depot/+/509
Reviewed-by: lukegb <lukegb@tvl.fyi>
2020-06-20 02:59:20 +00:00
Vincent Ambo
dbb4a57bbf style(cheddar): Reformat with rustfmt
Change-Id: I9a0764f23c1269447a8b18f3128074fc58f70456
Reviewed-on: https://cl.tvl.fyi/c/depot/+/492
Reviewed-by: glittershark <grfn@gws.fyi>
2020-06-19 02:49:41 +00:00
Vincent Ambo
d1524a5a6f refactor(cheddar): Pass references readers & writers into renderers
This paves the way for using other things than stdin/stdout as
sources/sinks, which is required for example for implementing a
syntect_server replacement based on cheddar.

Change-Id: I5779db8dbf7b7ced109c26b940f721d237d60785
Reviewed-on: https://cl.tvl.fyi/c/depot/+/491
Reviewed-by: glittershark <grfn@gws.fyi>
Reviewed-by: lukegb <lukegb@tvl.fyi>
2020-06-19 02:49:41 +00:00
Vincent Ambo
5e5e02d6a7 refactor(cheddar): Switch to clap-rs for command line arguments
The complexity of the arg parsing is increasing somewhat because we're
adding more features to cheddar, so to set us up for that this
switches the arg parsing to the somewhat more flexible clap.

Change-Id: I187bc0c1b6c6bd596fa0f6bb494b04e335262ba9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/445
Reviewed-by: lukegb <lukegb@tvl.fyi>
Reviewed-by: tazjin <mail@tazj.in>
2020-06-17 01:18:16 +00:00
Vincent Ambo
51594b0594 chore(cheddar): Bump all dependencies
Manual updates:
  comrak 0.6 -> 0.7
  syntect 3.3 -> 4.2.0

Leading to these automatic updates:
    Updating crates.io index
    Updating adler32 v1.0.4 -> v1.1.0
      Adding autocfg v1.0.0
    Updating base64 v0.10.1 -> v0.12.2
    Removing bindgen v0.53.3
    Removing cexpr v0.4.0
      Adding chrono v0.4.11
    Removing clang-sys v0.29.3
    Updating comrak v0.6.2 -> v0.7.0
    Removing env_logger v0.7.1
    Removing glob v0.3.0
    Updating hermit-abi v0.1.13 -> v0.1.14
    Removing humantime v1.3.0
      Adding indexmap v1.4.0
    Updating itoa v0.4.5 -> v0.4.6
    Updating libc v0.2.70 -> v0.2.71
    Removing libloading v0.5.2
    Removing log v0.4.8
    Updating miniz_oxide v0.3.6 -> v0.3.7
    Removing nom v5.1.1
      Adding num-integer v0.1.43
      Adding num-traits v0.2.12
    Updating onig v5.0.0 -> v6.0.0
    Removing peeking_take_while v0.1.2
    Updating plist v0.4.2 -> v1.0.0
    Updating proc-macro2 v1.0.17 -> v1.0.18
    Removing quick-error v1.2.3
    Updating quote v1.0.6 -> v1.0.7
    Updating regex v1.3.7 -> v1.3.9
    Updating regex-syntax v0.6.17 -> v0.6.18
    Removing rustc-hash v1.1.0
    Updating ryu v1.0.4 -> v1.0.5
    Updating serde v1.0.110 -> v1.0.112
    Updating serde_derive v1.0.110 -> v1.0.112
    Updating serde_json v1.0.53 -> v1.0.55
    Removing shlex v0.1.1
    Updating syn v1.0.25 -> v1.0.31
    Updating syntect v3.3.0 -> v4.2.0
    Removing termcolor v1.1.0
    Removing version_check v0.9.2
    Removing which v3.1.1
    Updating yaml-rust v0.4.3 -> v0.4.4

Change-Id: I2c2ee6a45bf7a5286fe30d61de52d7993871e7e1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/444
Reviewed-by: lukegb <lukegb@tvl.fyi>
2020-06-16 23:59:48 +00:00
Vincent Ambo
9885b70b7a feat(cheddar): Override syntax highlighting for 'rules.pl' to Prolog
Adds a mechanism for per-filename overrides of the chosen language
syntax and configures it for Gerrit's submit rule file.

This also switches the syntax set used to the one from
//third_party/bat_syntaxes, which contains custom additions such as
Prolog support.

Change-Id: I2023dbad5b326305ef2ef0ecf34ef66a3f7575ab
Reviewed-on: https://cl.tvl.fyi/c/depot/+/349
Reviewed-by: riking <rikingcoding@gmail.com>
Reviewed-by: lukegb <lukegb@tvl.fyi>
2020-06-15 16:52:27 +00:00
Vincent Ambo
6f8fbf4aa4 chore(tools/cheddar): Bump dependencies & upgrade to LLVM 10 2020-05-25 23:37:39 +01:00
Vincent Ambo
4bbbb58cb5 chore: Rename pkgs->depot in all Nix file headers 2020-02-21 13:54:53 +00:00
Vincent Ambo
14b5447aac Merge branch 'feat/cheddar-extensions' 2020-02-09 12:07:10 +00:00
Vincent Ambo
d752cbecc0 feat(cheddar): Add toggle flag for about-filter behaviour
Cheddar now needs to be passed the --about-filter flag to toggle the
behaviour for rendering Markdown into HTML.

By default Markdown will be highlighted like normal source code (i.e.
cgit source-filtering is the default behaviour).
2020-01-19 23:54:30 +00:00
Vincent Ambo
2236d43ff7 feat(cheddar): Implement callout paragraphs
Implements support for tagging paragraphs that begin with a callout
word (TODO, WARNING, QUESTION, TIP) with an additional `cheddar-*`
class that makes it possible to render these callouts specially.

This is currently not the nicest implementation, but it works.
2020-01-11 05:06:36 +00:00
Vincent Ambo
d4e469508f refactor(cheddar): Extract code block highlighting into function
Since I am going down the path of adding additional Markdown
extensions it makes sense to avoid letting `format_markdown` turn into
a giant beast of a function.

Therefore this commit extracts the logic for rendering code blocks via
syntect and changes the innards of `format_markdown` to instead
provide arbitrary AST value replacements.
2020-01-11 02:17:19 +00:00
Vincent Ambo
a36e9f817d fix(cheddar): Fix errors if filename does not have an extension 2019-12-22 15:21:23 +00:00
Vincent Ambo
03acae2f85 feat(cheddar): Style pre-elements for better readability
Uses GitHub-like styling for <pre> elements, i.e. slight padding and
background colour highlighting.
2019-12-21 16:18:26 +00:00
Vincent Ambo
f904951384 feat(cheddar): Render code blocks in Markdown via syntect
Implements fully static (i.e. no JavaScript!) highlighting of code
blocks when rendering Markdown.

This works by walking through the Comrak AST and replacing any code
blocks with pre-rendered HTML blocks.

Syntaxes are chosen based on the "block info", which is the string
users put after the block's opening fence. This can either be
a (case-insensitive) name of a syntax, or alternatively a file
extension associated with the desired syntax.

The theme is set to one that imitates GitHub.
2019-12-21 15:57:02 +00:00
Vincent Ambo
671dbc7f72 docs(cheddar): Mention cgit filter compatibility in README 2019-12-21 15:56:44 +00:00
Vincent Ambo
d6c255a35d feat(cheddar): Render Markdown via Comrak
Renders any ".md" file by pushing it through the Comrak rendering
pipeline.

This does not yet implement syntax highlighting of fenced blocks, but
we're getting there.
2019-12-21 14:49:35 +00:00
Vincent Ambo
d35aa4ae46 refactor(cheddar): Set up scaffolding for Markdown rendering
Generalises the two bits of the program that will be required either
way (extension parsing and syntax loading).

A dependency on Comrak is introduced as I think GitHub-flavoured
Markdown (with all its fancy extensions) is desirable!
2019-12-21 14:09:12 +00:00
Vincent Ambo
81d9b81b06 feat(cheddar): Use syntax highlighting assets from bat
This uses Nix to inject the path to the syntax highlighting assets
that ship with the bat source code into the cheddar build at compile
time, where the Rust compiler then inserts it into the binary via
macros.

bat has a lot of custom syntax highlighting definitions that they
collected from all over the place (including for languages like Nix!)
and this makes them accessible to cheddar.

Also if you're reading this, can you just take a moment to appreciate
how incredible it is that Nix just lets us do something like this?!
2019-12-21 04:55:10 +00:00
Vincent Ambo
4681c07bde feat(tools/cheddar): Check in new syntax highlighting tool
The first step with this tool will be to use it as a source-filter for
cgit. The second step is to use it as the Markdown renderer by
depending on one of the Markdown libraries, with integration for
rendering code snippets directly.
2019-12-21 04:54:57 +00:00