Skip to content

Instantly share code, notes, and snippets.

@JamesKim2998
Created February 17, 2017 10:02
Show Gist options
  • Save JamesKim2998/4fec41376f41c226ae59abb33dfcbcaf to your computer and use it in GitHub Desktop.
Save JamesKim2998/4fec41376f41c226ae59abb33dfcbcaf to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ ! -d "$1" ]; then
echo Usage: $(basename "$0") BOOKDIR \> trpl.md
echo Then: pandoc -S -o trpl.epub trpl.md
exit 1
fi
cat "$1/README.md"
echo
grep '^ *\*' "$1/SUMMARY.md" |
sed 's/^\*/main/g' |
sed 's/^ \+\*/sub/g' |
sed 's/\[.*\](\(.*\))/\1/g' |
while read level filename; do
cat "$1/$filename" |
if [ "$level" = "main" ]; then
sed 's/^\(#\+ \)/#\1/g' |
sed 's/^% /# /g'
else
sed 's/^\(#\+ \)/##\1/g' |
sed 's/^% /## /g'
fi |
sed 's/^\(```rust\),.*$/\1/g'
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment