#!/bin/bash set -e #dummy=0 [[ -z $1 ]] && echo markdown file? && exit 1 md=$1 # allow MD links in the title title=`grep '^# ' $md | head -1 | sed -r 's/^# +//; s/<[^>]*>//g; s/\[//g; s/\]//g; s/\([^\)]*\)//g'` [[ -z $title ]] && echo NO TITLE FOUND FOR $md # check there's at least one h2 to-be there grep -E '^## ' $md >/dev/null && h2_there=1 || true if (( h2_there == 1 )); then # make sure the first title is ## not ###* grep ^## $md | head -1 | grep -E '^## ' >/dev/null # todo - also eventually make sure there's no text apart from links before first h2 fi ## what happens when there is a double quote in some title?... #(( dummy == 1 )) && echo -e "$md: $title" && exit 1 cat < $title
EOF # there is no h2 title and we don't want to center everything # todo - as a result, h1 is also left-aligned, which is not what we wanted (( h2_there != 1 )) && cat < EOF #-f links,image,html,smarty,strikethrough,toc,autolink,footnote #awk '($0 ~ /https?:\/\/[^ ]+/) {printf("%s\n", $0, text); next } { text = $0 }' $md \ # deal badly indended doc (tabs are handled right, so convert to tabs) # holy fuck that breaks ascii charts # s@ @\t@g; # deal with web page anchors on-the-fly # id= doesnt allow spaces # todo - sed 's/&/&/g' against those ## only #sed -r 's@^## (.+)@## \1\1@' $md | \ # awk ' # /id="[^"]*\s[^"]*"/ && !in_target { # in_target=1 # } # in_target { # gsub(/ /, "_") # } # /<\/[^>]*>/ && in_target { in_target=0 } # { print } # ' | \ # make the title and menu always centered # while the underlying page starting with the first h2 goes left-aligned (within centered block) markdown -f autolink,fencedcode $md | \ sed -r ' s%
%
%g;
	s%
%
%g; 0,/

/{s@

([^<]+)

@\
\

\1

\ @}; ' # intentionally do not close the two divs, this is done with nginx sub # so it also handles directory listings # why do we keep footer over there? because we can use $uri and other variables # that is particularly useful for generating html and css validation links cat < EOF