2010-04-10 12:38:07 -07:00
|
|
|
{-
|
|
|
|
Copyright (C) 2010 John MacFarlane <jgm@berkeley.edu>
|
|
|
|
|
|
|
|
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 2 of the License, or
|
|
|
|
(at your option) 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, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
-}
|
|
|
|
|
|
|
|
{- |
|
|
|
|
Module : Text.Pandoc.Writers.Textile
|
|
|
|
Copyright : Copyright (C) 2010 John MacFarlane
|
2012-07-26 22:32:53 -07:00
|
|
|
License : GNU GPL, version 2 or above
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
Maintainer : John MacFarlane <jgm@berkeley.edu>
|
|
|
|
Stability : alpha
|
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Conversion of 'Pandoc' documents to Textile markup.
|
|
|
|
|
|
|
|
Textile: <http://thresholdstate.com/articles/4312/the-textile-reference-manual>
|
|
|
|
-}
|
|
|
|
module Text.Pandoc.Writers.Textile ( writeTextile ) where
|
|
|
|
import Text.Pandoc.Definition
|
2012-07-26 22:59:56 -07:00
|
|
|
import Text.Pandoc.Options
|
2012-07-26 22:32:53 -07:00
|
|
|
import Text.Pandoc.Shared
|
2013-07-01 20:47:26 -07:00
|
|
|
import Text.Pandoc.Writers.Shared
|
2013-05-10 22:53:35 -07:00
|
|
|
import Text.Pandoc.Templates (renderTemplate')
|
2010-04-10 12:38:07 -07:00
|
|
|
import Text.Pandoc.XML ( escapeStringForXML )
|
|
|
|
import Data.List ( intercalate )
|
|
|
|
import Control.Monad.State
|
|
|
|
import Data.Char ( isSpace )
|
|
|
|
|
|
|
|
data WriterState = WriterState {
|
|
|
|
stNotes :: [String] -- Footnotes
|
|
|
|
, stListLevel :: [Char] -- String at beginning of list items, e.g. "**"
|
|
|
|
, stUseTags :: Bool -- True if we should use HTML tags because we're in a complex list
|
|
|
|
}
|
|
|
|
|
|
|
|
-- | Convert Pandoc to Textile.
|
|
|
|
writeTextile :: WriterOptions -> Pandoc -> String
|
2012-07-26 22:32:53 -07:00
|
|
|
writeTextile opts document =
|
|
|
|
evalState (pandocToTextile opts document)
|
|
|
|
(WriterState { stNotes = [], stListLevel = [], stUseTags = False })
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
-- | Return Textile representation of document.
|
|
|
|
pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
|
2013-05-10 22:53:35 -07:00
|
|
|
pandocToTextile opts (Pandoc meta blocks) = do
|
2013-07-01 20:47:26 -07:00
|
|
|
metadata <- metaToJSON opts (blockListToTextile opts)
|
|
|
|
(inlineListToTextile opts) meta
|
2010-04-10 12:38:07 -07:00
|
|
|
body <- blockListToTextile opts blocks
|
|
|
|
notes <- liftM (unlines . reverse . stNotes) get
|
|
|
|
let main = body ++ if null notes then "" else ("\n\n" ++ notes)
|
2013-06-29 22:14:01 -07:00
|
|
|
let context = defField "body" main metadata
|
2010-04-10 12:38:07 -07:00
|
|
|
if writerStandalone opts
|
2013-05-10 22:53:35 -07:00
|
|
|
then return $ renderTemplate' (writerTemplate opts) context
|
2010-04-10 12:38:07 -07:00
|
|
|
else return main
|
|
|
|
|
|
|
|
withUseTags :: State WriterState a -> State WriterState a
|
|
|
|
withUseTags action = do
|
|
|
|
oldUseTags <- liftM stUseTags get
|
|
|
|
modify $ \s -> s { stUseTags = True }
|
|
|
|
result <- action
|
|
|
|
modify $ \s -> s { stUseTags = oldUseTags }
|
|
|
|
return result
|
|
|
|
|
|
|
|
-- | Escape one character as needed for Textile.
|
|
|
|
escapeCharForTextile :: Char -> String
|
|
|
|
escapeCharForTextile x = case x of
|
2011-12-27 15:45:34 -08:00
|
|
|
'&' -> "&"
|
|
|
|
'<' -> "<"
|
|
|
|
'>' -> ">"
|
|
|
|
'"' -> """
|
|
|
|
'*' -> "*"
|
|
|
|
'_' -> "_"
|
|
|
|
'@' -> "@"
|
|
|
|
'|' -> "|"
|
|
|
|
'\x2014' -> " -- "
|
|
|
|
'\x2013' -> " - "
|
|
|
|
'\x2019' -> "'"
|
|
|
|
'\x2026' -> "..."
|
|
|
|
c -> [c]
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
-- | Escape string as needed for Textile.
|
|
|
|
escapeStringForTextile :: String -> String
|
|
|
|
escapeStringForTextile = concatMap escapeCharForTextile
|
|
|
|
|
2012-07-26 22:32:53 -07:00
|
|
|
-- | Convert Pandoc block element to Textile.
|
2010-04-10 12:38:07 -07:00
|
|
|
blockToTextile :: WriterOptions -- ^ Options
|
|
|
|
-> Block -- ^ Block element
|
2012-07-26 22:32:53 -07:00
|
|
|
-> State WriterState String
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
blockToTextile _ Null = return ""
|
|
|
|
|
2013-08-08 23:14:12 -07:00
|
|
|
blockToTextile opts (Div _ bs) =
|
|
|
|
blockListToTextile opts bs
|
|
|
|
|
2012-07-26 22:32:53 -07:00
|
|
|
blockToTextile opts (Plain inlines) =
|
2010-04-10 12:38:07 -07:00
|
|
|
inlineListToTextile opts inlines
|
|
|
|
|
2013-01-15 08:45:46 -08:00
|
|
|
-- title beginning with fig: indicates that the image is a figure
|
|
|
|
blockToTextile opts (Para [Image txt (src,'f':'i':'g':':':tit)]) = do
|
2010-04-10 12:38:07 -07:00
|
|
|
capt <- blockToTextile opts (Para txt)
|
|
|
|
im <- inlineToTextile opts (Image txt (src,tit))
|
|
|
|
return $ im ++ "\n" ++ capt
|
|
|
|
|
|
|
|
blockToTextile opts (Para inlines) = do
|
|
|
|
useTags <- liftM stUseTags get
|
|
|
|
listLevel <- liftM stListLevel get
|
|
|
|
contents <- inlineListToTextile opts inlines
|
|
|
|
return $ if useTags
|
2011-01-23 10:08:11 -08:00
|
|
|
then "<p>" ++ contents ++ "</p>"
|
2010-04-10 12:38:07 -07:00
|
|
|
else contents ++ if null listLevel then "\n" else ""
|
|
|
|
|
2013-08-10 17:23:51 -07:00
|
|
|
blockToTextile _ (RawBlock f str)
|
|
|
|
| f == Format "html" || f == Format "textile" = return str
|
|
|
|
| otherwise = return ""
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
blockToTextile _ HorizontalRule = return "<hr />\n"
|
|
|
|
|
2013-02-28 18:47:49 -08:00
|
|
|
blockToTextile opts (Header level (ident,classes,keyvals) inlines) = do
|
2010-04-10 12:38:07 -07:00
|
|
|
contents <- inlineListToTextile opts inlines
|
2013-02-28 18:47:49 -08:00
|
|
|
let identAttr = if null ident then "" else ('#':ident)
|
|
|
|
let attribs = if null identAttr && null classes
|
|
|
|
then ""
|
|
|
|
else "(" ++ unwords classes ++ identAttr ++ ")"
|
|
|
|
let lang = maybe "" (\x -> "[" ++ x ++ "]") $ lookup "lang" keyvals
|
|
|
|
let styles = maybe "" (\x -> "{" ++ x ++ "}") $ lookup "style" keyvals
|
|
|
|
let prefix = 'h' : show level ++ attribs ++ styles ++ lang ++ ". "
|
2010-04-10 12:38:07 -07:00
|
|
|
return $ prefix ++ contents ++ "\n"
|
|
|
|
|
2011-01-23 08:49:19 -08:00
|
|
|
blockToTextile _ (CodeBlock (_,classes,_) str) | any (all isSpace) (lines str) =
|
|
|
|
return $ "<pre" ++ classes' ++ ">\n" ++ escapeStringForXML str ++
|
|
|
|
"\n</pre>\n"
|
|
|
|
where classes' = if null classes
|
|
|
|
then ""
|
|
|
|
else " class=\"" ++ unwords classes ++ "\""
|
|
|
|
|
2010-04-10 12:38:07 -07:00
|
|
|
blockToTextile _ (CodeBlock (_,classes,_) str) =
|
2011-01-23 10:08:11 -08:00
|
|
|
return $ "bc" ++ classes' ++ ". " ++ str ++ "\n\n"
|
2010-04-10 12:38:07 -07:00
|
|
|
where classes' = if null classes
|
|
|
|
then ""
|
|
|
|
else "(" ++ unwords classes ++ ")"
|
|
|
|
|
|
|
|
blockToTextile opts (BlockQuote bs@[Para _]) = do
|
|
|
|
contents <- blockListToTextile opts bs
|
2011-01-23 10:08:11 -08:00
|
|
|
return $ "bq. " ++ contents ++ "\n\n"
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
blockToTextile opts (BlockQuote blocks) = do
|
|
|
|
contents <- blockListToTextile opts blocks
|
|
|
|
return $ "<blockquote>\n\n" ++ contents ++ "\n</blockquote>\n"
|
|
|
|
|
|
|
|
blockToTextile opts (Table [] aligns widths headers rows') |
|
|
|
|
all (==0) widths && all (`elem` [AlignLeft,AlignDefault]) aligns = do
|
|
|
|
hs <- mapM (liftM (("_. " ++) . stripTrailingNewlines) . blockListToTextile opts) headers
|
|
|
|
let cellsToRow cells = "|" ++ intercalate "|" cells ++ "|"
|
|
|
|
let header = if all null headers then "" else cellsToRow hs
|
|
|
|
let rowToCells = mapM (liftM stripTrailingNewlines . blockListToTextile opts)
|
|
|
|
bs <- mapM rowToCells rows'
|
|
|
|
let body = unlines $ map cellsToRow bs
|
|
|
|
return $ header ++ "\n" ++ body ++ "\n"
|
|
|
|
|
|
|
|
blockToTextile opts (Table capt aligns widths headers rows') = do
|
|
|
|
let alignStrings = map alignmentToString aligns
|
|
|
|
captionDoc <- if null capt
|
|
|
|
then return ""
|
|
|
|
else do
|
|
|
|
c <- inlineListToTextile opts capt
|
2011-01-23 10:08:11 -08:00
|
|
|
return $ "<caption>" ++ c ++ "</caption>\n"
|
2010-04-10 12:38:07 -07:00
|
|
|
let percent w = show (truncate (100*w) :: Integer) ++ "%"
|
|
|
|
let coltags = if all (== 0.0) widths
|
|
|
|
then ""
|
|
|
|
else unlines $ map
|
2011-01-23 10:08:11 -08:00
|
|
|
(\w -> "<col width=\"" ++ percent w ++ "\" />") widths
|
2010-04-10 12:38:07 -07:00
|
|
|
head' <- if all null headers
|
|
|
|
then return ""
|
|
|
|
else do
|
|
|
|
hs <- tableRowToTextile opts alignStrings 0 headers
|
2011-01-23 10:08:11 -08:00
|
|
|
return $ "<thead>\n" ++ hs ++ "\n</thead>\n"
|
2010-04-10 12:38:07 -07:00
|
|
|
body' <- zipWithM (tableRowToTextile opts alignStrings) [1..] rows'
|
2011-01-23 10:08:11 -08:00
|
|
|
return $ "<table>\n" ++ captionDoc ++ coltags ++ head' ++
|
|
|
|
"<tbody>\n" ++ unlines body' ++ "</tbody>\n</table>\n"
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
blockToTextile opts x@(BulletList items) = do
|
|
|
|
oldUseTags <- liftM stUseTags get
|
|
|
|
let useTags = oldUseTags || not (isSimpleList x)
|
|
|
|
if useTags
|
|
|
|
then do
|
|
|
|
contents <- withUseTags $ mapM (listItemToTextile opts) items
|
2011-01-23 10:08:11 -08:00
|
|
|
return $ "<ul>\n" ++ vcat contents ++ "\n</ul>\n"
|
2010-04-10 12:38:07 -07:00
|
|
|
else do
|
|
|
|
modify $ \s -> s { stListLevel = stListLevel s ++ "*" }
|
2010-11-27 10:44:35 -08:00
|
|
|
level <- get >>= return . length . stListLevel
|
2010-04-10 12:38:07 -07:00
|
|
|
contents <- mapM (listItemToTextile opts) items
|
|
|
|
modify $ \s -> s { stListLevel = init (stListLevel s) }
|
2010-11-27 10:44:35 -08:00
|
|
|
return $ vcat contents ++ (if level > 1 then "" else "\n")
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
blockToTextile opts x@(OrderedList attribs items) = do
|
|
|
|
oldUseTags <- liftM stUseTags get
|
|
|
|
let useTags = oldUseTags || not (isSimpleList x)
|
|
|
|
if useTags
|
|
|
|
then do
|
|
|
|
contents <- withUseTags $ mapM (listItemToTextile opts) items
|
2011-01-23 10:08:11 -08:00
|
|
|
return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++
|
|
|
|
"\n</ol>\n"
|
2010-04-10 12:38:07 -07:00
|
|
|
else do
|
|
|
|
modify $ \s -> s { stListLevel = stListLevel s ++ "#" }
|
2010-11-27 10:44:35 -08:00
|
|
|
level <- get >>= return . length . stListLevel
|
2010-04-10 12:38:07 -07:00
|
|
|
contents <- mapM (listItemToTextile opts) items
|
|
|
|
modify $ \s -> s { stListLevel = init (stListLevel s) }
|
2010-11-27 10:44:35 -08:00
|
|
|
return $ vcat contents ++ (if level > 1 then "" else "\n")
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
blockToTextile opts (DefinitionList items) = do
|
|
|
|
contents <- withUseTags $ mapM (definitionListItemToTextile opts) items
|
2011-01-23 10:08:11 -08:00
|
|
|
return $ "<dl>\n" ++ vcat contents ++ "\n</dl>\n"
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
-- Auxiliary functions for lists:
|
|
|
|
|
|
|
|
-- | Convert ordered list attributes to HTML attribute string
|
|
|
|
listAttribsToString :: ListAttributes -> String
|
|
|
|
listAttribsToString (startnum, numstyle, _) =
|
|
|
|
let numstyle' = camelCaseToHyphenated $ show numstyle
|
|
|
|
in (if startnum /= 1
|
|
|
|
then " start=\"" ++ show startnum ++ "\""
|
|
|
|
else "") ++
|
|
|
|
(if numstyle /= DefaultStyle
|
|
|
|
then " style=\"list-style-type: " ++ numstyle' ++ ";\""
|
|
|
|
else "")
|
|
|
|
|
|
|
|
-- | Convert bullet or ordered list item (list of blocks) to Textile.
|
|
|
|
listItemToTextile :: WriterOptions -> [Block] -> State WriterState String
|
|
|
|
listItemToTextile opts items = do
|
|
|
|
contents <- blockListToTextile opts items
|
|
|
|
useTags <- get >>= return . stUseTags
|
|
|
|
if useTags
|
2011-01-23 10:08:11 -08:00
|
|
|
then return $ "<li>" ++ contents ++ "</li>"
|
2010-04-10 12:38:07 -07:00
|
|
|
else do
|
|
|
|
marker <- get >>= return . stListLevel
|
|
|
|
return $ marker ++ " " ++ contents
|
|
|
|
|
|
|
|
-- | Convert definition list item (label, list of blocks) to Textile.
|
|
|
|
definitionListItemToTextile :: WriterOptions
|
2012-07-26 22:32:53 -07:00
|
|
|
-> ([Inline],[[Block]])
|
2010-04-10 12:38:07 -07:00
|
|
|
-> State WriterState String
|
|
|
|
definitionListItemToTextile opts (label, items) = do
|
|
|
|
labelText <- inlineListToTextile opts label
|
|
|
|
contents <- mapM (blockListToTextile opts) items
|
2011-01-23 10:08:11 -08:00
|
|
|
return $ "<dt>" ++ labelText ++ "</dt>\n" ++
|
|
|
|
(intercalate "\n" $ map (\d -> "<dd>" ++ d ++ "</dd>") contents)
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
-- | True if the list can be handled by simple wiki markup, False if HTML tags will be needed.
|
|
|
|
isSimpleList :: Block -> Bool
|
|
|
|
isSimpleList x =
|
|
|
|
case x of
|
|
|
|
BulletList items -> all isSimpleListItem items
|
|
|
|
OrderedList (num, sty, _) items -> all isSimpleListItem items &&
|
|
|
|
num == 1 && sty `elem` [DefaultStyle, Decimal]
|
|
|
|
_ -> False
|
|
|
|
|
|
|
|
-- | True if list item can be handled with the simple wiki syntax. False if
|
|
|
|
-- HTML tags will be needed.
|
|
|
|
isSimpleListItem :: [Block] -> Bool
|
|
|
|
isSimpleListItem [] = True
|
|
|
|
isSimpleListItem [x] =
|
|
|
|
case x of
|
|
|
|
Plain _ -> True
|
|
|
|
Para _ -> True
|
|
|
|
BulletList _ -> isSimpleList x
|
|
|
|
OrderedList _ _ -> isSimpleList x
|
|
|
|
_ -> False
|
|
|
|
isSimpleListItem [x, y] | isPlainOrPara x =
|
|
|
|
case y of
|
|
|
|
BulletList _ -> isSimpleList y
|
|
|
|
OrderedList _ _ -> isSimpleList y
|
|
|
|
_ -> False
|
|
|
|
isSimpleListItem _ = False
|
|
|
|
|
|
|
|
isPlainOrPara :: Block -> Bool
|
|
|
|
isPlainOrPara (Plain _) = True
|
|
|
|
isPlainOrPara (Para _) = True
|
|
|
|
isPlainOrPara _ = False
|
|
|
|
|
|
|
|
-- | Concatenates strings with line breaks between them.
|
|
|
|
vcat :: [String] -> String
|
|
|
|
vcat = intercalate "\n"
|
|
|
|
|
|
|
|
-- Auxiliary functions for tables. (TODO: these are common to HTML, MediaWiki,
|
|
|
|
-- and Textile writers, and should be abstracted out.)
|
|
|
|
|
|
|
|
tableRowToTextile :: WriterOptions
|
|
|
|
-> [String]
|
|
|
|
-> Int
|
|
|
|
-> [[Block]]
|
|
|
|
-> State WriterState String
|
|
|
|
tableRowToTextile opts alignStrings rownum cols' = do
|
|
|
|
let celltype = if rownum == 0 then "th" else "td"
|
|
|
|
let rowclass = case rownum of
|
|
|
|
0 -> "header"
|
|
|
|
x | x `rem` 2 == 1 -> "odd"
|
|
|
|
_ -> "even"
|
2012-07-26 22:32:53 -07:00
|
|
|
cols'' <- sequence $ zipWith
|
|
|
|
(\alignment item -> tableItemToTextile opts celltype alignment item)
|
2010-04-10 12:38:07 -07:00
|
|
|
alignStrings cols'
|
|
|
|
return $ "<tr class=\"" ++ rowclass ++ "\">\n" ++ unlines cols'' ++ "</tr>"
|
|
|
|
|
|
|
|
alignmentToString :: Alignment -> [Char]
|
|
|
|
alignmentToString alignment = case alignment of
|
|
|
|
AlignLeft -> "left"
|
|
|
|
AlignRight -> "right"
|
|
|
|
AlignCenter -> "center"
|
|
|
|
AlignDefault -> "left"
|
|
|
|
|
|
|
|
tableItemToTextile :: WriterOptions
|
|
|
|
-> String
|
|
|
|
-> String
|
|
|
|
-> [Block]
|
|
|
|
-> State WriterState String
|
|
|
|
tableItemToTextile opts celltype align' item = do
|
|
|
|
let mkcell x = "<" ++ celltype ++ " align=\"" ++ align' ++ "\">" ++
|
|
|
|
x ++ "</" ++ celltype ++ ">"
|
|
|
|
contents <- blockListToTextile opts item
|
|
|
|
return $ mkcell contents
|
|
|
|
|
|
|
|
-- | Convert list of Pandoc block elements to Textile.
|
|
|
|
blockListToTextile :: WriterOptions -- ^ Options
|
|
|
|
-> [Block] -- ^ List of block elements
|
2012-07-26 22:32:53 -07:00
|
|
|
-> State WriterState String
|
2010-04-10 12:38:07 -07:00
|
|
|
blockListToTextile opts blocks =
|
|
|
|
mapM (blockToTextile opts) blocks >>= return . vcat
|
|
|
|
|
|
|
|
-- | Convert list of Pandoc inline elements to Textile.
|
|
|
|
inlineListToTextile :: WriterOptions -> [Inline] -> State WriterState String
|
|
|
|
inlineListToTextile opts lst =
|
|
|
|
mapM (inlineToTextile opts) lst >>= return . concat
|
|
|
|
|
|
|
|
-- | Convert Pandoc inline element to Textile.
|
|
|
|
inlineToTextile :: WriterOptions -> Inline -> State WriterState String
|
|
|
|
|
2013-08-08 23:14:12 -07:00
|
|
|
inlineToTextile opts (Span _ lst) =
|
|
|
|
inlineListToTextile opts lst
|
|
|
|
|
2012-07-26 22:32:53 -07:00
|
|
|
inlineToTextile opts (Emph lst) = do
|
2010-04-10 12:38:07 -07:00
|
|
|
contents <- inlineListToTextile opts lst
|
|
|
|
return $ if '_' `elem` contents
|
|
|
|
then "<em>" ++ contents ++ "</em>"
|
2012-07-26 22:32:53 -07:00
|
|
|
else "_" ++ contents ++ "_"
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
inlineToTextile opts (Strong lst) = do
|
|
|
|
contents <- inlineListToTextile opts lst
|
|
|
|
return $ if '*' `elem` contents
|
|
|
|
then "<strong>" ++ contents ++ "</strong>"
|
|
|
|
else "*" ++ contents ++ "*"
|
|
|
|
|
|
|
|
inlineToTextile opts (Strikeout lst) = do
|
|
|
|
contents <- inlineListToTextile opts lst
|
|
|
|
return $ if '-' `elem` contents
|
|
|
|
then "<del>" ++ contents ++ "</del>"
|
|
|
|
else "-" ++ contents ++ "-"
|
|
|
|
|
|
|
|
inlineToTextile opts (Superscript lst) = do
|
|
|
|
contents <- inlineListToTextile opts lst
|
|
|
|
return $ if '^' `elem` contents
|
|
|
|
then "<sup>" ++ contents ++ "</sup>"
|
2010-11-27 10:44:58 -08:00
|
|
|
else "[^" ++ contents ++ "^]"
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
inlineToTextile opts (Subscript lst) = do
|
|
|
|
contents <- inlineListToTextile opts lst
|
|
|
|
return $ if '~' `elem` contents
|
|
|
|
then "<sub>" ++ contents ++ "</sub>"
|
2010-11-27 10:44:58 -08:00
|
|
|
else "[~" ++ contents ++ "~]"
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
inlineToTextile opts (SmallCaps lst) = inlineListToTextile opts lst
|
|
|
|
|
|
|
|
inlineToTextile opts (Quoted SingleQuote lst) = do
|
|
|
|
contents <- inlineListToTextile opts lst
|
|
|
|
return $ "'" ++ contents ++ "'"
|
|
|
|
|
|
|
|
inlineToTextile opts (Quoted DoubleQuote lst) = do
|
|
|
|
contents <- inlineListToTextile opts lst
|
|
|
|
return $ "\"" ++ contents ++ "\""
|
|
|
|
|
|
|
|
inlineToTextile opts (Cite _ lst) = inlineListToTextile opts lst
|
|
|
|
|
2011-01-26 20:44:25 -08:00
|
|
|
inlineToTextile _ (Code _ str) =
|
2010-04-10 12:38:07 -07:00
|
|
|
return $ if '@' `elem` str
|
|
|
|
then "<tt>" ++ escapeStringForXML str ++ "</tt>"
|
2012-07-26 22:32:53 -07:00
|
|
|
else "@" ++ str ++ "@"
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
inlineToTextile _ (Str str) = return $ escapeStringForTextile str
|
|
|
|
|
|
|
|
inlineToTextile _ (Math _ str) =
|
|
|
|
return $ "<span class=\"math\">" ++ escapeStringForXML str ++ "</math>"
|
|
|
|
|
2013-08-10 17:23:51 -07:00
|
|
|
inlineToTextile _ (RawInline f str)
|
|
|
|
| f == Format "html" || f == Format "textile" = return str
|
|
|
|
| otherwise = return ""
|
2010-04-10 12:38:07 -07:00
|
|
|
|
|
|
|
inlineToTextile _ (LineBreak) = return "\n"
|
|
|
|
|
|
|
|
inlineToTextile _ Space = return " "
|
|
|
|
|
|
|
|
inlineToTextile opts (Link txt (src, _)) = do
|
|
|
|
label <- case txt of
|
2012-11-06 16:05:17 -08:00
|
|
|
[Code _ s]
|
|
|
|
| s == src -> return "$"
|
|
|
|
[Str s]
|
|
|
|
| s == src -> return "$"
|
2011-01-26 20:44:25 -08:00
|
|
|
_ -> inlineListToTextile opts txt
|
2010-04-10 12:38:07 -07:00
|
|
|
return $ "\"" ++ label ++ "\":" ++ src
|
|
|
|
|
|
|
|
inlineToTextile opts (Image alt (source, tit)) = do
|
|
|
|
alt' <- inlineListToTextile opts alt
|
|
|
|
let txt = if null tit
|
|
|
|
then if null alt'
|
|
|
|
then ""
|
|
|
|
else "(" ++ alt' ++ ")"
|
|
|
|
else "(" ++ tit ++ ")"
|
|
|
|
return $ "!" ++ source ++ txt ++ "!"
|
|
|
|
|
|
|
|
inlineToTextile opts (Note contents) = do
|
|
|
|
curNotes <- liftM stNotes get
|
|
|
|
let newnum = length curNotes + 1
|
|
|
|
contents' <- blockListToTextile opts contents
|
|
|
|
let thisnote = "fn" ++ show newnum ++ ". " ++ contents' ++ "\n"
|
|
|
|
modify $ \s -> s { stNotes = thisnote : curNotes }
|
|
|
|
return $ "[" ++ show newnum ++ "]"
|
|
|
|
-- note - may not work for notes with multiple blocks
|