Skip to content

Commit 46dfd96

Browse files
committed
docs: highlight cookbook code blocks via makeup_syntect
Adds makeup_syntect + a docs alias step aliasing bash/sh fences to the shell grammar, so toml/bash/sh/python/rust/markdown blocks highlight.
1 parent 9b72969 commit 46dfd96

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

mix.exs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ defmodule Hyper.MixProject do
7171
{:junit_formatter, "~> 3.4", only: :test, runtime: false},
7272
{:dialyxir, "~> 1.4", only: [:dev], runtime: false},
7373
{:ex_doc, "~> 0.34", only: :dev, runtime: false},
74+
# Syntect-backed Makeup lexer: covers the doc languages that have no
75+
# dedicated Makeup lexer (markdown, toml, bash, sh, python). Elixir/erlang
76+
# still use their native lexers; this fills the rest in one dep.
77+
{:makeup_syntect, "~> 0.1", only: :dev, runtime: false},
7478
{:ecto_sql, "~> 3.13"},
7579
{:grpc, "~> 1.0"},
7680
{:grpc_server, "~> 1.0"},
@@ -109,6 +113,8 @@ defmodule Hyper.MixProject do
109113
extras: [
110114
"README.md",
111115
"docs/cookbook/intro.md",
116+
"docs/cookbook/install.md",
117+
"docs/cookbook/config.md",
112118
"docs/cookbook/architecture.md",
113119
"docs/grpc.md"
114120
],
@@ -187,6 +193,32 @@ defmodule Hyper.MixProject do
187193
end
188194

189195
# `mix check` - the strict gate. Runs fast checks first, slow ones (dialyzer) last.
196+
# Give ```bash / ```sh real syntax highlighting in the docs.
197+
#
198+
# Two obstacles, both about *who registers the lexer last*:
199+
# 1. makeup_syntect registers the shell grammar only under its raw syntect
200+
# name "Shell-Unix-Generic" (ExDoc resolves fences by lexer name, not
201+
# file extension), so ```bash / ```sh never reach it.
202+
# 2. ExDoc itself registers a minimal `ExDoc.ShellLexer` for sh/bash/shell/
203+
# zsh (it only de-selects the `$ ` prompt; everything else is plain text)
204+
# from `ExDoc.Application.start`, which runs during the `docs` task.
205+
#
206+
# So we start :ex_doc and :makeup_syntect here first (idempotent — the later
207+
# `docs` task won't re-run their `start/2`), then register our shell aliases
208+
# LAST so they win. Dev-only; runs as the `docs` alias's first step.
209+
defp register_doc_lexers(_args) do
210+
{:ok, _} = Application.ensure_all_started(:makeup_syntect)
211+
{:ok, _} = Application.ensure_all_started(:ex_doc)
212+
213+
Makeup.Registry.register_lexer(MakeupSyntect.Lexer,
214+
options: [language: "Shell-Unix-Generic"],
215+
names: ["bash", "sh", "shell", "zsh"],
216+
extensions: []
217+
)
218+
219+
:ok
220+
end
221+
190222
defp aliases do
191223
[
192224
check: [
@@ -196,6 +228,12 @@ defmodule Hyper.MixProject do
196228
"test --warnings-as-errors",
197229
"dialyzer"
198230
],
231+
# makeup_syntect registers the shell grammar only under its raw syntect
232+
# name "Shell-Unix-Generic", and ExDoc resolves fences by lexer *name*
233+
# (not file extension), so ```bash / ```sh would fall back to plain text.
234+
# Alias them to the shell grammar before ExDoc runs (same VM, so the
235+
# registration is visible to the highlighter).
236+
docs: ["loadpaths", &register_doc_lexers/1, "docs"],
199237
# Force a regeneration of the Firecracker bindings (ignores staleness).
200238
"firecracker.gen": ["compile.firecracker_gen --force"],
201239
# Force a regeneration of the gRPC bindings (ignores staleness).

mix.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
%{
22
"acceptor_pool": {:hex, :acceptor_pool, "1.0.1", "d88c2e8a0be9216cf513fbcd3e5a4beb36bee3ff4168e85d6152c6f899359cdb", [:rebar3], [], "hexpm", "f172f3d74513e8edd445c257d596fc84dbdd56d2c6fa287434269648ae5a421e"},
33
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
4+
"castore": {:hex, :castore, "1.0.19", "6903cabdfd9d1af46454126e7c8385186659dd33ecfb74a885cae52221ad6109", [:mix], [], "hexpm", "3669e6cab13f54c2df26b3e6833745d647f35b6e30d8ddd5975df0d5c842ca98"},
45
"chatterbox": {:hex, :ts_chatterbox, "0.15.1", "5cac4d15dd7ad61fc3c4415ce4826fc563d4643dee897a558ec4ea0b1c835c9c", [:rebar3], [{:hpack, "~> 0.3.0", [hex: :hpack_erl, repo: "hexpm", optional: false]}], "hexpm", "4f75b91451338bc0da5f52f3480fa6ef6e3a2aeecfc33686d6b3d0a0948f31aa"},
56
"cowboy": {:hex, :cowboy, "2.16.1", "fa04080b602ff25c40a7700f2dc0152dbc1ba26b42093ae0fa9bb7a337d5a242", [:make, :rebar3], [{:cowlib, ">= 2.16.0 and < 3.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, ">= 1.8.0 and < 3.0.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "b8ea4dd317a043e3177ec840cfa3bcb47cfb41035d3abb24d954dc7d51def399"},
67
"cowlib": {:hex, :cowlib, "2.17.1", "3e6053016d1ab245730f0af688755476dcedb1c25ed8fb5751f59a2bfdc0c9af", [:make, :rebar3], [], "hexpm", "ff08bd17e6dd931445b18af77315b9b5fe052407110964ad2588c686b57b5e3f"},
@@ -38,6 +39,7 @@
3839
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
3940
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
4041
"makeup_erlang": {:hex, :makeup_erlang, "1.1.0", "835f7e60792e08824cda445639555d7bf1bbbddb1b60b306e33cb6f6db24dc74", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "1cd6780fb1dd1a03979abaed0fe82712b0625118fd5257d3ebbf73f960c73c3c"},
42+
"makeup_syntect": {:hex, :makeup_syntect, "0.1.4", "e1230c9e0513c667b226b21c83eb182e1ab581f65af9441edab1f9ac626acba6", [:mix], [{:makeup, "~> 1.2", [hex: :makeup, repo: "hexpm", optional: false]}, {:rustler, "~> 0.37.1", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.8.2", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "5b624a434d9665786b9a352a5f3502b6c98e1996ede9936b20035ec140daef70"},
4143
"merkle_map": {:hex, :merkle_map, "0.2.2", "f36ff730cca1f2658e317a3c73406f50bbf5ac8aff54cf837d7ca2069a6e251c", [:mix], [], "hexpm", "383107f0503f230ac9175e0631647c424efd027e89ea65ab5ea12eeb54257aaf"},
4244
"mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"},
4345
"mint": {:hex, :mint, "1.9.0", "d6f534c2a3e98b2a8cc749b4796eb77e9e3af79a76f96e4c74035a827de0d318", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1 or ~> 0.2.0 or ~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "007154c7d8c43916aed3c93afd1f11aebbaa9c5ff4b7ba55ebe0d17ee0296042"},
@@ -57,6 +59,7 @@
5759
"protobuf": {:hex, :protobuf, "0.17.0", "39e24e43c9648e148feba16ed51100b5b2028ea900b55460377b0476f6e10613", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "ca6c91f6f63e2c147b47f03eefd10b80538aa6fc55ff4b12b795efb786b0152f"},
5860
"ranch": {:hex, :ranch, "2.2.0", "25528f82bc8d7c6152c57666ca99ec716510fe0925cb188172f41ce93117b1b0", [:make, :rebar3], [], "hexpm", "fa0b99a1780c80218a4197a59ea8d3bdae32fbff7e88527d7d8a4787eff4f8e7"},
5961
"req": {:hex, :req, "0.6.2", "b9b2024f35bcf60a92cc8cad2eaaf9d4e7aace463ff74be1afe5986830184413", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.21", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "cc9cd30a2ddd04989929b887178e1610c940456d962c6c3a52df6146d2eef9bf"},
62+
"rustler_precompiled": {:hex, :rustler_precompiled, "0.8.4", "700a878312acfac79fb6c572bb8b57f5aae05fe1cf70d34b5974850bbf2c05bf", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "3b33d99b540b15f142ba47944f7a163a25069f6d608783c321029bc1ffb09514"},
6063
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
6164
"stream_data": {:hex, :stream_data, "1.3.0", "bde37905530aff386dea1ddd86ecbf00e6642dc074ceffc10b7d4e41dfd6aac9", [:mix], [], "hexpm", "3cc552e286e817dca43c98044c706eec9318083a1480c52ae2688b08e2936e3c"},
6265
"telemetry": {:hex, :telemetry, "1.4.2", "a0cb522801dffb1c49fe6e30561badffc7b6d0e180db1300df759faa22062855", [:rebar3], [], "hexpm", "928f6495066506077862c0d1646609eed891a4326bee3126ba54b60af61febb1"},

0 commit comments

Comments
 (0)