#!/bin/sh

# This script makes a txt version of the wiki that's ready to be read by a
# text-to-speech. Use this if you're blind or just want an audio book.

echo "making..."
echo "" > lrs_wiki_tts.txt

for f in *.md; do
  echo $f
  cat $f | tr "\n" "\r" | \
    sed "s/\r### /\rheading 3: /g" | \
    sed "s/\r## /\rheading 2: /g" | \
    sed "s/\(\r\\|^\)# /\1heading 1: /g" | \
    sed "s/\r *- /\rlist item: /g" | \
    sed "s/\*\*\([^*]*\)\*\*/\1/g" | \
    sed "s/\*\([^*]*\)\*/\1/g" | \
    sed "s/\[\([^]]*\)\]([^)]*)/\1/g" | \
    sed "s/\r *\([0-9]\+\)\. /\ritem \1: /g" | \
    sed "s/{\([^{]*\)}/; COMMENT -- \1 -- END OF COMMENT;/g" | \
    sed "s/\([^\`]\)\`\([^\`]\)/\"\1\2\"/g" | \
    sed "s/\r\`\`\`[^\`]*\r\`\`\`/\rcode segment/g" | \
    sed "s/\(\r|[^\r]*\)\+\r[^|]/\rtable\r\r/g" | \
    tr "\r" "\n" >> lrs_wiki_tts.txt
done

echo "done"
