1 #! /usr/bin/env nix-shell
2 #! nix-shell -I nixpkgs=. -i bash -p delta jq perl
5 shopt -s inherit_errexit
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
28 build-options-json
() {
29 nix-build
--no-out-link --expr '
31 sys = import ./nixos/default.nix {
36 sys.config.system.build.manual.optionsJSON
44 echo "Worktree is dirty. Please stash or commit first."
48 echo "Building options.json ..."
49 old_options
=$
(build-options-json
)
51 echo "Applying replacements ..."
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;
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;
74 echo "Building options.json again ..."
75 new_options
=$
(build-options-json
)
78 ! cmp -s {$old_options,$new_options}/share
/doc
/nixos
/options.json
&& {
80 <(jq .
<$old_options/share
/doc
/nixos
/options.json
) \
81 <(jq .
<$new_options/share
/doc
/nixos
/options.json
) \