Skip to content

Instantly share code, notes, and snippets.

@allisonking
Created January 28, 2020 03:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allisonking/473330bf38cca2c512ac7484d96298d1 to your computer and use it in GitHub Desktop.
Save allisonking/473330bf38cca2c512ac7484d96298d1 to your computer and use it in GitHub Desktop.
Various scripts for working with markdown chapters

These are a few scripts I've used to help me out while writing a novel where each chapter is a markdown file. A repo might have a format like this:

book/
├── part-1
│   ├── chapter-01.md
│   ├── chapter-02.md
│   ├── chapter-03.md
│   ├── chapter-04.md
│   ├── chapter-05.md
│   └── chapter-06.md
└── part-2
    ├── chapter-07.md
    ├── chapter-08.md
    └── chapter-09.md

More details in this blog post.

#!/bin/bash
pandoc -H options.sty \ # add a style file to pandoc to format how our pdf looks
--toc \ # add table of contents
--metadata title="My Shiny New Book And Me" \ # metadata for epub title
--metadata creator="Chip Skylark" \ # metadata for author name
`find ../book-1 -type f -name 'chapter*.md' | sort` \ # find all markdown chapter files and sort them
-o ../book-1/book1.epub # output as an epub file
#!/bin/bash
pandoc -H options.sty \ # add a style file to pandoc to format how our pdf looks
--toc \ # tell pandoc to also generate a table of contents
`find book -type f -name 'chapter*.md' | sort` \ # find all markdown chapter files and sort them
-o book/book.pdf # output as a pdf
\usepackage{setspace}
\onehalfspacing # 1.5 spacing
\usepackage[vmargin=1in,hmargin=1in]{geometry} # margin size
\setlength{\parindent}{2em} # size of paragraph indent
\usepackage{indentfirst} # indent the first paragraph of every section
\usepackage{palatino} # use the Palatino font
#!/bin/bash
# read in a file path where markdown files are
FPATH=$1
# if no path given, use the current directory
if [ -z "$1" ]
then
FPATH='.'
fi
# find all markdown files, sort them, and get the word count of each one
find "$FPATH" -type f -name 'chapter*.md' | sort | xargs wc -w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment