#!/bin/bash # Updates/generates the table of contents in markdown (wiki) files # The first argument specifies the file(s) to process. If not given, all modified .md files in current folder are processed # Keeps the files with Windows EOLs if run from MSYS (since markdown-toc changes EOL in some lines) # # Uses markdown-toc module inside Node.js - https://github.com/jonschlinkert/markdown-toc, assumes that the module is # installed globally, which is done by # npm install -g markdown-toc # Installation of Node.js including npm is straightforward from https://nodejs.org/en/download/ # # The TOC is added after the line or replaces the existing TOC between this line and files=${1:-`git diff --name-only | grep \.md$`} for f in $files; do #echo $f markdown-toc -i $f if [ $OSTYPE == "msys" ]; then unix2dos $f fi done