Created
June 22, 2013 16:30
-
-
Save siscia/5841486 to your computer and use it in GitHub Desktop.
for blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns asciidoc-to-markdown.core | |
(:use [clojure.tools.cli :only [cli]])) | |
(def titles-regex | |
(sorted-map-by #(> (count %1) (count %2)) | |
"###### $1" #"====== +([^ \t\n\r\f\v].*?)" | |
"##### $1" #"===== +([^ \t\n\r\f\v].*?)" | |
"#### $1" #"==== +([^ \t\n\r\f\v].*?)" | |
"### $1" #"=== +([^ \t\n\r\f\v].*?)" | |
"## $1" #"== +([^ \t\n\r\f\v].*?)" | |
"# $1" #"= +([^ \t\n\r\f\v].*?)")) | |
(defn title [text] | |
(reduce (fn [text regex] | |
(clojure.string/replace text (get titles-regex regex) regex)) | |
text | |
(keys titles-regex))) | |
(defn source [text & jekyll] | |
(clojure.string/replace text | |
#"\[source,(.*?)\]\n----\n(.*?\n+.*?)\n----" | |
(if (first jekyll) | |
"{% highlight $1 %}\n$2\n{% endhighlight %}" | |
"``` $1\n$2\n```"))) | |
(defn inline-code [text] | |
(clojure.string/replace text | |
#"\+(.*?)\+" | |
"`$1`")) | |
(defn -main [input output & args] | |
(let [[args opts banner] | |
(cli args | |
["-h" "--help" "Show help" :default false] | |
["-j" "--jekyll" "Make jekyll ready markdown file" :flag true :default true])] | |
(println args opts banner) | |
(println (:jekyll args)) | |
(spit output (-> input | |
slurp | |
(source (:jekyll args)) | |
title | |
inline-code)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment