1 #! /usr/bin/env nix-shell
2 #! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/21.11 -i bash -p pandoc
4 # This script is temporarily needed while we transition the manual to
5 # CommonMark. It converts the .md files in the regular manual folder
6 # into DocBook files in the from_md folder.
8 DIR
="$( cd "$
( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
11 # NOTE: Keep in sync with Nixpkgs manual (/doc/Makefile).
12 # TODO: Remove raw-attribute when we can get rid of DocBook altogether.
13 pandoc_commonmark_enabled_extensions
=+attributes
+fenced_divs
+footnotes
+bracketed_spans
+definition_lists
+pipe_tables
+raw_attribute
16 # - diagram-generator.lua (we do not support that in NixOS manual to limit dependencies)
17 # - media extraction (was only required for diagram generator)
18 # - docbook-reader/citerefentry-to-rst-role.lua (only relevant for DocBook → MarkDown/rST/MyST)
19 "--lua-filter=$DIR/../../../doc/build-aux/pandoc-filters/myst-reader/roles.lua"
20 "--lua-filter=$DIR/../../../doc/build-aux/pandoc-filters/link-unix-man-references.lua"
21 "--lua-filter=$DIR/../../../doc/build-aux/pandoc-filters/docbook-writer/rst-roles.lua"
22 "--lua-filter=$DIR/../../../doc/build-aux/pandoc-filters/docbook-writer/html-elements.lua"
23 "--lua-filter=$DIR/../../../doc/build-aux/pandoc-filters/docbook-writer/labelless-link-is-xref.lua"
24 -f "commonmark${pandoc_commonmark_enabled_extensions}+smart"
29 mapfile
-t MD_FILES
< <(find .
-type f
-regex '.*\.md$')
31 for mf
in ${MD_FILES[*]}; do
32 if [ "${mf: -11}" == ".section.md" ]; then
33 mkdir
-p "$(dirname "$OUT/$mf")"
34 OUTFILE
="$OUT/${mf%".section.md"}.section.xml"
35 pandoc
"$mf" "${pandoc_flags[@]}" \
37 grep -q -m 1 "xi:include" "$OUTFILE" && sed -i 's|xmlns:xlink="http://www.w3.org/1999/xlink"| xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude"|' "$OUTFILE"
40 if [ "${mf: -11}" == ".chapter.md" ]; then
41 mkdir
-p "$(dirname "$OUT/$mf")"
42 OUTFILE
="$OUT/${mf%".chapter.md"}.chapter.xml"
43 pandoc
"$mf" "${pandoc_flags[@]}" \
44 --top-level-division=chapter \
46 grep -q -m 1 "xi:include" "$OUTFILE" && sed -i 's|xmlns:xlink="http://www.w3.org/1999/xlink"| xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude"|' "$OUTFILE"