pointtools

Simple point utilities to hold text presentations.
git clone git://r-36.net/pointtools
Log | Files | Refs | LICENSE

md2point (772B)


      1 #!/bin/sh
      2 
      3 mkfilename() {
      4 	printf "%.4d-%s" "$1" "$2" | tr '# :.()/' '_'
      5 	printf ".txt"
      6 }
      7 
      8 mkunderline() {
      9 	i=$1
     10 	while [ $i -gt 1 ];
     11 	do
     12 		printf "%s" "$2"
     13 		i=$(($i - 1))
     14 	done
     15 }
     16 
     17 fname=""
     18 snum=0
     19 
     20 while IFS='
     21 ' read -r line;
     22 do
     23 	case $line in
     24 	\#\#*)
     25 		titlelen="$(utf8expr length "$line")"
     26 		title="$(utf8expr substr "$line" 3 $titlelen)"
     27 		fname="$(mkfilename "$snum" "$title")"
     28 		snum=$((snum + 1))
     29 		printf "\n  %s\n  %s\n\n" \
     30 			"$title" "$(mkunderline $titlelen "=")" > $fname
     31 		;;
     32 	\#pause)
     33 		fname="$(mkfilename "$snum" "$title")"
     34 		cat "$(mkfilename "$((snum - 1))" "$title")" >> $fname
     35 		snum=$((snum + 1))
     36 		;;
     37 	*)
     38 		[ -n "$fname" ] && \
     39 			printf " %s\n" "$line" \
     40 			| sed 's,	,        ,' \
     41 			| sed 's,^\([[:blank:]]*\)\*,\1o,' >> $fname
     42 		;;
     43 	esac
     44 done
     45