File tree Expand file tree Collapse file tree 3 files changed +97
-0
lines changed Expand file tree Collapse file tree 3 files changed +97
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ # shell script to convert textile content to markdown using sed, awk and pandoc.
4+ # copy this file and tomd_pre.awk and tomd_post.awk into your local jekyll project folder
5+ # then `chmod +x tomd` and invoke with `tomd [_posts] [_old_posts]`
6+ # remember to keep a backup of everything, and USE THIS AT YOUR OWN RISK.
7+
8+ set -e
9+ set -o pipefail
10+
11+ # make sure the following exist
12+ echo " checking for sed, awk, and pandoc"
13+ which sed | sed ' 1 q'
14+ awk --version | sed ' 1 q'
15+ pandoc -v | sed ' 1 q'
16+
17+ # script dir
18+ DIR=` dirname $0 `
19+
20+ # posts dir
21+ if [ $1 ] ; then
22+ POSTSDIR=$1
23+ else
24+ POSTSDIR=_posts
25+ fi
26+
27+ # archive dir
28+ if [ $2 ] ; then
29+ OLDDIR=$2
30+ else
31+ OLDDIR=_old_posts
32+ fi
33+
34+ echo " looking for .textile files in $POSTSDIR moving them to $OLDDIR "
35+ mkdir -p -v $OLDDIR
36+
37+ # find all the textile files
38+ find $POSTSDIR -name \* .textile | sed ' s/\.textile$//' > tomd_files.txt
39+
40+ while read foo; do
41+
42+ # save YAML header
43+ sed -n ' 1,/^---/ p' $foo .textile > tomd_head.txt
44+
45+ # textile (minus header) | tomd_pre | pandoc | tomd_post
46+ sed ' 1,/^---/ d' $foo .textile | awk -f $DIR /tomd_pre.awk | pandoc -B tomd_head.txt -f textile -t markdown_github | awk -f $DIR /tomd_post.awk > $foo .md
47+
48+ # archive
49+ mv $foo .textile $OLDDIR
50+
51+ done < tomd_files.txt
52+
53+ echo ` wc -l < tomd_files.txt` textile files converted
54+
55+ # clean up
56+ rm -f tomd_files.txt tomd_head.txt tomd-include-* .txt
Original file line number Diff line number Diff line change 1+ # awk post-processor - after pandoc
2+ # re-creates !include sections extracted by tomd_pre.awk
3+
4+ /^ !include tomd-include- / {
5+ while ((getline line < $2 ) > 0 ) { print line }
6+ close ($2 );
7+ next ;
8+ }
9+
10+ { print }
Original file line number Diff line number Diff line change 1+ # tomd awk pre-processor (before pandoc)
2+ # redirects {% highlight %} sections to numbered files
3+ # and passes through <notextile> blocks
4+
5+ BEGIN { nme = " tomd-include-" ; cnt = 0 ; }
6+
7+ /{% + highlight / {
8+ including = " yes" ;
9+ incfile = (nme cnt++ " .txt" );
10+ print (" !include " incfile);
11+ }
12+
13+ /{% + endhighlight / {
14+ including = " " ;
15+ print > incfile;
16+ next ;
17+ }
18+
19+ /^ <notextile> / {
20+ including = " yes" ;
21+ incfile = (nme cnt++ " .txt" );
22+ print (" !include " incfile);
23+ next ;
24+ }
25+
26+ /^ <\/ notextile> / {
27+ including = " " ;
28+ next ;
29+ }
30+
31+ { if (including) { print > incfile } else { print }}
You can’t perform that action at this time.
0 commit comments