summaryrefslogtreecommitdiffstats
path: root/src/doc/book/tools/nostarch.sh
blob: eec0ac5ea16870892245b4b421c9cfadb97f6201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash

set -eu

cargo build --release

mkdir -p tmp
rm -rf tmp/*.md
rm -rf tmp/markdown

# Render the book as Markdown to include all the code listings
MDBOOK_OUTPUT__MARKDOWN=1 mdbook build -d tmp

# Get all the Markdown files
find tmp/markdown -name "${1:-\"\"}*.md" -print0 | \
# Extract just the filename so we can reuse it easily.
xargs -0 basename | \
# Remove all links followed by `<!-- ignore -->``, then
# Change all remaining links from Markdown to italicized inline text.
while IFS= read -r filename; do
  < "tmp/markdown/$filename" ./target/release/remove_links \
    | ./target/release/link2print \
    | ./target/release/remove_markup \
    | ./target/release/remove_hidden_lines > "tmp/$filename"
done
# Concatenate the files into the `nostarch` dir.
./target/release/concat_chapters tmp nostarch