summary refs log tree commit diff
path: root/nixos/doc/manual/md-to-db.sh
diff options
context:
space:
mode:
authorRyan Mulligan <ryan@ryantm.com>2020-12-22 21:56:46 -0800
committerJonathan Ringer <jonringer@users.noreply.github.com>2021-05-22 18:14:49 -0700
commit6c14851943fe55da9df88a502d1e1fe2271d9666 (patch)
tree3508d24c58f5a5402650446aaae471f2243c24b4 /nixos/doc/manual/md-to-db.sh
parentff1ded3e2047268a55d3443459cda01cf9242e45 (diff)
downloadnixpkgs-6c14851943fe55da9df88a502d1e1fe2271d9666.tar
nixpkgs-6c14851943fe55da9df88a502d1e1fe2271d9666.tar.gz
nixpkgs-6c14851943fe55da9df88a502d1e1fe2271d9666.tar.bz2
nixpkgs-6c14851943fe55da9df88a502d1e1fe2271d9666.tar.lz
nixpkgs-6c14851943fe55da9df88a502d1e1fe2271d9666.tar.xz
nixpkgs-6c14851943fe55da9df88a502d1e1fe2271d9666.tar.zst
nixpkgs-6c14851943fe55da9df88a502d1e1fe2271d9666.zip
nixos/doc: add md-to-db.sh, convert "Building Your Own NixOS CD" to CommonMark
Diffstat (limited to 'nixos/doc/manual/md-to-db.sh')
-rwxr-xr-xnixos/doc/manual/md-to-db.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/nixos/doc/manual/md-to-db.sh b/nixos/doc/manual/md-to-db.sh
new file mode 100755
index 00000000000..a29d981d457
--- /dev/null
+++ b/nixos/doc/manual/md-to-db.sh
@@ -0,0 +1,32 @@
+#! /usr/bin/env nix-shell
+#! nix-shell -I nixpkgs=channel:nixpkgs-unstable -i bash -p pandoc
+
+# This script is temporarily needed while we transition the manual to
+# CommonMark. It converts the .md files in the regular manual folder
+# into DocBook files in the from_md folder.
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+pushd $DIR
+
+OUT="$DIR/from_md"
+mapfile -t MD_FILES < <(find . -type f -regex '.*\.md$')
+
+for mf in ${MD_FILES[*]}; do
+  mkdir -p $(dirname "$OUT/$mf")
+  if [ "${mf: -11}" == ".section.md" ]; then
+    pandoc "$mf" -t docbook \
+      --extract-media=media \
+      -f markdown+smart \
+    | cat  > "$OUT/${mf%".section.md"}.section.xml"
+  fi
+
+  if [ "${mf: -11}" == ".chapter.md" ]; then
+    pandoc "$mf" -t docbook \
+      --top-level-division=chapter \
+      --extract-media=media \
+      -f markdown+smart \
+    | cat  > "$OUT/${mf%".chapter.md"}.chapter.xml"
+  fi
+done
+
+popd