{-# LANGUAGE OverloadedStrings #-}-- Copyright (C) 2010-2011 John Millikin <jmillikin@gmail.com>-- 2011 Dirk Laurie <dirk.laurie@gmail.com>---- This program is free software: you can redistribute it and/or modify-- it under the terms of the GNU General Public License as published by-- the Free Software Foundation, either version 3 of the License, or-- any later version.---- This program is distributed in the hope that it will be useful,-- but WITHOUT ANY WARRANTY; without even the implied warranty of-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-- GNU General Public License for more details.---- You should have received a copy of the GNU General Public License-- along with this program. If not, see <http://www.gnu.org/licenses/>.moduleAnansi.Loom.Markdown(loomMarkdown)whereimportControl.Monad(forM_)importControl.Monad.Reader(asks)importControl.Monad.Writer(tell)importData.ByteString(ByteString)importData.Monoid(mconcat)importqualifiedData.TextimportData.Text(Text)importData.Text.Encoding(encodeUtf8)importAnansi.Types-- | Generate Markdown. Modified from LaTeX.hs.loomMarkdown::LoomloomMarkdown=mapM_putBlock.documentBlockswhereputBlockb=casebofBlockTexttext->tell(encodeUtf8text)BlockFilepathcontent->dotell"\n> **\xC2\xBB "tell=<<escapeTextpathtell"**\n\n"putContentcontenttell"\n"BlockDefinenamecontent->dotell"\n> **\xC2\xAB"tell=<<escapeTextnametell"\xC2\xBB**\n\n"putContentcontenttell"\n"putContentcs=forM_cs$\c->casecofContentText_text->dotell"> "escapeCodetext>>=telltell"\n"ContentMacro_indentname->formatMacroindentname>>=tellformatMacroindentname=doescIndent<-escapeCodeindentescName<-escapeCodenamereturn(mconcat["> ",escIndent,"\xC2\xAB",escName,"\xC2\xBB\n"])escapeCode::Text->LoomMByteStringescapeCodetext=dotabSize<-asksloomOptionTabSizereturn$encodeUtf8$Data.Text.concatMap(\c->casecof'\t'->Data.Text.replicate(fromIntegertabSize)" "_->Data.Text.singletonc)textescapeText::Text->LoomMByteStringescapeTexttext=dotabSize<-asksloomOptionTabSizereturn$encodeUtf8$Data.Text.concatMap(\c->casecof'\t'->Data.Text.replicate(fromIntegertabSize)" "'\\'->"\\\\"'_'->"\\_"'*'->"\\*"'['->"\\["']'->"\\]"'`'->"\\`"'&'->"&amp;"_->Data.Text.singletonc)text