Skip to content

Add markdown-code-runner #387

@wolfgangwalther

Description

@wolfgangwalther

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 add markdown-language = "nix"; or so. This is bad, because it (a) forces exactly the same settings in *.nix files and nix blocks inside *.md files - but it could be the case that the latter should use different settings (not that it would matter for nixfmt 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:
    languages = {
      nix = { ... };
      json = { ... };
    };
    Ideally the options would be set up in a way, that would allow me to do something like nix = config.settings.formatter.nixfmt or so, thus making it easy to copy exactly the same settings, but also allowing to modify them.

cc @drupol @Mic92 @MattSturgeon

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions