Skip to content
Browse files

init

1 parent 3fa0217 commit 795bb8b03a4a61a92c855173a54148315d62214e @jldec committed
Showing with 153 additions and 1 deletion.
  1. +22 −0 LICENSE.md
  2. +35 −1 README.md
  3. +55 −0 tomd
  4. +10 −0 tomd_post.awk
  5. +31 −0 tomd_pre.awk
View
22 LICENSE.md
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2015-2016 Jürgen Leschner -- github.com/jldec
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
36 README.md
@@ -1,2 +1,36 @@
# tomd
-Shell script for upgrading textile posts to markdown.
+
+### Automated conversion from .textile to .md with pandoc
+
+Users with many textile files in their Jekyll Pages site should consider using [pandoc](http://pandoc.org), a utility for converting between different markup formats. E.g. for converting from textile to markdown:
+
+```sh
+pandoc --wrap=preserve -f textile -t markdown_github <foo.textile >foo.md
+```
+
+##### limitations
+Unfortunately pandoc may change content in unwanted ways when it encounters:
+
+- YAML frontmatter at the top of .textile files
+- `{% highlight %}` blocks
+- `<notextile>` blocks
+
+To get around these limitations, this `tomd` shell script calls [awk](http://www.grymoire.com/Unix/Awk.html) and [sed](http://www.grymoire.com/Unix/Sed.html) to filter out those sections and then re-insert them after pandoc has converted the rest the file.
+
+##### to run `tomd`
+Copy `tomd` and the 2 awk scripts from this repo into your jekyll project folder (or a subdirectory if you prefer)
+
+Then invoke with `./tomd`.
+
+```
+$ ./tomd
+checking for sed, awk, and pandoc
+/usr/bin/sed
+awk version 20070501
+pandoc 1.16.0.2
+looking for .textile files in _posts moving them to _old_posts
+226 textile files converted
+```
+
+#### NOTE
+The `tomd` script has been run successfully on OSX on a couple of repos - YMMV.
View
55 tomd
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+# shell script to convert textile content to markdown using sed, awk and pandoc.
+# copy this file and tomd_pre.awk and tomd_post.awk into your local jekyll project folder
+# then `chmod +x tomd` and invoke with `tomd [_posts] [_old_posts]`
+# remember to keep a backup of everything, and USE THIS AT YOUR OWN RISK.
+
+set -e
+
+# make sure the following exist
+echo "checking for sed, awk, and pandoc"
+which sed | sed
+awk --version
+pandoc -v | sed '1 q'
+
+# script dir
+DIR=`dirname $0`
+
+# posts dir
+if [ $1 ] ; then
+ POSTSDIR=$1
+else
+ POSTSDIR=_posts
+fi
+
+# archive dir
+if [ $2 ] ; then
+ OLDDIR=$1
+else
+ OLDDIR=_old_posts
+fi
+
+echo "looking for .textile files in $POSTSDIR moving them to $OLDDIR"
+mkdir -p -v $OLDDIR
+
+# find all the textile files
+find $POSTSDIR -name \*.textile | sed 's/\.textile$//' >tomd_files.txt
+
+while read foo; do
+
+ # save YAML header
+ sed -n '1,/^---/ p' $foo.textile >tomd_head.txt
+
+ # textile (minus header) | tomd_pre | pandoc | tomd_post
+ 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
+
+ # archive
+ mv $foo.textile $OLDDIR
+
+done <tomd_files.txt
+
+echo `wc -l <tomd_files.txt` textile files converted
+
+# clean up
+rm -f tomd_files.txt tomd_head.txt tomd-include-*.txt
View
10 tomd_post.awk
@@ -0,0 +1,10 @@
+# awk post-processor - after pandoc
+# re-creates !include sections extracted by tomd_pre.awk
+
+/^!include tomd-include-/ {
+ while ((getline line < $2) > 0) { print line }
+ close($2);
+ next;
+}
+
+{ print }
View
31 tomd_pre.awk
@@ -0,0 +1,31 @@
+# tomd awk pre-processor (before pandoc)
+# redirects {% highlight %} sections to numbered files
+# and passes through <notextile> blocks
+
+BEGIN { nme = "tomd-include-"; cnt = 0; }
+
+/{% +highlight/ {
+ including = "yes";
+ incfile = (nme cnt++ ".txt");
+ print ("!include " incfile);
+}
+
+/{% +endhighlight/ {
+ including = "";
+ print >incfile;
+ next;
+}
+
+/^<notextile>/ {
+ including = "yes";
+ incfile = (nme cnt++ ".txt");
+ print ("!include " incfile);
+ next;
+}
+
+/^<\/notextile>/ {
+ including = "";
+ next;
+}
+
+{ if(including) { print >incfile } else { print }}

0 comments on commit 795bb8b

Please sign in to comment.
Something went wrong with that request. Please try again.