{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Writers.XWiki ( writeXWiki ) where
import Control.Monad.Reader (ReaderT, asks, local, runReaderT)
import qualified Data.Set as Set
import qualified Data.Text as Text
import Data.Text (Text, intercalate, replace, split)
import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
import Text.Pandoc.Definition
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.Pandoc.Shared
import Text.Pandoc.URI
import Text.Pandoc.Writers.MediaWiki (highlightingLangs)
import Text.Pandoc.Templates (renderTemplate)
import Text.Pandoc.Writers.Shared (defField, metaToContext, toLegacyTable)
import Text.DocLayout (render, literal)
newtype WriterState = WriterState {
WriterState -> Text
listLevel :: Text
}
type XWikiReader m = ReaderT WriterState m
writeXWiki :: PandocMonad m => WriterOptions -> Pandoc -> m Text
writeXWiki :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> m Text
writeXWiki WriterOptions
opts (Pandoc Meta
meta [Block]
blocks) = do
let env :: WriterState
env = WriterState { listLevel :: Text
listLevel = Text
"" }
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
. Text -> Text
trimr) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\[Block]
bs -> forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (forall (m :: * -> *).
PandocMonad m =>
[Block] -> XWikiReader m Text
blockListToXWiki [Block]
bs) WriterState
env))
(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
. Text -> Text
trimr) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\[Inline]
is -> forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
is) WriterState
env))
Meta
meta
Text
body <- forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (forall (m :: * -> *).
PandocMonad m =>
[Block] -> XWikiReader m Text
blockListToXWiki [Block]
blocks) WriterState
env
let context :: Context Text
context = forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"body" Text
body
forall a b. (a -> b) -> a -> b
$ forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"toc" (WriterOptions -> Bool
writerTableOfContents WriterOptions
opts) 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
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
Maybe (Template Text)
Nothing -> Text
body
vcat :: [Text] -> Text
vcat :: [Text] -> Text
vcat = Text -> [Text] -> Text
intercalate Text
"\n"
genAnchor :: Text -> Text
genAnchor :: Text -> Text
genAnchor Text
id' = if Text -> Bool
Text.null Text
id'
then Text
""
else Text
"{{id name=\"" forall a. Semigroup a => a -> a -> a
<> Text
id' forall a. Semigroup a => a -> a -> a
<> Text
"\" /}}"
blockListToXWiki :: PandocMonad m => [Block] -> XWikiReader m Text
blockListToXWiki :: forall (m :: * -> *).
PandocMonad m =>
[Block] -> XWikiReader m Text
blockListToXWiki [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 => Block -> XWikiReader m Text
blockToXWiki [Block]
blocks
blockToXWiki :: PandocMonad m => Block -> XWikiReader m Text
blockToXWiki :: forall (m :: * -> *). PandocMonad m => Block -> XWikiReader m Text
blockToXWiki (Div (Text
id', [Text]
_, [(Text, Text)]
_) [Block]
blocks) = do
Text
content <- forall (m :: * -> *).
PandocMonad m =>
[Block] -> XWikiReader m Text
blockListToXWiki [Block]
blocks
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text
genAnchor Text
id' forall a. Semigroup a => a -> a -> a
<> Text
content
blockToXWiki (Plain [Inline]
inlines) =
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
inlines
blockToXWiki (Para [Inline]
inlines) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
inlines
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"\n"
blockToXWiki (LineBlock [[Inline]]
lns) =
forall (m :: * -> *). PandocMonad m => Block -> XWikiReader m Text
blockToXWiki forall a b. (a -> b) -> a -> b
$ [[Inline]] -> Block
linesToPara [[Inline]]
lns
blockToXWiki b :: Block
b@(RawBlock Format
f Text
str)
| Format
f forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"xwiki" = forall (m :: * -> *) a. Monad m => a -> m a
return Text
str
| Bool
otherwise = Text
"" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (Block -> LogMessage
BlockNotRendered Block
b)
blockToXWiki Block
HorizontalRule = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"\n----\n"
blockToXWiki (Header Int
level (Text
id', [Text]
_, [(Text, Text)]
_) [Inline]
inlines) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
inlines
let eqs :: Text
eqs = Int -> Text -> Text
Text.replicate Int
level Text
"="
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
eqs 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
" " forall a. Semigroup a => a -> a -> a
<> Text -> Text
genAnchor Text
id' forall a. Semigroup a => a -> a -> a
<> Text
eqs forall a. Semigroup a => a -> a -> a
<> Text
"\n"
blockToXWiki (CodeBlock (Text, [Text], [(Text, Text)])
attrs Text
str) = do
Text
contents <- forall (m :: * -> *). PandocMonad m => Inline -> XWikiReader m Text
inlineToXWiki ((Text, [Text], [(Text, Text)]) -> Text -> Inline
Code (Text, [Text], [(Text, Text)])
attrs (Text
"\n" forall a. Semigroup a => a -> a -> a
<> Text
str forall a. Semigroup a => a -> a -> a
<> Text
"\n"))
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"\n" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"\n"
blockToXWiki (BlockQuote [Block]
blocks) = do
Text
blockText <- forall (m :: * -> *).
PandocMonad m =>
[Block] -> XWikiReader m Text
blockListToXWiki [Block]
blocks
let quoteLines :: [Text]
quoteLines = (Char -> Bool) -> Text -> [Text]
split (forall a. Eq a => a -> a -> Bool
== Char
'\n') Text
blockText
let prefixed :: [Text]
prefixed = forall a b. (a -> b) -> [a] -> [b]
map (Text
">" forall a. Semigroup a => a -> a -> a
<>) [Text]
quoteLines
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Text] -> Text
vcat [Text]
prefixed
blockToXWiki (BulletList [[Block]]
contents) = forall (m :: * -> *).
PandocMonad m =>
Text -> [[Block]] -> XWikiReader m Text
blockToXWikiList Text
"*" [[Block]]
contents
blockToXWiki (OrderedList ListAttributes
_ [[Block]]
contents) = forall (m :: * -> *).
PandocMonad m =>
Text -> [[Block]] -> XWikiReader m Text
blockToXWikiList Text
"1" [[Block]]
contents
blockToXWiki (DefinitionList [([Inline], [[Block]])]
items) = do
Text
lev <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterState -> Text
listLevel
[Text]
contents <- forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\WriterState
s -> WriterState
s { listLevel :: Text
listLevel = WriterState -> Text
listLevel WriterState
s forall a. Semigroup a => a -> a -> a
<> Text
";" }) 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 =>
([Inline], [[Block]]) -> XWikiReader m Text
definitionListItemToMediaWiki [([Inline], [[Block]])]
items
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 Text -> Bool
Text.null Text
lev then Text
"\n" else Text
""
blockToXWiki (Figure (Text, [Text], [(Text, Text)])
attr Caption
_ [Block]
body) = do
Text
content <- forall (m :: * -> *). PandocMonad m => Block -> XWikiReader m Text
blockToXWiki forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> [Block] -> Block
Div (Text, [Text], [(Text, Text)])
attr [Block]
body
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
intercalate Text
content [Text
"(((\n", Text
"\n)))"]
blockToXWiki (Table (Text, [Text], [(Text, Text)])
_ Caption
blkCapt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot) = do
let ([Inline]
_, [Alignment]
_, [Double]
_, [[Block]]
headers, [[[Block]]]
rows') = Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> ([Inline], [Alignment], [Double], [[Block]], [[[Block]]])
toLegacyTable Caption
blkCapt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot
[Text]
headers' <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
Bool -> [Block] -> XWikiReader m Text
tableCellXWiki Bool
True) forall a b. (a -> b) -> a -> b
$ forall a. Int -> [a] -> [a]
take (forall (t :: * -> *) a. Foldable t => t a -> Int
length [ColSpec]
specs) forall a b. (a -> b) -> a -> b
$ [[Block]]
headers forall a. [a] -> [a] -> [a]
++ forall a. a -> [a]
repeat []
[Text]
otherRows <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall (m :: * -> *).
PandocMonad m =>
[[Block]] -> XWikiReader m Text
formRow [[[Block]]]
rows'
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Text] -> Text
Text.unlines ([Text] -> Text
Text.unwords [Text]
headers'forall a. a -> [a] -> [a]
:[Text]
otherRows)
formRow :: PandocMonad m => [[Block]] -> XWikiReader m Text
formRow :: forall (m :: * -> *).
PandocMonad m =>
[[Block]] -> XWikiReader m Text
formRow [[Block]]
row = do
[Text]
cellStrings <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
Bool -> [Block] -> XWikiReader m Text
tableCellXWiki Bool
False) [[Block]]
row
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Text] -> Text
Text.unwords [Text]
cellStrings
tableCellXWiki :: PandocMonad m => Bool -> [Block] -> XWikiReader m Text
tableCellXWiki :: forall (m :: * -> *).
PandocMonad m =>
Bool -> [Block] -> XWikiReader m Text
tableCellXWiki Bool
isHeader [Block]
cell = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Block] -> XWikiReader m Text
blockListToXWiki [Block]
cell
let isMultiline :: Bool
isMultiline = (forall (t :: * -> *) a. Foldable t => t a -> Int
length forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> [Text]
split (forall a. Eq a => a -> a -> Bool
== Char
'\n')) Text
contents forall a. Ord a => a -> a -> Bool
> Int
1
let contents' :: Text
contents' = Text -> [Text] -> Text
intercalate Text
contents forall a b. (a -> b) -> a -> b
$ if Bool
isMultiline then [Text
"(((", Text
")))"] else [forall a. Monoid a => a
mempty, forall a. Monoid a => a
mempty]
let cellBorder :: Text
cellBorder = if Bool
isHeader then Text
"|=" else Text
"|"
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
cellBorder forall a. Semigroup a => a -> a -> a
<> Text
contents'
inlineListToXWiki :: PandocMonad m => [Inline] -> XWikiReader m Text
inlineListToXWiki :: forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
lst =
forall a. Monoid a => [a] -> a
mconcat 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 => Inline -> XWikiReader m Text
inlineToXWiki [Inline]
lst
inlineToXWiki :: PandocMonad m => Inline -> XWikiReader m Text
inlineToXWiki :: forall (m :: * -> *). PandocMonad m => Inline -> XWikiReader m Text
inlineToXWiki (Str Text
str) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text
escapeXWikiString Text
str
inlineToXWiki Inline
Space = forall (m :: * -> *) a. Monad m => a -> m a
return Text
" "
inlineToXWiki Inline
LineBreak = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"\\\\"
inlineToXWiki Inline
SoftBreak = forall (m :: * -> *) a. Monad m => a -> m a
return Text
" "
inlineToXWiki (Emph [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [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
"//"
inlineToXWiki (Underline [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [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
"__"
inlineToXWiki (Strong [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [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
"**"
inlineToXWiki (Strikeout [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [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
"--"
inlineToXWiki (Superscript [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [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
"^^"
inlineToXWiki (Subscript [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [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
",,"
inlineToXWiki (SmallCaps [Inline]
lst) =
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
lst
inlineToXWiki (Quoted QuoteType
SingleQuote [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [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
"’"
inlineToXWiki (Quoted QuoteType
DoubleQuote [Inline]
lst) = do
Text
contents <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [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
"”"
inlineToXWiki (Code (Text
_,[Text]
classes,[(Text, Text)]
_) Text
contents) = do
let at :: Set Text
at = forall a. Ord a => [a] -> Set a
Set.fromList [Text]
classes forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set Text
highlightingLangs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
case forall a. Set a -> [a]
Set.toList Set Text
at of
[] -> Text
"{{code}}" forall a. Semigroup a => a -> a -> a
<> Text
contents forall a. Semigroup a => a -> a -> a
<> Text
"{{/code}}"
(Text
l:[Text]
_) -> Text
"{{code language=\"" forall a. Semigroup a => a -> a -> a
<> Text
l 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
"{{/code}}"
inlineToXWiki (Cite [Citation]
_ [Inline]
lst) = forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
lst
inlineToXWiki (Math MathType
_ Text
str) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"{{formula}}" forall a. Semigroup a => a -> a -> a
<> Text
str forall a. Semigroup a => a -> a -> a
<> Text
"{{/formula}}"
inlineToXWiki il :: Inline
il@(RawInline Format
frmt Text
str)
| Format
frmt forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"xwiki" = forall (m :: * -> *) a. Monad m => a -> m a
return Text
str
| Bool
otherwise = Text
"" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (Inline -> LogMessage
InlineNotRendered Inline
il)
inlineToXWiki (Link (Text
id', [Text]
_, [(Text, Text)]
_) [Inline]
txt (Text
src, Text
_)) = do
Text
label <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
txt
case [Inline]
txt of
[Str Text
s] | Text -> Bool
isURI Text
src Bool -> Bool -> Bool
&& Text -> Text
escapeURI Text
s forall a. Eq a => a -> a -> Bool
== Text
src -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
src forall a. Semigroup a => a -> a -> a
<> Text -> Text
genAnchor Text
id'
[Inline]
_ -> 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
label forall a. Semigroup a => a -> a -> a
<> Text
">>" forall a. Semigroup a => a -> a -> a
<> Text
src forall a. Semigroup a => a -> a -> a
<> Text
"]]" forall a. Semigroup a => a -> a -> a
<> Text -> Text
genAnchor Text
id'
inlineToXWiki (Image (Text, [Text], [(Text, Text)])
_ [Inline]
alt (Text
source, Text
tit)) = do
Text
alt' <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
alt
let
params :: Text
params = [Text] -> Text
Text.unwords forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
Text.null) [
if Text -> Bool
Text.null Text
alt' then Text
"" else Text
"alt=\"" forall a. Semigroup a => a -> a -> a
<> Text
alt' forall a. Semigroup a => a -> a -> a
<> Text
"\"",
if Text -> Bool
Text.null Text
tit then Text
"" else Text
"title=\"" forall a. Semigroup a => a -> a -> a
<> Text
tit 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
"[[image:" forall a. Semigroup a => a -> a -> a
<> Text
source forall a. Semigroup a => a -> a -> a
<> (if Text -> Bool
Text.null Text
params then Text
"" else Text
"||" forall a. Semigroup a => a -> a -> a
<> Text
params) forall a. Semigroup a => a -> a -> a
<> Text
"]]"
inlineToXWiki (Note [Block]
contents) = do
Text
contents' <- forall (m :: * -> *).
PandocMonad m =>
[Block] -> XWikiReader m Text
blockListToXWiki [Block]
contents
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
"{{footnote}}" forall a. Semigroup a => a -> a -> a
<> Text -> Text
Text.strip Text
contents' forall a. Semigroup a => a -> a -> a
<> Text
"{{/footnote}}"
inlineToXWiki (Span (Text
id', [Text]
_, [(Text, Text)]
_) [Inline]
contents) = do
Text
contents' <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [Inline]
contents
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text
genAnchor Text
id' forall a. Semigroup a => a -> a -> a
<> Text
contents'
blockToXWikiList :: PandocMonad m => Text -> [[Block]] -> XWikiReader m Text
blockToXWikiList :: forall (m :: * -> *).
PandocMonad m =>
Text -> [[Block]] -> XWikiReader m Text
blockToXWikiList Text
marker [[Block]]
contents = do
Text
lev <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterState -> Text
listLevel
[Text]
contents' <- forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\WriterState
s -> WriterState
s { listLevel :: Text
listLevel = WriterState -> Text
listLevel WriterState
s forall a. Semigroup a => a -> a -> a
<> Text
marker } ) 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 =>
[Block] -> XWikiReader m Text
listItemToXWiki [[Block]]
contents
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 Text -> Bool
Text.null Text
lev then Text
"\n" else Text
""
listItemToXWiki :: PandocMonad m => [Block] -> XWikiReader m Text
listItemToXWiki :: forall (m :: * -> *).
PandocMonad m =>
[Block] -> XWikiReader m Text
listItemToXWiki [Block]
contents = do
Text
marker <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterState -> Text
listLevel
Text
contents' <- forall (m :: * -> *).
PandocMonad m =>
[Block] -> XWikiReader m Text
blockListToXWiki [Block]
contents
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
marker forall a. Semigroup a => a -> a -> a
<> Text
". " forall a. Semigroup a => a -> a -> a
<> Text -> Text
Text.strip Text
contents'
definitionListItemToMediaWiki :: PandocMonad m
=> ([Inline],[[Block]])
-> XWikiReader m Text
definitionListItemToMediaWiki :: forall (m :: * -> *).
PandocMonad m =>
([Inline], [[Block]]) -> XWikiReader m Text
definitionListItemToMediaWiki ([Inline]
label, [[Block]]
items) = do
Text
labelText <- forall (m :: * -> *).
PandocMonad m =>
[Inline] -> XWikiReader m Text
inlineListToXWiki [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 =>
[Block] -> XWikiReader m Text
blockListToXWiki [[Block]]
items
Text
marker <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterState -> Text
listLevel
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
marker forall a. Semigroup a => a -> a -> a
<> Text
" " forall a. Semigroup a => a -> a -> a
<> Text
labelText forall a. Semigroup a => a -> a -> a
<> Text
"\n" forall a. Semigroup a => a -> a -> a
<>
Text -> [Text] -> Text
intercalate Text
"\n" (forall a b. (a -> b) -> [a] -> [b]
map (\Text
d -> Text -> Text
Text.init Text
marker forall a. Semigroup a => a -> a -> a
<> Text
": " forall a. Semigroup a => a -> a -> a
<> Text
d) [Text]
contents)
escapeXWikiString :: Text -> Text
escapeXWikiString :: Text -> Text
escapeXWikiString Text
s = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text -> Text -> Text -> Text
replace) Text
s forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Text
"--", Text
"**", Text
"//", Text
"^^", Text
",,", Text
"~"] [Text
"~-~-", Text
"~*~*", Text
"~/~/", Text
"~^~^", Text
"~,~,", Text
"~~"]