ansible-later: 2.0.22 -> 2.0.23
[NixPkgs.git] / maintainers / scripts / mdize-module.sh
blobe2d2e5467aa9803938cd5a5ba7e6ae287adb83ab
1 #! /usr/bin/env nix-shell
2 #! nix-shell -I nixpkgs=. -i bash -p delta jq perl
4 set -euo pipefail
5 shopt -s inherit_errexit
7 cat <<'EOF'
8 This script attempts to automatically convert option descriptions from
9 DocBook syntax to markdown. Naturally this process is incomplete and
10 imperfect, so any changes generated by this script MUST be reviewed.
12 Possible problems include: incorrectly replaced tags, badly formatted
13 markdown, DocBook tags this script doesn't recognize remaining in the
14 output and crashing the docs build, incorrect escaping of markdown
15 metacharacters, incorrect unescaping of XML entities—and the list goes on.
17 Always review the generated changes!
19 Some known limitations:
20 - Does not transform literalDocBook items
21 - Replacements can occur in non-option code, such as string literals
24 EOF
28 build-options-json() {
29 nix-build --no-out-link --expr '
30 let
31 sys = import ./nixos/default.nix {
32 configuration = {};
36 sys.config.system.build.manual.optionsJSON
43 git diff --quiet || {
44 echo "Worktree is dirty. Please stash or commit first."
45 exit 1
48 echo "Building options.json ..."
49 old_options=$(build-options-json)
51 echo "Applying replacements ..."
52 perl -pi -e '
53 BEGIN {
54 undef $/;
57 s,<literal>([^`]*?)</literal>,`$1`,smg;
58 s,<replaceable>([^»]*?)</replaceable>,«$1»,smg;
59 s,<filename>([^`]*?)</filename>,{file}`$1`,smg;
60 s,<option>([^`]*?)</option>,{option}`$1`,smg;
61 s,<code>([^`]*?)</code>,`$1`,smg;
62 s,<command>([^`]*?)</command>,{command}`$1`,smg;
63 s,<link xlink:href="(.+?)" ?/>,<$1>,smg;
64 s,<link xlink:href="(.+?)">(.*?)</link>,[$2]($1),smg;
65 s,<package>([^`]*?)</package>,`$1`,smg;
66 s,<emphasis>([^*]*?)</emphasis>,*$1*,smg;
67 s,<citerefentry>\s*
68 <refentrytitle>\s*(.*?)\s*</refentrytitle>\s*
69 <manvolnum>\s*(.*?)\s*</manvolnum>\s*
70 </citerefentry>,{manpage}`$1($2)`,smgx;
71 s,^( +description =),\1 lib.mdDoc,smg;
72 ' "$@"
74 echo "Building options.json again ..."
75 new_options=$(build-options-json)
78 ! cmp -s {$old_options,$new_options}/share/doc/nixos/options.json && {
79 diff -U10 \
80 <(jq . <$old_options/share/doc/nixos/options.json) \
81 <(jq . <$new_options/share/doc/nixos/options.json) \
82 | delta