Created
December 12, 2016 07:52
-
-
Save ar7hur/b17965fc72f58df95bbfa5aa1fd8af0d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn space-in-emph [[match g1 g2]] | |
(let [l (if (= " " g2) "" g2)] | |
(str "{" g1 l "}"))) | |
(defn footnote [[match g1]] | |
(if (#{"..." "…"} g1) | |
" \\el " | |
(str "\\footnote{" g1 "}"))) | |
(defn final-clean [txt] | |
(-> txt | |
(s/replace #"[ \t\xA0]+" " ") ; non breaking space | |
(s/replace #"\n +" "\n") | |
(s/replace #"[\r\n]{2,}" "\n\n") | |
(s/replace #"\[ " "[") | |
(s/replace #"\( " "(") | |
(s/replace #" \]" "]") | |
(s/replace #" \)" ")") | |
(s/replace #"\} ," "},") | |
(s/replace #" »" "\"") | |
(s/replace #"« " "\"") | |
(s/replace #" *\[([^\]]+)\]" footnote) ; [] -> footnote | |
(s/replace #"\" ?\\emph\{([^\}]+)\} ?\"" "\"$1\"") ; double quote | |
(s/replace #"\{ *([^\}]+)([^\}])\}" space-in-emph) | |
(s/replace #" ([,\.])" "$1") ; "hi , alex -> hi, alex" | |
(s/replace #" - " " \u2014 ") | |
(s/replace #"%" "\\%"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment