1 #! /usr/bin/env nix-shell
2 #! nix-shell -I nixpkgs=. -i bash -p pandoc
4 # This script is temporarily needed while we transition the manual to
5 # CommonMark. It converts DocBook files into our CommonMark flavour.
10 while [ "$#" -gt 0 ]; do
22 echo "WARNING: This is an experimental script and might not preserve all formatting." > /dev
/stderr
23 echo "Please report any issues you discover." > /dev
/stderr
30 DIR
="$( cd "$
( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
32 # NOTE: Keep in sync with Nixpkgs manual (/doc/Makefile).
33 # TODO: Remove raw-attribute when we can get rid of DocBook altogether.
34 pandoc_commonmark_enabled_extensions
=+attributes
+fenced_divs
+footnotes
+bracketed_spans
+definition_lists
+pipe_tables
+raw_attribute
35 targetLang
="commonmark${pandoc_commonmark_enabled_extensions}+smart"
41 # - diagram-generator.lua (we do not support that in NixOS manual to limit dependencies)
42 # - media extraction (was only required for diagram generator)
43 # - myst-reader/roles.lua (only relevant for MyST → DocBook)
44 # - link-manpages.lua (links should only be added to display output)
45 # - docbook-writer/rst-roles.lua (only relevant for → DocBook)
46 # - docbook-writer/labelless-link-is-xref.lua (only relevant for → DocBook)
47 "--lua-filter=$DIR/../../doc/build-aux/pandoc-filters/docbook-reader/citerefentry-to-rst-role.lua"
48 "--lua-filter=$DIR/../../doc/build-aux/pandoc-filters/myst-writer/roles.lua"
49 "--lua-filter=$DIR/doc/unknown-code-language.lua"
56 for file in "${files[@]}"; do
57 if [[ ! -f "$file" ]]; then
58 echo "db-to-md.sh: $file does not exist" > /dev
/stderr
61 rootElement
=$
(xmllint
--xpath 'name(//*)' "$file")
63 if [[ $rootElement = chapter
]]; then
64 extension
=".chapter.$outExtension"
65 elif [[ $rootElement = section
]]; then
66 extension
=".section.$outExtension"
68 echo "db-to-md.sh: $file contains an unsupported root element $rootElement" > /dev
/stderr
72 outFile
="${file%".section.xml"}"
73 outFile
="${outFile%".chapter.xml"}"
74 outFile
="${outFile%".xml"}$extension"
76 $DIR/doc
/escape-code-markup.py
"$file" "$temp1"
78 echo "Converted $file to $temp1" > /dev
/stderr
81 $DIR/doc
/replace-xrefs-by-empty-links.py
"$temp1" "$temp2"
83 echo "Converted $temp1 to $temp2" > /dev
/stderr
85 pandoc
"$temp2" -o "$outFile" "${pandoc_flags[@]}"
86 echo "Converted $file to $outFile" > /dev
/stderr