#!/usr/bin/env nu # SPDX-License-Identifier: AGPL-3.0-only # Copyright (c) 2026 MatrixFurry # Replace content between `` elements in a markdown file # # Allows you to directly edit the static parts of your markdown files without # using templates, while also being able to update the content that is # auto-generated by your CI scripts. # # This is useful, for example, to keep package lists and descriptions # up to date, and is used in this repo (see [`meta/update-readme.nu`](./meta/update-readme.nu))! export def main [ tag: string body: string path?: path ]: [ nothing -> nothing string -> string ] { let pipeline = $in != null let input = $in if not $pipeline and not ($path | path exists) { error make -u { msg: $"Could not open the specified file: `($path)`" } } if $pipeline { $input } else { open $path --raw } | str replace --regex $"\(?s\)\(?<=\).*?\(?=\)" $body | if $pipeline { $in } else { collect | save -f $path } }