{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Writers.Textile ( writeTextile ) where
import Control.Monad (zipWithM, liftM)
import Control.Monad.State.Strict ( StateT, gets, modify, evalStateT )
import Data.Char (isSpace)
import Data.Text (Text)
import qualified Data.Text as T
import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
import Text.Pandoc.Definition
import Text.Pandoc.ImageSize
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.DocLayout (render, literal)
import Text.Pandoc.Shared
import Text.Pandoc.Templates (renderTemplate)
import Text.Pandoc.Writers.Shared
import Text.Pandoc.XML (escapeStringForXML)
data WriterState = WriterState {
WriterState -> [Text]
stNotes :: [Text]
, WriterState -> [Char]
stListLevel :: [Char]
, WriterState -> Maybe Int
stStartNum :: Maybe Int
, WriterState -> Bool
stUseTags :: Bool
}
type TW = StateT WriterState
writeTextile :: PandocMonad m => WriterOptions -> Pandoc -> m Text
writeTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> m Text
writeTextile WriterOptions
opts Pandoc
document =
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> TW m Text
pandocToTextile WriterOptions
opts Pandoc
document)
WriterState { stNotes :: [Text]
stNotes = [],
stListLevel :: [Char]
stListLevel = [],
stStartNum :: Maybe Int
stStartNum = forall a. Maybe a
Nothing,
stUseTags :: Bool
stUseTags = Bool
False }
pandocToTextile :: PandocMonad m
=> WriterOptions -> Pandoc -> TW m Text
pandocToTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> TW m Text
pandocToTextile WriterOptions
opts (Pandoc Meta
meta [Block]
blocks) = do
Context Text
metadata <- forall (m :: * -> *) a.
(Monad m, TemplateTarget a) =>
WriterOptions
-> ([Block] -> m (Doc a))
-> ([Inline] -> m (Doc a))
-> Meta
-> m (Context a)
metaToContext WriterOptions
opts
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. HasChars a => a -> Doc a
literal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts)
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. HasChars a => a -> Doc a
literal forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts) Meta
meta
Text
body <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
blocks
Text
notes <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets forall a b. (a -> b) -> a -> b
$ [Text] -> Text
T.unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterState -> [Text]
stNotes
let main :: Text
main = Text
body forall a. Semigroup a => a -> a -> a
<> if Text -> Bool
T.null Text
notes then Text
"" else Text
"\n\n" forall a. Semigroup a => a -> a -> a
<> Text
notes
let context :: Context Text
context = forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"body" Text
main Context Text
metadata
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
case WriterOptions -> Maybe (Template Text)
writerTemplate WriterOptions
opts of
Maybe (Template Text)
Nothing -> Text
main
Just Template Text
tpl -> forall a. HasChars a => Maybe Int -> Doc a -> a
render forall a. Maybe a
Nothing forall a b. (a -> b) -> a -> b
$ forall a b.
(TemplateTarget a, ToContext a b) =>
Template a -> b -> Doc a
renderTemplate Template Text
tpl Context Text
context
withUseTags :: PandocMonad m => TW m a -> TW m a
withUseTags :: forall (m :: * -> *) a. PandocMonad m => TW m a -> TW m a
withUseTags TW m a
action = do
Bool
oldUseTags <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Bool
stUseTags
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
s -> WriterState
s { stUseTags :: Bool
stUseTags = Bool
True }
a
result <- TW m a
action
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
s -> WriterState
s { stUseTags :: Bool
stUseTags = Bool
oldUseTags }
forall (m :: * -> *) a. Monad m => a -> m a
return a
result
escapeCharForTextile :: Char -> Text
escapeCharForTextile :: Char -> Text
escapeCharForTextile Char
x = case Char
x of
Char
'&' -> Text
"&"
Char
'<' -> Text
"<"
Char
'>' -> Text
">"
Char
'"' -> Text
"""
Char
'*' -> Text
"*"
Char
'_' -> Text
"_"
Char
'@' -> Text
"@"
Char
'+' -> Text
"+"
Char
'-' -> Text
"-"
Char
'|' -> Text
"|"
Char
'\x2014' -> Text
" -- "
Char
'\x2013' -> Text
" - "
Char
'\x2019' -> Text
"'"
Char
'\x2026' -> Text
"..."
Char
c -> Char -> Text
T.singleton Char
c
escapeTextForTextile :: Text -> Text
escapeTextForTextile :: Text -> Text
escapeTextForTextile = (Char -> Text) -> Text -> Text
T.concatMap Char -> Text
escapeCharForTextile
blockToTextile :: PandocMonad m
=> WriterOptions
-> Block
-> TW m Text
blockToTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> TW m Text
blockToTextile WriterOptions
opts (Div Attr
attr [Block]
bs) = do
let startTag :: Text
startTag = forall a. HasChars a => Maybe Int -> Doc a -> a
render forall a. Maybe a
Nothing forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Attr -> Doc a
tagWithAttrs Text
"div" Attr
attr
let endTag :: Text
endTag = Text
"</div>"
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
bs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
startTag forall a. Semigroup a => a -> a -> a
<> Text
"\n\n" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"\n\n" forall a. Semigroup a => a -> a -> a
<> Text
endTag forall a. Semigroup a => a -> a -> a
<> Text
"\n"
blockToTextile WriterOptions
opts (Plain [Inline]
inlines) =
forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
inlines
blockToTextile WriterOptions
opts (Para [Inline]
inlines) = do
Bool
useTags <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Bool
stUseTags
[Char]
listLevel <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> [Char]
stListLevel
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
inlines
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
useTags
then Text
"<p>" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"</p>"
else Text
contents forall a. Semigroup a => a -> a -> a
<> if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
listLevel then Text
"\n" else Text
""
blockToTextile WriterOptions
opts (LineBlock [[Inline]]
lns) =
forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> TW m Text
blockToTextile WriterOptions
opts forall a b. (a -> b) -> a -> b
$ [[Inline]] -> Block
linesToPara [[Inline]]
lns
blockToTextile WriterOptions
_ b :: Block
b@(RawBlock Format
f Text
str)
| Format
f forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"html" Bool -> Bool -> Bool
|| Format
f forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"textile" = forall (m :: * -> *) a. Monad m => a -> m a
return Text
str
| Bool
otherwise = do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Block -> LogMessage
BlockNotRendered Block
b
forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
blockToTextile WriterOptions
_ Block
HorizontalRule = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"<hr />\n"
blockToTextile WriterOptions
opts (Header Int
level (Text
ident,[Text]
classes,[(Text, Text)]
keyvals) [Inline]
inlines) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
inlines
let identAttr :: Text
identAttr = if Text -> Bool
T.null Text
ident then Text
"" else Text
"#" forall a. Semigroup a => a -> a -> a
<> Text
ident
let attribs :: Text
attribs = if Text -> Bool
T.null Text
identAttr Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
classes
then Text
""
else Text
"(" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.unwords [Text]
classes forall a. Semigroup a => a -> a -> a
<> Text
identAttr forall a. Semigroup a => a -> a -> a
<> Text
")"
let lang :: Text
lang = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (\Text
x -> Text
"[" forall a. Semigroup a => a -> a -> a
<> Text
x forall a. Semigroup a => a -> a -> a
<> Text
"]") forall a b. (a -> b) -> a -> b
$ forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"lang" [(Text, Text)]
keyvals
let styles :: Text
styles = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (\Text
x -> Text
"{" forall a. Semigroup a => a -> a -> a
<> Text
x forall a. Semigroup a => a -> a -> a
<> Text
"}") forall a b. (a -> b) -> a -> b
$ forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"style" [(Text, Text)]
keyvals
let prefix :: Text
prefix = Text
"h" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
tshow Int
level forall a. Semigroup a => a -> a -> a
<> Text
attribs forall a. Semigroup a => a -> a -> a
<> Text
styles forall a. Semigroup a => a -> a -> a
<> Text
lang forall a. Semigroup a => a -> a -> a
<> Text
". "
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
prefix forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"\n"
blockToTextile WriterOptions
_ (CodeBlock (Text
_,[Text]
classes,[(Text, Text)]
_) Text
str) | forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any ((Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isSpace) (Text -> [Text]
T.lines Text
str) =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<pre" forall a. Semigroup a => a -> a -> a
<> Text
classes' forall a. Semigroup a => a -> a -> a
<> Text
">\n" forall a. Semigroup a => a -> a -> a
<> Text -> Text
escapeStringForXML Text
str forall a. Semigroup a => a -> a -> a
<>
Text
"\n</pre>\n"
where classes' :: Text
classes' = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
classes
then Text
""
else Text
" class=\"" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.unwords [Text]
classes forall a. Semigroup a => a -> a -> a
<> Text
"\""
blockToTextile WriterOptions
_ (CodeBlock (Text
_,[Text]
classes,[(Text, Text)]
_) Text
str) =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"bc" forall a. Semigroup a => a -> a -> a
<> Text
classes' forall a. Semigroup a => a -> a -> a
<> Text
". " forall a. Semigroup a => a -> a -> a
<> Text
str forall a. Semigroup a => a -> a -> a
<> Text
"\n\n"
where classes' :: Text
classes' = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
classes
then Text
""
else Text
"(" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.unwords [Text]
classes forall a. Semigroup a => a -> a -> a
<> Text
")"
blockToTextile WriterOptions
opts (BlockQuote bs :: [Block]
bs@[Para [Inline]
_]) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
bs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"bq. " forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"\n\n"
blockToTextile WriterOptions
opts (BlockQuote [Block]
blocks) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
blocks
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<blockquote>\n\n" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"\n</blockquote>\n"
blockToTextile WriterOptions
opts (Table Attr
_ Caption
blkCapt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot)
= case Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> ([Inline], [Alignment], [Double], [[Block]], [[[Block]]])
toLegacyTable Caption
blkCapt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot of
([], [Alignment]
aligns, [Double]
widths, [[Block]]
headers, [[[Block]]]
rows') | forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
==Double
0) [Double]
widths -> do
[Text]
hs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((Text
"_. " forall a. Semigroup a => a -> a -> a
<>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
stripTrailingNewlines) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts) [[Block]]
headers
let cellsToRow :: [Text] -> Text
cellsToRow [Text]
cells = Text
"|" forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
"|" [Text]
cells forall a. Semigroup a => a -> a -> a
<> Text
"|"
let header :: Text
header = if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Block]]
headers then Text
"" else [Text] -> Text
cellsToRow [Text]
hs forall a. Semigroup a => a -> a -> a
<> Text
"\n"
let blocksToCell :: (Alignment, [Block]) -> StateT WriterState m Text
blocksToCell (Alignment
align, [Block]
bs) = do
Text
contents <- Text -> Text
stripTrailingNewlines forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
bs
let alignMarker :: Text
alignMarker = case Alignment
align of
Alignment
AlignLeft -> Text
"<. "
Alignment
AlignRight -> Text
">. "
Alignment
AlignCenter -> Text
"=. "
Alignment
AlignDefault -> Text
""
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
alignMarker forall a. Semigroup a => a -> a -> a
<> Text
contents
let rowToCells :: [[Block]] -> StateT WriterState m [Text]
rowToCells = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall {m :: * -> *}.
PandocMonad m =>
(Alignment, [Block]) -> StateT WriterState m Text
blocksToCell forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. [a] -> [b] -> [(a, b)]
zip [Alignment]
aligns
[[Text]]
bs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM [[Block]] -> StateT WriterState m [Text]
rowToCells [[[Block]]]
rows'
let body :: Text
body = [Text] -> Text
T.unlines forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map [Text] -> Text
cellsToRow [[Text]]
bs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
header forall a. Semigroup a => a -> a -> a
<> Text
body
([Inline]
capt, [Alignment]
aligns, [Double]
widths, [[Block]]
headers, [[[Block]]]
rows') -> do
let alignStrings :: [Text]
alignStrings = forall a b. (a -> b) -> [a] -> [b]
map Alignment -> Text
alignmentToText [Alignment]
aligns
Text
captionDoc <- if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inline]
capt
then forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
else do
Text
c <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
capt
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<caption>" forall a. Semigroup a => a -> a -> a
<> Text
c forall a. Semigroup a => a -> a -> a
<> Text
"</caption>\n"
let percent :: a -> Text
percent a
w = forall a. Show a => a -> Text
tshow (forall a b. (RealFrac a, Integral b) => a -> b
truncate (a
100forall a. Num a => a -> a -> a
*a
w) :: Integer) forall a. Semigroup a => a -> a -> a
<> Text
"%"
let coltags :: Text
coltags = if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
== Double
0.0) [Double]
widths
then Text
""
else [Text] -> Text
T.unlines forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map
(\Double
w -> Text
"<col width=\"" forall a. Semigroup a => a -> a -> a
<> forall {a}. RealFrac a => a -> Text
percent Double
w forall a. Semigroup a => a -> a -> a
<> Text
"\" />") [Double]
widths
Text
head' <- if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Block]]
headers
then forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
else do
Text
hs <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Text] -> Int -> [[Block]] -> TW m Text
tableRowToTextile WriterOptions
opts [Text]
alignStrings Int
0 [[Block]]
headers
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<thead>\n" forall a. Semigroup a => a -> a -> a
<> Text
hs forall a. Semigroup a => a -> a -> a
<> Text
"\n</thead>\n"
[Text]
body' <- forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Text] -> Int -> [[Block]] -> TW m Text
tableRowToTextile WriterOptions
opts [Text]
alignStrings) [Int
1..] [[[Block]]]
rows'
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<table>\n" forall a. Semigroup a => a -> a -> a
<> Text
captionDoc forall a. Semigroup a => a -> a -> a
<> Text
coltags forall a. Semigroup a => a -> a -> a
<> Text
head' forall a. Semigroup a => a -> a -> a
<>
Text
"<tbody>\n" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.unlines [Text]
body' forall a. Semigroup a => a -> a -> a
<> Text
"</tbody>\n</table>\n"
blockToTextile WriterOptions
opts x :: Block
x@(BulletList [[Block]]
items) = do
Bool
oldUseTags <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Bool
stUseTags
let useTags :: Bool
useTags = Bool
oldUseTags Bool -> Bool -> Bool
|| Bool -> Bool
not (Block -> Bool
isSimpleList Block
x)
if Bool
useTags
then do
[Text]
contents <- forall (m :: * -> *) a. PandocMonad m => TW m a -> TW m a
withUseTags forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
listItemToTextile WriterOptions
opts) [[Block]]
items
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<ul>\n" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
vcat [Text]
contents forall a. Semigroup a => a -> a -> a
<> Text
"\n</ul>\n"
else do
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
s -> WriterState
s { stListLevel :: [Char]
stListLevel = WriterState -> [Char]
stListLevel WriterState
s forall a. Semigroup a => a -> a -> a
<> [Char]
"*" }
Int
level <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Int
length forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterState -> [Char]
stListLevel
[Text]
contents <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
listItemToTextile WriterOptions
opts) [[Block]]
items
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
s -> WriterState
s { stListLevel :: [Char]
stListLevel = forall a. [a] -> [a]
init (WriterState -> [Char]
stListLevel WriterState
s) }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Text] -> Text
vcat [Text]
contents forall a. Semigroup a => a -> a -> a
<> (if Int
level forall a. Ord a => a -> a -> Bool
> Int
1 then Text
"" else Text
"\n")
blockToTextile WriterOptions
opts x :: Block
x@(OrderedList attribs :: ListAttributes
attribs@(Int
start, ListNumberStyle
_, ListNumberDelim
_) [[Block]]
items) = do
Bool
oldUseTags <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Bool
stUseTags
let useTags :: Bool
useTags = Bool
oldUseTags Bool -> Bool -> Bool
|| Bool -> Bool
not (Block -> Bool
isSimpleList Block
x)
if Bool
useTags
then do
[Text]
contents <- forall (m :: * -> *) a. PandocMonad m => TW m a -> TW m a
withUseTags forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
listItemToTextile WriterOptions
opts) [[Block]]
items
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<ol" forall a. Semigroup a => a -> a -> a
<> ListAttributes -> Text
listAttribsToString ListAttributes
attribs forall a. Semigroup a => a -> a -> a
<> Text
">\n" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
vcat [Text]
contents forall a. Semigroup a => a -> a -> a
<>
Text
"\n</ol>\n"
else do
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
s -> WriterState
s { stListLevel :: [Char]
stListLevel = WriterState -> [Char]
stListLevel WriterState
s forall a. Semigroup a => a -> a -> a
<> [Char]
"#"
, stStartNum :: Maybe Int
stStartNum = if Int
start forall a. Ord a => a -> a -> Bool
> Int
1
then forall a. a -> Maybe a
Just Int
start
else forall a. Maybe a
Nothing }
Int
level <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Int
length forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterState -> [Char]
stListLevel
[Text]
contents <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
listItemToTextile WriterOptions
opts) [[Block]]
items
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
s -> WriterState
s { stListLevel :: [Char]
stListLevel = forall a. [a] -> [a]
init (WriterState -> [Char]
stListLevel WriterState
s),
stStartNum :: Maybe Int
stStartNum = forall a. Maybe a
Nothing }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Text] -> Text
vcat [Text]
contents forall a. Semigroup a => a -> a -> a
<> (if Int
level forall a. Ord a => a -> a -> Bool
> Int
1 then Text
"" else Text
"\n")
blockToTextile WriterOptions
opts (DefinitionList [([Inline], [[Block]])]
items) = do
[Text]
contents <- forall (m :: * -> *) a. PandocMonad m => TW m a -> TW m a
withUseTags forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> ([Inline], [[Block]]) -> TW m Text
definitionListItemToTextile WriterOptions
opts) [([Inline], [[Block]])]
items
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<dl>\n" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
vcat [Text]
contents forall a. Semigroup a => a -> a -> a
<> Text
"\n</dl>\n"
blockToTextile WriterOptions
opts (Figure Attr
attr (Caption Maybe [Inline]
_ [Block]
caption) [Block]
body) = do
let startTag :: Text
startTag = forall a. HasChars a => Maybe Int -> Doc a -> a
render forall a. Maybe a
Nothing forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Attr -> Doc a
tagWithAttrs Text
"figure" Attr
attr
let endTag :: Text
endTag = Text
"</figure>"
let captionInlines :: [Inline]
captionInlines = [Block] -> [Inline]
blocksToInlines [Block]
caption
Text
captionMarkup <- if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inline]
captionInlines
then forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
else ((forall a. Semigroup a => a -> a -> a
<> Text
"\n\n</figcaption>\n\n") forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text
"<figcaption>\n\n" forall a. Semigroup a => a -> a -> a
<>)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts ([Block] -> [Inline]
blocksToInlines [Block]
caption)
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
body
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
startTag forall a. Semigroup a => a -> a -> a
<> Text
"\n\n" forall a. Semigroup a => a -> a -> a
<>
Text
captionMarkup forall a. Semigroup a => a -> a -> a
<>
Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"\n\n" forall a. Semigroup a => a -> a -> a
<> Text
endTag forall a. Semigroup a => a -> a -> a
<> Text
"\n"
listAttribsToString :: ListAttributes -> Text
listAttribsToString :: ListAttributes -> Text
listAttribsToString (Int
startnum, ListNumberStyle
numstyle, ListNumberDelim
_) =
let numstyle' :: Text
numstyle' = Text -> Text
camelCaseToHyphenated forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> Text
tshow ListNumberStyle
numstyle
in (if Int
startnum forall a. Eq a => a -> a -> Bool
/= Int
1
then Text
" start=\"" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
tshow Int
startnum forall a. Semigroup a => a -> a -> a
<> Text
"\""
else Text
"") forall a. Semigroup a => a -> a -> a
<>
(if ListNumberStyle
numstyle forall a. Eq a => a -> a -> Bool
/= ListNumberStyle
DefaultStyle
then Text
" style=\"list-style-type: " forall a. Semigroup a => a -> a -> a
<> Text
numstyle' forall a. Semigroup a => a -> a -> a
<> Text
";\""
else Text
"")
listItemToTextile :: PandocMonad m
=> WriterOptions -> [Block] -> TW m Text
listItemToTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
listItemToTextile WriterOptions
opts [Block]
items = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
items
Bool
useTags <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Bool
stUseTags
if Bool
useTags
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<li>" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"</li>"
else do
[Char]
marker <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> [Char]
stListLevel
Maybe Int
mbstart <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Maybe Int
stStartNum
case Maybe Int
mbstart of
Just Int
n -> do
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
s -> WriterState
s{ stStartNum :: Maybe Int
stStartNum = forall a. Maybe a
Nothing }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack [Char]
marker forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
tshow Int
n forall a. Semigroup a => a -> a -> a
<> Text
" " forall a. Semigroup a => a -> a -> a
<> Text
contents
Maybe Int
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack [Char]
marker forall a. Semigroup a => a -> a -> a
<> Text
" " forall a. Semigroup a => a -> a -> a
<> Text
contents
definitionListItemToTextile :: PandocMonad m
=> WriterOptions
-> ([Inline],[[Block]])
-> TW m Text
definitionListItemToTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> ([Inline], [[Block]]) -> TW m Text
definitionListItemToTextile WriterOptions
opts ([Inline]
label, [[Block]]
items) = do
Text
labelText <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
label
[Text]
contents <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts) [[Block]]
items
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<dt>" forall a. Semigroup a => a -> a -> a
<> Text
labelText forall a. Semigroup a => a -> a -> a
<> Text
"</dt>\n" forall a. Semigroup a => a -> a -> a
<>
Text -> [Text] -> Text
T.intercalate Text
"\n" (forall a b. (a -> b) -> [a] -> [b]
map (\Text
d -> Text
"<dd>" forall a. Semigroup a => a -> a -> a
<> Text
d forall a. Semigroup a => a -> a -> a
<> Text
"</dd>") [Text]
contents)
isSimpleList :: Block -> Bool
isSimpleList :: Block -> Bool
isSimpleList Block
x =
case Block
x of
BulletList [[Block]]
items -> forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all [Block] -> Bool
isSimpleListItem [[Block]]
items
OrderedList (Int
_, ListNumberStyle
sty, ListNumberDelim
_) [[Block]]
items -> forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all [Block] -> Bool
isSimpleListItem [[Block]]
items Bool -> Bool -> Bool
&&
ListNumberStyle
sty forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [ListNumberStyle
DefaultStyle, ListNumberStyle
Decimal]
Block
_ -> Bool
False
isSimpleListItem :: [Block] -> Bool
isSimpleListItem :: [Block] -> Bool
isSimpleListItem [] = Bool
True
isSimpleListItem [Block
x] =
case Block
x of
Plain [Inline]
_ -> Bool
True
Para [Inline]
_ -> Bool
True
BulletList [[Block]]
_ -> Block -> Bool
isSimpleList Block
x
OrderedList ListAttributes
_ [[Block]]
_ -> Block -> Bool
isSimpleList Block
x
Block
_ -> Bool
False
isSimpleListItem [Block
x, Block
y] | Block -> Bool
isPlainOrPara Block
x =
case Block
y of
BulletList [[Block]]
_ -> Block -> Bool
isSimpleList Block
y
OrderedList ListAttributes
_ [[Block]]
_ -> Block -> Bool
isSimpleList Block
y
Block
_ -> Bool
False
isSimpleListItem [Block]
_ = Bool
False
isPlainOrPara :: Block -> Bool
isPlainOrPara :: Block -> Bool
isPlainOrPara (Plain [Inline]
_) = Bool
True
isPlainOrPara (Para [Inline]
_) = Bool
True
isPlainOrPara Block
_ = Bool
False
vcat :: [Text] -> Text
vcat :: [Text] -> Text
vcat = Text -> [Text] -> Text
T.intercalate Text
"\n"
tableRowToTextile :: PandocMonad m
=> WriterOptions
-> [Text]
-> Int
-> [[Block]]
-> TW m Text
tableRowToTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Text] -> Int -> [[Block]] -> TW m Text
tableRowToTextile WriterOptions
opts [Text]
alignStrings Int
rownum [[Block]]
cols' = do
let celltype :: Text
celltype = if Int
rownum forall a. Eq a => a -> a -> Bool
== Int
0 then Text
"th" else Text
"td"
let rowclass :: Text
rowclass = case Int
rownum of
Int
0 -> Text
"header"
Int
x | Int
x forall a. Integral a => a -> a -> a
`rem` Int
2 forall a. Eq a => a -> a -> Bool
== Int
1 -> Text
"odd"
Int
_ -> Text
"even"
[Text]
cols'' <- forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM
(\Text
alignment [Block]
item -> forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Text -> Text -> [Block] -> TW m Text
tableItemToTextile WriterOptions
opts Text
celltype Text
alignment [Block]
item)
[Text]
alignStrings [[Block]]
cols'
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<tr class=\"" forall a. Semigroup a => a -> a -> a
<> Text
rowclass forall a. Semigroup a => a -> a -> a
<> Text
"\">\n" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.unlines [Text]
cols'' forall a. Semigroup a => a -> a -> a
<> Text
"</tr>"
alignmentToText :: Alignment -> Text
alignmentToText :: Alignment -> Text
alignmentToText Alignment
alignment = case Alignment
alignment of
Alignment
AlignLeft -> Text
"left"
Alignment
AlignRight -> Text
"right"
Alignment
AlignCenter -> Text
"center"
Alignment
AlignDefault -> Text
"left"
tableItemToTextile :: PandocMonad m
=> WriterOptions
-> Text
-> Text
-> [Block]
-> TW m Text
tableItemToTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Text -> Text -> [Block] -> TW m Text
tableItemToTextile WriterOptions
opts Text
celltype Text
align' [Block]
item = do
let mkcell :: Text -> Text
mkcell Text
x = Text
"<" forall a. Semigroup a => a -> a -> a
<> Text
celltype forall a. Semigroup a => a -> a -> a
<> Text
" align=\"" forall a. Semigroup a => a -> a -> a
<> Text
align' forall a. Semigroup a => a -> a -> a
<> Text
"\">" forall a. Semigroup a => a -> a -> a
<>
Text
x forall a. Semigroup a => a -> a -> a
<> Text
"</" forall a. Semigroup a => a -> a -> a
<> Text
celltype forall a. Semigroup a => a -> a -> a
<> Text
">"
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
item
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text
mkcell Text
contents
blockListToTextile :: PandocMonad m
=> WriterOptions
-> [Block]
-> TW m Text
blockListToTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
blocks =
[Text] -> Text
vcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> TW m Text
blockToTextile WriterOptions
opts) [Block]
blocks
inlineListToTextile :: PandocMonad m
=> WriterOptions -> [Inline] -> TW m Text
inlineListToTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst =
[Text] -> Text
T.concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Inline -> TW m Text
inlineToTextile WriterOptions
opts) [Inline]
lst
inlineToTextile :: PandocMonad m => WriterOptions -> Inline -> TW m Text
inlineToTextile :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Inline -> TW m Text
inlineToTextile WriterOptions
opts (Span Attr
_ [Inline]
lst) =
forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
inlineToTextile WriterOptions
opts (Emph [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'_') Text
contents
then Text
"<em>" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"</em>"
else Text
"_" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"_"
inlineToTextile WriterOptions
opts (Underline [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'+') Text
contents
then Text
"<u>" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"</u>"
else Text
"+" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"+"
inlineToTextile WriterOptions
opts (Strong [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'*') Text
contents
then Text
"<strong>" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"</strong>"
else Text
"*" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"*"
inlineToTextile WriterOptions
opts (Strikeout [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'-') Text
contents
then Text
"<del>" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"</del>"
else Text
"-" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"-"
inlineToTextile WriterOptions
opts (Superscript [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'^') Text
contents
then Text
"<sup>" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"</sup>"
else Text
"[^" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"^]"
inlineToTextile WriterOptions
opts (Subscript [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'~') Text
contents
then Text
"<sub>" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"</sub>"
else Text
"[~" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"~]"
inlineToTextile WriterOptions
opts (SmallCaps [Inline]
lst) = forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
inlineToTextile WriterOptions
opts (Quoted QuoteType
SingleQuote [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"'" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"'"
inlineToTextile WriterOptions
opts (Quoted QuoteType
DoubleQuote [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"\"" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"\""
inlineToTextile WriterOptions
opts (Cite [Citation]
_ [Inline]
lst) = forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
lst
inlineToTextile WriterOptions
_ (Code Attr
_ Text
str) =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
'@') Text
str
then Text
"<tt>" forall a. Semigroup a => a -> a -> a
<> Text -> Text
escapeStringForXML Text
str forall a. Semigroup a => a -> a -> a
<> Text
"</tt>"
else Text
"@" forall a. Semigroup a => a -> a -> a
<> Text
str forall a. Semigroup a => a -> a -> a
<> Text
"@"
inlineToTextile WriterOptions
_ (Str Text
str) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text
escapeTextForTextile Text
str
inlineToTextile WriterOptions
_ (Math MathType
_ Text
str) =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"<span class=\"math\">" forall a. Semigroup a => a -> a -> a
<> Text -> Text
escapeStringForXML Text
str forall a. Semigroup a => a -> a -> a
<> Text
"</span>"
inlineToTextile WriterOptions
opts il :: Inline
il@(RawInline Format
f Text
str)
| Format
f forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"html" Bool -> Bool -> Bool
|| Format
f forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"textile" = forall (m :: * -> *) a. Monad m => a -> m a
return Text
str
| (Format
f forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"latex" Bool -> Bool -> Bool
|| Format
f forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"tex") Bool -> Bool -> Bool
&&
forall a. HasSyntaxExtensions a => Extension -> a -> Bool
isEnabled Extension
Ext_raw_tex WriterOptions
opts = forall (m :: * -> *) a. Monad m => a -> m a
return Text
str
| Bool
otherwise = do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Inline -> LogMessage
InlineNotRendered Inline
il
forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
inlineToTextile WriterOptions
_ Inline
LineBreak = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"\n"
inlineToTextile WriterOptions
_ Inline
SoftBreak = forall (m :: * -> *) a. Monad m => a -> m a
return Text
" "
inlineToTextile WriterOptions
_ Inline
Space = forall (m :: * -> *) a. Monad m => a -> m a
return Text
" "
inlineToTextile WriterOptions
opts (Link (Text
_, [Text]
cls, [(Text, Text)]
_) [Inline]
txt (Text
src, Text
_)) = do
Text
label <- case [Inline]
txt of
[Code Attr
_ Text
s]
| Text
s forall a. Eq a => a -> a -> Bool
== Text
src -> forall (m :: * -> *) a. Monad m => a -> m a
return Text
"$"
[Str Text
s]
| Text
s forall a. Eq a => a -> a -> Bool
== Text
src -> forall (m :: * -> *) a. Monad m => a -> m a
return Text
"$"
[Inline]
_ -> forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
txt
let classes :: Text
classes = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
cls Bool -> Bool -> Bool
|| [Text]
cls forall a. Eq a => a -> a -> Bool
== [Text
"uri"] Bool -> Bool -> Bool
&& Text
label forall a. Eq a => a -> a -> Bool
== Text
"$"
then Text
""
else Text
"(" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.unwords [Text]
cls forall a. Semigroup a => a -> a -> a
<> Text
")"
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"\"" forall a. Semigroup a => a -> a -> a
<> Text
classes forall a. Semigroup a => a -> a -> a
<> Text
label forall a. Semigroup a => a -> a -> a
<> Text
"\":" forall a. Semigroup a => a -> a -> a
<> Text
src
inlineToTextile WriterOptions
opts (Image attr :: Attr
attr@(Text
_, [Text]
cls, [(Text, Text)]
_) [Inline]
alt (Text
source, Text
tit)) = do
Text
alt' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> TW m Text
inlineListToTextile WriterOptions
opts [Inline]
alt
let txt :: Text
txt = if Text -> Bool
T.null Text
tit
then if Text -> Bool
T.null Text
alt'
then Text
""
else Text
"(" forall a. Semigroup a => a -> a -> a
<> Text
alt' forall a. Semigroup a => a -> a -> a
<> Text
")"
else Text
"(" forall a. Semigroup a => a -> a -> a
<> Text
tit forall a. Semigroup a => a -> a -> a
<> Text
")"
classes :: Text
classes = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
cls
then Text
""
else Text
"(" forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.unwords [Text]
cls forall a. Semigroup a => a -> a -> a
<> Text
")"
showDim :: Direction -> Maybe Text
showDim Direction
dir = let toCss :: Text -> Maybe Text
toCss Text
str = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> Text
tshow Direction
dir forall a. Semigroup a => a -> a -> a
<> Text
":" forall a. Semigroup a => a -> a -> a
<> Text
str forall a. Semigroup a => a -> a -> a
<> Text
";"
in case Direction -> Attr -> Maybe Dimension
dimension Direction
dir Attr
attr of
Just (Percent Double
a) -> Text -> Maybe Text
toCss forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> Text
tshow (Double -> Dimension
Percent Double
a)
Just Dimension
dim -> Text -> Maybe Text
toCss forall a b. (a -> b) -> a -> b
$ WriterOptions -> Dimension -> Text
showInPixel WriterOptions
opts Dimension
dim forall a. Semigroup a => a -> a -> a
<> Text
"px"
Maybe Dimension
Nothing -> forall a. Maybe a
Nothing
styles :: Text
styles = case (Direction -> Maybe Text
showDim Direction
Width, Direction -> Maybe Text
showDim Direction
Height) of
(Just Text
w, Just Text
h) -> Text
"{" forall a. Semigroup a => a -> a -> a
<> Text
w forall a. Semigroup a => a -> a -> a
<> Text
h forall a. Semigroup a => a -> a -> a
<> Text
"}"
(Just Text
w, Maybe Text
Nothing) -> Text
"{" forall a. Semigroup a => a -> a -> a
<> Text
w forall a. Semigroup a => a -> a -> a
<> Text
"height:auto;}"
(Maybe Text
Nothing, Just Text
h) -> Text
"{" forall a. Semigroup a => a -> a -> a
<> Text
"width:auto;" forall a. Semigroup a => a -> a -> a
<> Text
h forall a. Semigroup a => a -> a -> a
<> Text
"}"
(Maybe Text
Nothing, Maybe Text
Nothing) -> Text
""
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"!" forall a. Semigroup a => a -> a -> a
<> Text
classes forall a. Semigroup a => a -> a -> a
<> Text
styles forall a. Semigroup a => a -> a -> a
<> Text
source forall a. Semigroup a => a -> a -> a
<> Text
txt forall a. Semigroup a => a -> a -> a
<> Text
"!"
inlineToTextile WriterOptions
opts (Note [Block]
contents) = do
[Text]
curNotes <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> [Text]
stNotes
let newnum :: Int
newnum = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
curNotes forall a. Num a => a -> a -> a
+ Int
1
Text
contents' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> TW m Text
blockListToTextile WriterOptions
opts [Block]
contents
let thisnote :: Text
thisnote = Text
"fn" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
tshow Int
newnum forall a. Semigroup a => a -> a -> a
<> Text
". " forall a. Semigroup a => a -> a -> a
<> Text
contents' forall a. Semigroup a => a -> a -> a
<> Text
"\n"
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
s -> WriterState
s { stNotes :: [Text]
stNotes = Text
thisnote forall a. a -> [a] -> [a]
: [Text]
curNotes }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"[" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
tshow Int
newnum forall a. Semigroup a => a -> a -> a
<> Text
"]"