-
Notifications
You must be signed in to change notification settings - Fork 131
Description
We're using markdown-code-runner in Nixpkgs for the docs already and would like to use it with treefmt
as well. Upstream PR is here: NixOS/nixpkgs#427460. This works, but ofc it would be nicer if this was integrated in treefmt-nix.
Since mdcr is essentially a wrapper around other formatters, it would be nice to be able to link the existing formatter configurations to markdown code blocks for a specific block.
For example, instead of setting up another nixfmt
of nix
blocks, it would be better to re-use the existing settings.formatters.nixfmt
for it etc.
Has there been any previous work / ideas on either setting up "nested / injected languages" * or re-using these definitions in other formatters?
* "nix in markdown" here, but it generalizes to many other cases, too, I think - for example "bash in nix"...
Some ideas:
- One way to do it would be to put the language specification on each of the existing formatters. So for example in
nixfmt.nix
, I'd addmarkdown-language = "nix";
or so. This is bad, because it (a) forces exactly the same settings in*.nix
files andnix
blocks inside*.md
files - but it could be the case that the latter should use different settings (not that it would matter fornixfmt
at all...). Also, this could lead to conflicts, if multiple modules define the same language. - Another way would be to have a mapping in the settings for
markdown-code-runner
, where I can say:Ideally the options would be set up in a way, that would allow me to do something likelanguages = { nix = { ... }; json = { ... }; };
nix = config.settings.formatter.nixfmt
or so, thus making it easy to copy exactly the same settings, but also allowing to modify them.