Skip to content

Instantly share code, notes, and snippets.

@stefan2904
Created October 7, 2021 16:55
Show Gist options
  • Save stefan2904/b74b6141d3ebe89beaf095e62320f0b4 to your computer and use it in GitHub Desktop.
Save stefan2904/b74b6141d3ebe89beaf095e62320f0b4 to your computer and use it in GitHub Desktop.
Convert directory of markdown files into orgmode heading
#!/bin/bash
# if [[ -d $PASSED ]]; then
# echo "$PASSED is a directory. Let's convert it."
# elif [[ -f $PASSED ]]; then
# echo "$PASSED is a file. Try md2org instead?"
# exit 2
# else
# echo "$PASSED is not valid?"
# exit 1
# fi
cd $1
for f in *.md; do
echo ""
filename="${f%%.*}"
echo "** $filename" | sed 's/_/ /'
pandoc --from markdown --to org "$f" \
| sed 's/\[toc\]//' \
| sed 's/\.\.\/\.\.\/_resources/file:\.\.\/_resources/' \
| sed 's/\.\.\/\.\.\/work/\.\.\/work/' \
| sed 's/\.\.\/journals/\.\.\/work\/journals/' \
| sed 's/^\* /*** /' \
| sed 's/^\*\* /*** /' \
| sed 's/ :/:/' \
| sed 's/☒/\[x\]/' \
| sed 's/☐/\[ \]/'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment