{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Writers.MediaWiki ( writeMediaWiki, highlightingLangs ) where
import Control.Monad.Reader
import Control.Monad.State.Strict
import Data.Maybe (fromMaybe)
import qualified Data.Set as Set
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 -> Bool
stNotes :: Bool
, WriterState -> WriterOptions
stOptions :: WriterOptions
}
data WriterReader = WriterReader {
WriterReader -> WriterOptions
options :: WriterOptions
, WriterReader -> [Char]
listLevel :: [Char]
, WriterReader -> Bool
useTags :: Bool
}
type MediaWikiWriter m = ReaderT WriterReader (StateT WriterState m)
writeMediaWiki :: PandocMonad m => WriterOptions -> Pandoc -> m Text
writeMediaWiki :: WriterOptions -> Pandoc -> m Text
writeMediaWiki WriterOptions
opts Pandoc
document =
let initialState :: WriterState
initialState = WriterState :: Bool -> WriterOptions -> WriterState
WriterState { stNotes :: Bool
stNotes = Bool
False, stOptions :: WriterOptions
stOptions = WriterOptions
opts }
env :: WriterReader
env = WriterReader :: WriterOptions -> [Char] -> Bool -> WriterReader
WriterReader { options :: WriterOptions
options = WriterOptions
opts, listLevel :: [Char]
listLevel = [], useTags :: Bool
useTags = Bool
False }
in StateT WriterState m Text -> WriterState -> m Text
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT (ReaderT WriterReader (StateT WriterState m) Text
-> WriterReader -> StateT WriterState m Text
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (Pandoc -> ReaderT WriterReader (StateT WriterState m) Text
forall (m :: * -> *).
PandocMonad m =>
Pandoc -> MediaWikiWriter m Text
pandocToMediaWiki Pandoc
document) WriterReader
env) WriterState
initialState
pandocToMediaWiki :: PandocMonad m => Pandoc -> MediaWikiWriter m Text
pandocToMediaWiki :: Pandoc -> MediaWikiWriter m Text
pandocToMediaWiki (Pandoc Meta
meta [Block]
blocks) = do
WriterOptions
opts <- (WriterReader -> WriterOptions)
-> ReaderT WriterReader (StateT WriterState m) WriterOptions
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> WriterOptions
options
Context Text
metadata <- WriterOptions
-> ([Block]
-> ReaderT WriterReader (StateT WriterState m) (Doc Text))
-> ([Inline]
-> ReaderT WriterReader (StateT WriterState m) (Doc Text))
-> Meta
-> ReaderT WriterReader (StateT WriterState m) (Context Text)
forall (m :: * -> *) a.
(Monad m, TemplateTarget a) =>
WriterOptions
-> ([Block] -> m (Doc a))
-> ([Inline] -> m (Doc a))
-> Meta
-> m (Context a)
metaToContext WriterOptions
opts
((Text -> Doc Text)
-> MediaWikiWriter m Text
-> ReaderT WriterReader (StateT WriterState m) (Doc Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Doc Text
forall a. HasChars a => a -> Doc a
literal (Text -> Doc Text) -> (Text -> Text) -> Text -> Doc Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trimr) (MediaWikiWriter m Text
-> ReaderT WriterReader (StateT WriterState m) (Doc Text))
-> ([Block] -> MediaWikiWriter m Text)
-> [Block]
-> ReaderT WriterReader (StateT WriterState m) (Doc Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
blockListToMediaWiki)
((Text -> Doc Text)
-> MediaWikiWriter m Text
-> ReaderT WriterReader (StateT WriterState m) (Doc Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> Doc Text
forall a. HasChars a => a -> Doc a
literal (Text -> Doc Text) -> (Text -> Text) -> Text -> Doc Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trimr) (MediaWikiWriter m Text
-> ReaderT WriterReader (StateT WriterState m) (Doc Text))
-> ([Inline] -> MediaWikiWriter m Text)
-> [Inline]
-> ReaderT WriterReader (StateT WriterState m) (Doc Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki)
Meta
meta
Text
body <- [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
blockListToMediaWiki [Block]
blocks
Bool
notesExist <- (WriterState -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Bool
stNotes
let notes :: Text
notes = if Bool
notesExist
then Text
"\n<references />"
else Text
""
let main :: Text
main = Text
body Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
notes
let context :: Context Text
context = Text -> Text -> Context Text -> Context Text
forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"body" Text
main
(Context Text -> Context Text) -> Context Text -> Context Text
forall a b. (a -> b) -> a -> b
$ Text -> Bool -> Context Text -> Context Text
forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"toc" (WriterOptions -> Bool
writerTableOfContents WriterOptions
opts) Context Text
metadata
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
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 -> Maybe Int -> Doc Text -> Text
forall a. HasChars a => Maybe Int -> Doc a -> a
render Maybe Int
forall a. Maybe a
Nothing (Doc Text -> Text) -> Doc Text -> Text
forall a b. (a -> b) -> a -> b
$ Template Text -> Context Text -> Doc Text
forall a b.
(TemplateTarget a, ToContext a b) =>
Template a -> b -> Doc a
renderTemplate Template Text
tpl Context Text
context
escapeText :: Text -> Text
escapeText :: Text -> Text
escapeText = Text -> Text
escapeStringForXML
blockToMediaWiki :: PandocMonad m
=> Block
-> MediaWikiWriter m Text
blockToMediaWiki :: Block -> MediaWikiWriter m Text
blockToMediaWiki Block
Null = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
blockToMediaWiki (Div Attr
attrs [Block]
bs) = do
Text
contents <- [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
blockListToMediaWiki [Block]
bs
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Maybe Int -> Doc Text -> Text
forall a. HasChars a => Maybe Int -> Doc a -> a
render Maybe Int
forall a. Maybe a
Nothing (Text -> Attr -> Doc Text
forall a. HasChars a => Text -> Attr -> Doc a
tagWithAttrs Text
"div" Attr
attrs) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</div>"
blockToMediaWiki (Plain [Inline]
inlines) =
[Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
inlines
blockToMediaWiki (SimpleFigure Attr
attr [Inline]
txt (Text
src, Text
tit)) = do
Text
capt <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
txt
Text
img <- Attr -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
Attr -> MediaWikiWriter m Text
imageToMediaWiki Attr
attr
let opt :: Text
opt = if Text -> Bool
T.null Text
tit
then
if Text -> Bool
T.null Text
capt
then Text
""
else Text
"alt=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
capt
else Text
"alt=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tit
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"[[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text -> [Text] -> Text
T.intercalate Text
"|"
((Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
T.null) [Text
"File:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
src
, Text
"thumb"
, Text
"none"
, Text
img
, Text
opt
, Text
capt
]) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
"]]\n"
blockToMediaWiki (Para [Inline]
inlines) = do
Bool
tags <- (WriterReader -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> Bool
useTags
[Char]
lev <- (WriterReader -> [Char])
-> ReaderT WriterReader (StateT WriterState m) [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> [Char]
listLevel
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
inlines
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ if Bool
tags
then Text
"<p>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</p>"
else Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if [Char] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
lev then Text
"\n" else Text
""
blockToMediaWiki (LineBlock [[Inline]]
lns) =
Block -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
Block -> MediaWikiWriter m Text
blockToMediaWiki (Block -> MediaWikiWriter m Text)
-> Block -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ [[Inline]] -> Block
linesToPara [[Inline]]
lns
blockToMediaWiki b :: Block
b@(RawBlock Format
f Text
str)
| Format
f Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"mediawiki" = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
str
| Format
f Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"html" = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
str
| Bool
otherwise = Text
"" Text
-> ReaderT WriterReader (StateT WriterState m) ()
-> MediaWikiWriter m Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LogMessage -> ReaderT WriterReader (StateT WriterState m) ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (Block -> LogMessage
BlockNotRendered Block
b)
blockToMediaWiki Block
HorizontalRule = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"\n-----\n"
blockToMediaWiki (Header Int
level Attr
_ [Inline]
inlines) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
inlines
let eqs :: Text
eqs = Int -> Text -> Text
T.replicate Int
level Text
"="
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
eqs Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
eqs Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
blockToMediaWiki (CodeBlock (Text
_,[Text]
classes,[(Text, Text)]
keyvals) Text
str) = do
let at :: Set Text
at = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList [Text]
classes Set Text -> Set Text -> Set Text
forall a. Ord a => Set a -> Set a -> Set a
`Set.intersection` Set Text
highlightingLangs
let numberLines :: Bool
numberLines = (Text -> Bool) -> [Text] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"number",Text
"numberLines", Text
"number-lines"])
[Text]
classes
let start :: Maybe Text
start = Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"startFrom" [(Text, Text)]
keyvals
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$
case Set Text -> [Text]
forall a. Set a -> [a]
Set.toList Set Text
at of
[] -> Text
"<pre" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (if [Text] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
classes
then Text
">"
else Text
" class=\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.unwords [Text]
classes Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\">") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text -> Text
escapeText Text
str Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</pre>"
(Text
l:[Text]
_) -> Text
"<syntaxhighlight lang=\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
l Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
(if Bool
numberLines then Text
" line" else Text
"") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text -> (Text -> Text) -> Maybe Text -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (\Text
x -> Text
" start=\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\"") Maybe Text
start Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
str Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
"</syntaxhighlight>"
blockToMediaWiki (BlockQuote [Block]
blocks) = do
Text
contents <- [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
blockListToMediaWiki [Block]
blocks
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<blockquote>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</blockquote>"
blockToMediaWiki (Table Attr
_ Caption
blkCapt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot) = do
let ([Inline]
capt, [Alignment]
aligns, [Double]
widths, [[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
caption <- if [Inline] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inline]
capt
then Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
else do
Text
c <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
capt
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"|+ " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
trimr Text
c Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n"
let headless :: Bool
headless = ([Block] -> Bool) -> [[Block]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all [Block] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Block]]
headers
let allrows :: [[[Block]]]
allrows = if Bool
headless then [[[Block]]]
rows' else [[Block]]
headers[[Block]] -> [[[Block]]] -> [[[Block]]]
forall a. a -> [a] -> [a]
:[[[Block]]]
rows'
Text
tableBody <- Text -> [Text] -> Text
T.intercalate Text
"|-\n" ([Text] -> Text)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> MediaWikiWriter m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap`
((Int, [[Block]]) -> MediaWikiWriter m Text)
-> [(Int, [[Block]])]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Bool
-> [Alignment]
-> [Double]
-> (Int, [[Block]])
-> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
Bool
-> [Alignment]
-> [Double]
-> (Int, [[Block]])
-> MediaWikiWriter m Text
tableRowToMediaWiki Bool
headless [Alignment]
aligns [Double]
widths)
([Int] -> [[[Block]]] -> [(Int, [[Block]])]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
1..] [[[Block]]]
allrows)
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"{|\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
caption Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tableBody Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"|}\n"
blockToMediaWiki x :: Block
x@(BulletList [[Block]]
items) = do
Bool
tags <-
(Bool -> Bool -> Bool
|| Bool -> Bool
not (Block -> Bool
isSimpleList Block
x)) (Bool -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
-> ReaderT WriterReader (StateT WriterState m) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (WriterReader -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> Bool
useTags
if Bool
tags
then do
[Text]
contents <- (WriterReader -> WriterReader)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\ WriterReader
s -> WriterReader
s { useTags :: Bool
useTags = Bool
True }) (ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text])
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall a b. (a -> b) -> a -> b
$ ([Block] -> MediaWikiWriter m Text)
-> [[Block]] -> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
listItemToMediaWiki [[Block]]
items
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<ul>\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
vcat [Text]
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</ul>\n"
else do
[Char]
lev <- (WriterReader -> [Char])
-> ReaderT WriterReader (StateT WriterState m) [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> [Char]
listLevel
[Text]
contents <- (WriterReader -> WriterReader)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\WriterReader
s -> WriterReader
s { listLevel :: [Char]
listLevel = WriterReader -> [Char]
listLevel WriterReader
s [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
"*" }) (ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text])
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall a b. (a -> b) -> a -> b
$ ([Block] -> MediaWikiWriter m Text)
-> [[Block]] -> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
listItemToMediaWiki [[Block]]
items
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
vcat [Text]
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if [Char] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
lev then Text
"\n" else Text
""
blockToMediaWiki x :: Block
x@(OrderedList ListAttributes
attribs [[Block]]
items) = do
Bool
tags <-
(Bool -> Bool -> Bool
|| Bool -> Bool
not (Block -> Bool
isSimpleList Block
x)) (Bool -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
-> ReaderT WriterReader (StateT WriterState m) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (WriterReader -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> Bool
useTags
if Bool
tags
then do
[Text]
contents <- (WriterReader -> WriterReader)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\WriterReader
s -> WriterReader
s { useTags :: Bool
useTags = Bool
True }) (ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text])
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall a b. (a -> b) -> a -> b
$ ([Block] -> MediaWikiWriter m Text)
-> [[Block]] -> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
listItemToMediaWiki [[Block]]
items
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<ol" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ListAttributes -> Text
listAttribsToText ListAttributes
attribs Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
">\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
vcat [Text]
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</ol>\n"
else do
[Char]
lev <- (WriterReader -> [Char])
-> ReaderT WriterReader (StateT WriterState m) [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> [Char]
listLevel
[Text]
contents <- (WriterReader -> WriterReader)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\WriterReader
s -> WriterReader
s { listLevel :: [Char]
listLevel = WriterReader -> [Char]
listLevel WriterReader
s [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
"#" }) (ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text])
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall a b. (a -> b) -> a -> b
$ ([Block] -> MediaWikiWriter m Text)
-> [[Block]] -> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
listItemToMediaWiki [[Block]]
items
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
vcat [Text]
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if [Char] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
lev then Text
"\n" else Text
""
blockToMediaWiki x :: Block
x@(DefinitionList [([Inline], [[Block]])]
items) = do
Bool
tags <-
(Bool -> Bool -> Bool
|| Bool -> Bool
not (Block -> Bool
isSimpleList Block
x)) (Bool -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
-> ReaderT WriterReader (StateT WriterState m) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (WriterReader -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> Bool
useTags
if Bool
tags
then do
[Text]
contents <- (WriterReader -> WriterReader)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\WriterReader
s -> WriterReader
s { useTags :: Bool
useTags = Bool
True }) (ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text])
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall a b. (a -> b) -> a -> b
$ (([Inline], [[Block]]) -> MediaWikiWriter m Text)
-> [([Inline], [[Block]])]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ([Inline], [[Block]]) -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
([Inline], [[Block]]) -> MediaWikiWriter m Text
definitionListItemToMediaWiki [([Inline], [[Block]])]
items
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<dl>\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
vcat [Text]
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</dl>\n"
else do
[Char]
lev <- (WriterReader -> [Char])
-> ReaderT WriterReader (StateT WriterState m) [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> [Char]
listLevel
[Text]
contents <- (WriterReader -> WriterReader)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local (\WriterReader
s -> WriterReader
s { listLevel :: [Char]
listLevel = WriterReader -> [Char]
listLevel WriterReader
s [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
";" }) (ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text])
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall a b. (a -> b) -> a -> b
$ (([Inline], [[Block]]) -> MediaWikiWriter m Text)
-> [([Inline], [[Block]])]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ([Inline], [[Block]]) -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
([Inline], [[Block]]) -> MediaWikiWriter m Text
definitionListItemToMediaWiki [([Inline], [[Block]])]
items
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
vcat [Text]
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> if [Char] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
lev then Text
"\n" else Text
""
listAttribsToText :: ListAttributes -> Text
listAttribsToText :: ListAttributes -> Text
listAttribsToText (Int
startnum, ListNumberStyle
numstyle, ListNumberDelim
_) =
let numstyle' :: Text
numstyle' = Text -> Text
camelCaseToHyphenated (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ ListNumberStyle -> Text
forall a. Show a => a -> Text
tshow ListNumberStyle
numstyle
in (if Int
startnum Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
1
then Text
" start=\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
tshow Int
startnum Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\""
else Text
"") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
(if ListNumberStyle
numstyle ListNumberStyle -> ListNumberStyle -> Bool
forall a. Eq a => a -> a -> Bool
/= ListNumberStyle
DefaultStyle
then Text
" style=\"list-style-type: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
numstyle' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
";\""
else Text
"")
listItemToMediaWiki :: PandocMonad m => [Block] -> MediaWikiWriter m Text
listItemToMediaWiki :: [Block] -> MediaWikiWriter m Text
listItemToMediaWiki [Block]
items = do
Text
contents <- [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
blockListToMediaWiki [Block]
items
Bool
tags <- (WriterReader -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> Bool
useTags
if Bool
tags
then Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<li>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</li>"
else do
[Char]
marker <- (WriterReader -> [Char])
-> ReaderT WriterReader (StateT WriterState m) [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> [Char]
listLevel
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack [Char]
marker Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents
definitionListItemToMediaWiki :: PandocMonad m
=> ([Inline],[[Block]])
-> MediaWikiWriter m Text
definitionListItemToMediaWiki :: ([Inline], [[Block]]) -> MediaWikiWriter m Text
definitionListItemToMediaWiki ([Inline]
label, [[Block]]
items) = do
Text
labelText <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
label
[Text]
contents <- ([Block] -> MediaWikiWriter m Text)
-> [[Block]] -> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
blockListToMediaWiki [[Block]]
items
Bool
tags <- (WriterReader -> Bool)
-> ReaderT WriterReader (StateT WriterState m) Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> Bool
useTags
if Bool
tags
then Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<dt>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
labelText Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</dt>\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text -> [Text] -> Text
T.intercalate Text
"\n" ((Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (\Text
d -> Text
"<dd>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
d Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</dd>") [Text]
contents)
else do
[Char]
marker <- (WriterReader -> [Char])
-> ReaderT WriterReader (StateT WriterState m) [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> [Char]
listLevel
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack [Char]
marker Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
labelText Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text -> [Text] -> Text
T.intercalate Text
"\n" ((Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (\Text
d -> [Char] -> Text
T.pack ([Char] -> [Char]
forall a. [a] -> [a]
init [Char]
marker) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
": " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
d) [Text]
contents)
isSimpleList :: Block -> Bool
isSimpleList :: Block -> Bool
isSimpleList Block
x =
case Block
x of
BulletList [[Block]]
items -> ([Block] -> Bool) -> [[Block]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all [Block] -> Bool
isSimpleListItem [[Block]]
items
OrderedList (Int
num, ListNumberStyle
sty, ListNumberDelim
_) [[Block]]
items -> ([Block] -> Bool) -> [[Block]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all [Block] -> Bool
isSimpleListItem [[Block]]
items Bool -> Bool -> Bool
&&
Int
num Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 Bool -> Bool -> Bool
&& ListNumberStyle
sty ListNumberStyle -> [ListNumberStyle] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [ListNumberStyle
DefaultStyle, ListNumberStyle
Decimal]
DefinitionList [([Inline], [[Block]])]
items -> ([Block] -> Bool) -> [[Block]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all [Block] -> Bool
isSimpleListItem ([[Block]] -> Bool) -> [[Block]] -> Bool
forall a b. (a -> b) -> a -> b
$ (([Inline], [[Block]]) -> [[Block]])
-> [([Inline], [[Block]])] -> [[Block]]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ([Inline], [[Block]]) -> [[Block]]
forall a b. (a, b) -> b
snd [([Inline], [[Block]])]
items
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
DefinitionList [([Inline], [[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
DefinitionList [([Inline], [[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"
tableRowToMediaWiki :: PandocMonad m
=> Bool
-> [Alignment]
-> [Double]
-> (Int, [[Block]])
-> MediaWikiWriter m Text
tableRowToMediaWiki :: Bool
-> [Alignment]
-> [Double]
-> (Int, [[Block]])
-> MediaWikiWriter m Text
tableRowToMediaWiki Bool
headless [Alignment]
alignments [Double]
widths (Int
rownum, [[Block]]
cells) = do
[Text]
cells' <- ((Alignment, Double, [Block]) -> MediaWikiWriter m Text)
-> [(Alignment, Double, [Block])]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Bool
-> Int -> (Alignment, Double, [Block]) -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
Bool
-> Int -> (Alignment, Double, [Block]) -> MediaWikiWriter m Text
tableCellToMediaWiki Bool
headless Int
rownum)
([(Alignment, Double, [Block])]
-> ReaderT WriterReader (StateT WriterState m) [Text])
-> [(Alignment, Double, [Block])]
-> ReaderT WriterReader (StateT WriterState m) [Text]
forall a b. (a -> b) -> a -> b
$ [Alignment]
-> [Double] -> [[Block]] -> [(Alignment, Double, [Block])]
forall a b c. [a] -> [b] -> [c] -> [(a, b, c)]
zip3 [Alignment]
alignments [Double]
widths [[Block]]
cells
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
T.unlines [Text]
cells'
tableCellToMediaWiki :: PandocMonad m
=> Bool
-> Int
-> (Alignment, Double, [Block])
-> MediaWikiWriter m Text
tableCellToMediaWiki :: Bool
-> Int -> (Alignment, Double, [Block]) -> MediaWikiWriter m Text
tableCellToMediaWiki Bool
headless Int
rownum (Alignment
alignment, Double
width, [Block]
bs) = do
Text
contents <- [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
blockListToMediaWiki [Block]
bs
let marker :: Text
marker = if Int
rownum Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
headless then Text
"!" else Text
"|"
let percent :: a -> Text
percent a
w = Integer -> Text
forall a. Show a => a -> Text
tshow (a -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate (a
100a -> a -> a
forall a. Num a => a -> a -> a
*a
w) :: Integer) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"%"
let attrs :: [Text]
attrs = [Text
"align=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
forall a. Show a => a -> Text
tshow (Alignment -> Text
alignmentToText Alignment
alignment) |
Alignment
alignment Alignment -> Alignment -> Bool
forall a. Eq a => a -> a -> Bool
/= Alignment
AlignDefault Bool -> Bool -> Bool
&& Alignment
alignment Alignment -> Alignment -> Bool
forall a. Eq a => a -> a -> Bool
/= Alignment
AlignLeft] [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>
[Text
"width=\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Double -> Text
forall a. RealFrac a => a -> Text
percent Double
width Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\"" |
Double
width Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
/= Double
0.0 Bool -> Bool -> Bool
&& Int
rownum Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1]
let attr :: Text
attr = if [Text] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
attrs
then Text
""
else [Text] -> Text
T.unwords [Text]
attrs Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"|"
let sep :: Text
sep = case [Block]
bs of
[Plain [Inline]
_] -> Text
" "
[Para [Inline]
_] -> Text
" "
[] -> Text
""
[Block]
_ -> Text
"\n"
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
marker Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
attr Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
sep Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
trimr Text
contents
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"
imageToMediaWiki :: PandocMonad m => Attr -> MediaWikiWriter m Text
imageToMediaWiki :: Attr -> MediaWikiWriter m Text
imageToMediaWiki Attr
attr = do
WriterOptions
opts <- (WriterState -> WriterOptions)
-> ReaderT WriterReader (StateT WriterState m) WriterOptions
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> WriterOptions
stOptions
let (Text
_, [Text]
cls, [(Text, Text)]
_) = Attr
attr
toPx :: Maybe Dimension -> Maybe Text
toPx = (Dimension -> Text) -> Maybe Dimension -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (WriterOptions -> Dimension -> Text
showInPixel WriterOptions
opts) (Maybe Dimension -> Maybe Text)
-> (Maybe Dimension -> Maybe Dimension)
-> Maybe Dimension
-> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Dimension -> Maybe Dimension
checkPct
checkPct :: Maybe Dimension -> Maybe Dimension
checkPct (Just (Percent Double
_)) = Maybe Dimension
forall a. Maybe a
Nothing
checkPct Maybe Dimension
maybeDim = Maybe Dimension
maybeDim
go :: Maybe a -> Maybe a -> a
go (Just a
w) Maybe a
Nothing = a
w a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
"px"
go (Just a
w) (Just a
h) = a
w a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
"x" a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
h a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
"px"
go Maybe a
Nothing (Just a
h) = a
"x" a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
h a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
"px"
go Maybe a
Nothing Maybe a
Nothing = a
""
dims :: Text
dims = Maybe Text -> Maybe Text -> Text
forall a. (Semigroup a, IsString a) => Maybe a -> Maybe a -> a
go (Maybe Dimension -> Maybe Text
toPx (Maybe Dimension -> Maybe Text) -> Maybe Dimension -> Maybe Text
forall a b. (a -> b) -> a -> b
$ Direction -> Attr -> Maybe Dimension
dimension Direction
Width Attr
attr) (Maybe Dimension -> Maybe Text
toPx (Maybe Dimension -> Maybe Text) -> Maybe Dimension -> Maybe Text
forall a b. (a -> b) -> a -> b
$ Direction -> Attr -> Maybe Dimension
dimension Direction
Height Attr
attr)
classes :: Text
classes = if [Text] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
cls
then Text
""
else Text
"class=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
T.unwords [Text]
cls
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
T.intercalate Text
"|" ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
T.null) [Text
dims, Text
classes]
blockListToMediaWiki :: PandocMonad m
=> [Block]
-> MediaWikiWriter m Text
blockListToMediaWiki :: [Block] -> MediaWikiWriter m Text
blockListToMediaWiki [Block]
blocks =
[Text] -> Text
vcat ([Text] -> Text)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> MediaWikiWriter m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Block -> MediaWikiWriter m Text)
-> [Block] -> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Block -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
Block -> MediaWikiWriter m Text
blockToMediaWiki [Block]
blocks
inlineListToMediaWiki :: PandocMonad m => [Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki :: [Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst =
([Text] -> Text)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> MediaWikiWriter m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Text] -> Text
T.concat (ReaderT WriterReader (StateT WriterState m) [Text]
-> MediaWikiWriter m Text)
-> ReaderT WriterReader (StateT WriterState m) [Text]
-> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ (Inline -> MediaWikiWriter m Text)
-> [Inline] -> ReaderT WriterReader (StateT WriterState m) [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Inline -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
Inline -> MediaWikiWriter m Text
inlineToMediaWiki ([Inline] -> ReaderT WriterReader (StateT WriterState m) [Text])
-> [Inline] -> ReaderT WriterReader (StateT WriterState m) [Text]
forall a b. (a -> b) -> a -> b
$ [Inline] -> [Inline]
fixup [Inline]
lst
where
fixup :: [Inline] -> [Inline]
fixup [] = []
fixup (Str Text
t : Inline
x : [Inline]
xs)
| Bool -> Bool
not (Text -> Bool
T.null Text
t) Bool -> Bool -> Bool
&& Text -> Char
T.last Text
t Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'['
, Inline -> Bool
isLinkOrImage Inline
x =
Text -> Inline
Str Text
t Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Format -> Text -> Inline
RawInline (Text -> Format
Format Text
"mediawiki") Text
"<nowiki/>" Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Inline
x Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline] -> [Inline]
fixup [Inline]
xs
fixup (Inline
x:[Inline]
xs) = Inline
x Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline] -> [Inline]
fixup [Inline]
xs
isLinkOrImage :: Inline -> Bool
isLinkOrImage Link{} = Bool
True
isLinkOrImage Image{} = Bool
True
isLinkOrImage Inline
_ = Bool
False
inlineToMediaWiki :: PandocMonad m => Inline -> MediaWikiWriter m Text
inlineToMediaWiki :: Inline -> MediaWikiWriter m Text
inlineToMediaWiki (Span Attr
attrs [Inline]
ils) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
ils
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Maybe Int -> Doc Text -> Text
forall a. HasChars a => Maybe Int -> Doc a -> a
render Maybe Int
forall a. Maybe a
Nothing (Text -> Attr -> Doc Text
forall a. HasChars a => Text -> Attr -> Doc a
tagWithAttrs Text
"span" Attr
attrs) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</span>"
inlineToMediaWiki (Emph [Inline]
lst) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"''" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"''"
inlineToMediaWiki (Underline [Inline]
lst) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<u>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</u>"
inlineToMediaWiki (Strong [Inline]
lst) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"'''" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"'''"
inlineToMediaWiki (Strikeout [Inline]
lst) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<s>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</s>"
inlineToMediaWiki (Superscript [Inline]
lst) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<sup>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</sup>"
inlineToMediaWiki (Subscript [Inline]
lst) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<sub>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</sub>"
inlineToMediaWiki (SmallCaps [Inline]
lst) = [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
inlineToMediaWiki (Quoted QuoteType
SingleQuote [Inline]
lst) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"\8216" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\8217"
inlineToMediaWiki (Quoted QuoteType
DoubleQuote [Inline]
lst) = do
Text
contents <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"\8220" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\8221"
inlineToMediaWiki (Cite [Citation]
_ [Inline]
lst) = [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
lst
inlineToMediaWiki (Code Attr
_ Text
str) =
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<code>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
escapeText Text
str Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</code>"
inlineToMediaWiki (Str Text
str) = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
escapeText Text
str
inlineToMediaWiki (Math MathType
mt Text
str) = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$
Text
"<math display=\"" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
(if MathType
mt MathType -> MathType -> Bool
forall a. Eq a => a -> a -> Bool
== MathType
DisplayMath then Text
"block" else Text
"inline") Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text
"\">" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
str Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</math>"
inlineToMediaWiki il :: Inline
il@(RawInline Format
f Text
str)
| Format
f Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"mediawiki" = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
str
| Format
f Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"html" = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
str
| Bool
otherwise = Text
"" Text
-> ReaderT WriterReader (StateT WriterState m) ()
-> MediaWikiWriter m Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LogMessage -> ReaderT WriterReader (StateT WriterState m) ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (Inline -> LogMessage
InlineNotRendered Inline
il)
inlineToMediaWiki Inline
LineBreak = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"<br />\n"
inlineToMediaWiki Inline
SoftBreak = do
WrapOption
wrapText <- (WriterState -> WrapOption)
-> ReaderT WriterReader (StateT WriterState m) WrapOption
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (WriterOptions -> WrapOption
writerWrapText (WriterOptions -> WrapOption)
-> (WriterState -> WriterOptions) -> WriterState -> WrapOption
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterState -> WriterOptions
stOptions)
[Char]
listlevel <- (WriterReader -> [Char])
-> ReaderT WriterReader (StateT WriterState m) [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks WriterReader -> [Char]
listLevel
case WrapOption
wrapText of
WrapOption
WrapAuto -> Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
" "
WrapOption
WrapNone -> Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
" "
WrapOption
WrapPreserve -> if [Char] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
listlevel
then Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
"\n"
else Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
" "
inlineToMediaWiki Inline
Space = Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
" "
inlineToMediaWiki (Link Attr
_ [Inline]
txt (Text
src, Text
_)) = do
Text
label <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
txt
case [Inline]
txt of
[Str Text
s] | Text -> Bool
isURI Text
src Bool -> Bool -> Bool
&& Text -> Text
escapeURI Text
s Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
src -> Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
src
[Inline]
_ -> Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ if Text -> Bool
isURI Text
src
then Text
"[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
src Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
label Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]"
else Text
"[[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
src' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"|" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
label Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]]"
where src' :: Text
src' = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
src (Maybe Text -> Text) -> Maybe Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Maybe Text
T.stripPrefix Text
"/" Text
src
inlineToMediaWiki (Image Attr
attr [Inline]
alt (Text
source, Text
tit)) = do
Text
img <- Attr -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
Attr -> MediaWikiWriter m Text
imageToMediaWiki Attr
attr
Text
alt' <- [Inline] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki [Inline]
alt
let txt :: Text
txt = if Text -> Bool
T.null Text
alt'
then if Text -> Bool
T.null Text
tit
then Text
""
else Text
tit
else Text
alt'
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"[[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
Text -> [Text] -> Text
T.intercalate Text
"|"
((Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
T.null)
[ Text
"File:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
source
, Text
img
, Text
txt
]) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]]"
inlineToMediaWiki (Note [Block]
contents) = do
Text
contents' <- [Block] -> MediaWikiWriter m Text
forall (m :: * -> *).
PandocMonad m =>
[Block] -> MediaWikiWriter m Text
blockListToMediaWiki [Block]
contents
(WriterState -> WriterState)
-> ReaderT WriterReader (StateT WriterState m) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (\WriterState
s -> WriterState
s { stNotes :: Bool
stNotes = Bool
True })
Text -> MediaWikiWriter m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MediaWikiWriter m Text) -> Text -> MediaWikiWriter m Text
forall a b. (a -> b) -> a -> b
$ Text
"<ref>" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
stripTrailingNewlines Text
contents' Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"</ref>"
highlightingLangs :: Set.Set Text
highlightingLangs :: Set Text
highlightingLangs = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList [
Text
"abap",
Text
"abl",
Text
"abnf",
Text
"aconf",
Text
"actionscript",
Text
"actionscript3",
Text
"ada",
Text
"ada2005",
Text
"ada95",
Text
"adl",
Text
"agda",
Text
"ahk",
Text
"alloy",
Text
"ambienttalk",
Text
"ambienttalk/2",
Text
"antlr",
Text
"antlr-actionscript",
Text
"antlr-as",
Text
"antlr-c#",
Text
"antlr-cpp",
Text
"antlr-csharp",
Text
"antlr-java",
Text
"antlr-objc",
Text
"antlr-perl",
Text
"antlr-python",
Text
"antlr-rb",
Text
"antlr-ruby",
Text
"apache",
Text
"apacheconf",
Text
"apl",
Text
"applescript",
Text
"arduino",
Text
"arexx",
Text
"as",
Text
"as3",
Text
"asm",
Text
"aspectj",
Text
"aspx-cs",
Text
"aspx-vb",
Text
"asy",
Text
"asymptote",
Text
"at",
Text
"autohotkey",
Text
"autoit",
Text
"awk",
Text
"b3d",
Text
"basemake",
Text
"bash",
Text
"basic",
Text
"bat",
Text
"batch",
Text
"bbcode",
Text
"because",
Text
"befunge",
Text
"bf",
Text
"blitzbasic",
Text
"blitzmax",
Text
"bmax",
Text
"bnf",
Text
"boo",
Text
"boogie",
Text
"bplus",
Text
"brainfuck",
Text
"bro",
Text
"bsdmake",
Text
"bugs",
Text
"c",
Text
"c#",
Text
"c++",
Text
"c++-objdumb",
Text
"c-objdump",
Text
"ca65",
Text
"cadl",
Text
"camkes",
Text
"cbmbas",
Text
"ceylon",
Text
"cf3",
Text
"cfc",
Text
"cfengine3",
Text
"cfg",
Text
"cfm",
Text
"cfs",
Text
"chai",
Text
"chaiscript",
Text
"chapel",
Text
"cheetah",
Text
"chpl",
Text
"cirru",
Text
"cl",
Text
"clay",
Text
"clipper",
Text
"clj",
Text
"cljs",
Text
"clojure",
Text
"clojurescript",
Text
"cmake",
Text
"cobol",
Text
"cobolfree",
Text
"coffee",
Text
"coffee-script",
Text
"coffeescript",
Text
"common-lisp",
Text
"componentpascal",
Text
"console",
Text
"control",
Text
"coq",
Text
"cp",
Text
"cpp",
Text
"cpp-objdump",
Text
"cpsa",
Text
"crmsh",
Text
"croc",
Text
"cry",
Text
"cryptol",
Text
"csh",
Text
"csharp",
Text
"csound",
Text
"csound-csd",
Text
"csound-document",
Text
"csound-orc",
Text
"csound-sco",
Text
"csound-score",
Text
"css",
Text
"css+django",
Text
"css+erb",
Text
"css+genshi",
Text
"css+genshitext",
Text
"css+jinja",
Text
"css+lasso",
Text
"css+mako",
Text
"css+mozpreproc",
Text
"css+myghty",
Text
"css+php",
Text
"css+ruby",
Text
"css+smarty",
Text
"cu",
Text
"cucumber",
Text
"cuda",
Text
"cxx-objdump",
Text
"cypher",
Text
"cython",
Text
"d",
Text
"d-objdump",
Text
"dart",
Text
"debcontrol",
Text
"debsources",
Text
"delphi",
Text
"dg",
Text
"diff",
Text
"django",
Text
"docker",
Text
"dockerfile",
Text
"dosbatch",
Text
"doscon",
Text
"dosini",
Text
"dpatch",
Text
"dtd",
Text
"duby",
Text
"duel",
Text
"dylan",
Text
"dylan-console",
Text
"dylan-lid",
Text
"dylan-repl",
Text
"earl-grey",
Text
"earlgrey",
Text
"easytrieve",
Text
"ebnf",
Text
"ec",
Text
"ecl",
Text
"eg",
Text
"eiffel",
Text
"elisp",
Text
"elixir",
Text
"elm",
Text
"emacs",
Text
"erb",
Text
"erl",
Text
"erlang",
Text
"evoque",
Text
"ex",
Text
"exs",
Text
"ezhil",
Text
"factor",
Text
"fan",
Text
"fancy",
Text
"felix",
Text
"fish",
Text
"fishshell",
Text
"flx",
Text
"fortran",
Text
"fortranfixed",
Text
"foxpro",
Text
"fsharp",
Text
"fy",
Text
"gap",
Text
"gas",
Text
"gawk",
Text
"genshi",
Text
"genshitext",
Text
"gherkin",
Text
"glsl",
Text
"gnuplot",
Text
"go",
Text
"golo",
Text
"gooddata-cl",
Text
"gosu",
Text
"groff",
Text
"groovy",
Text
"gst",
Text
"haml",
Text
"handlebars",
Text
"haskell",
Text
"haxe",
Text
"haxeml",
Text
"hexdump",
Text
"hs",
Text
"html",
Text
"html+cheetah",
Text
"html+django",
Text
"html+erb",
Text
"html+evoque",
Text
"html+genshi",
Text
"html+handlebars",
Text
"html+jinja",
Text
"html+kid",
Text
"html+lasso",
Text
"html+mako",
Text
"html+myghty",
Text
"html+php",
Text
"html+ruby",
Text
"html+smarty",
Text
"html+spitfire",
Text
"html+twig",
Text
"html+velocity",
Text
"htmlcheetah",
Text
"htmldjango",
Text
"http",
Text
"hx",
Text
"hxml",
Text
"hxsl",
Text
"hy",
Text
"hybris",
Text
"hylang",
Text
"i6",
Text
"i6t",
Text
"i7",
Text
"idl",
Text
"idl4",
Text
"idr",
Text
"idris",
Text
"iex",
Text
"igor",
Text
"igorpro",
Text
"ik",
Text
"inform6",
Text
"inform7",
Text
"ini",
Text
"io",
Text
"ioke",
Text
"irb",
Text
"irc",
Text
"isabelle",
Text
"j",
Text
"jade",
Text
"jags",
Text
"jasmin",
Text
"jasminxt",
Text
"java",
Text
"javascript",
Text
"javascript+cheetah",
Text
"javascript+django",
Text
"javascript+erb",
Text
"javascript+genshi",
Text
"javascript+genshitext",
Text
"javascript+jinja",
Text
"javascript+lasso",
Text
"javascript+mako",
Text
"javascript+mozpreproc",
Text
"javascript+myghty",
Text
"javascript+php",
Text
"javascript+ruby",
Text
"javascript+smarty",
Text
"javascript+spitfire",
Text
"jbst",
Text
"jcl",
Text
"jinja",
Text
"jl",
Text
"jlcon",
Text
"jproperties",
Text
"js",
Text
"js+cheetah",
Text
"js+django",
Text
"js+erb",
Text
"js+genshi",
Text
"js+genshitext",
Text
"js+jinja",
Text
"js+lasso",
Text
"js+mako",
Text
"js+myghty",
Text
"js+php",
Text
"js+ruby",
Text
"js+smarty",
Text
"js+spitfire",
Text
"json",
Text
"json-ld",
Text
"jsonld",
Text
"jsonml+bst",
Text
"jsp",
Text
"julia",
Text
"kal",
Text
"kconfig",
Text
"kernel-config",
Text
"kid",
Text
"koka",
Text
"kotlin",
Text
"ksh",
Text
"lagda",
Text
"lasso",
Text
"lassoscript",
Text
"latex",
Text
"lcry",
Text
"lcryptol",
Text
"lean",
Text
"less",
Text
"lhaskell",
Text
"lhs",
Text
"lid",
Text
"lidr",
Text
"lidris",
Text
"lighttpd",
Text
"lighty",
Text
"limbo",
Text
"linux-config",
Text
"liquid",
Text
"lisp",
Text
"literate-agda",
Text
"literate-cryptol",
Text
"literate-haskell",
Text
"literate-idris",
Text
"live-script",
Text
"livescript",
Text
"llvm",
Text
"logos",
Text
"logtalk",
Text
"lsl",
Text
"lua",
Text
"m2",
Text
"make",
Text
"makefile",
Text
"mako",
Text
"man",
Text
"maql",
Text
"mask",
Text
"mason",
Text
"mathematica",
Text
"matlab",
Text
"matlabsession",
Text
"mawk",
Text
"menuconfig",
Text
"mf",
Text
"minid",
Text
"mma",
Text
"modelica",
Text
"modula2",
Text
"moin",
Text
"monkey",
Text
"moo",
Text
"moocode",
Text
"moon",
Text
"moonscript",
Text
"mozhashpreproc",
Text
"mozpercentpreproc",
Text
"mq4",
Text
"mq5",
Text
"mql",
Text
"mql4",
Text
"mql5",
Text
"msc",
Text
"mscgen",
Text
"mupad",
Text
"mxml",
Text
"myghty",
Text
"mysql",
Text
"nasm",
Text
"nawk",
Text
"nb",
Text
"nemerle",
Text
"nesc",
Text
"newlisp",
Text
"newspeak",
Text
"nginx",
Text
"nim",
Text
"nimrod",
Text
"nit",
Text
"nix",
Text
"nixos",
Text
"nroff",
Text
"nsh",
Text
"nsi",
Text
"nsis",
Text
"numpy",
Text
"obj-c",
Text
"obj-c++",
Text
"obj-j",
Text
"objc",
Text
"objc++",
Text
"objdump",
Text
"objdump-nasm",
Text
"objective-c",
Text
"objective-c++",
Text
"objective-j",
Text
"objectivec",
Text
"objectivec++",
Text
"objectivej",
Text
"objectpascal",
Text
"objj",
Text
"ocaml",
Text
"octave",
Text
"odin",
Text
"ooc",
Text
"opa",
Text
"openbugs",
Text
"openedge",
Text
"pacmanconf",
Text
"pan",
Text
"parasail",
Text
"pas",
Text
"pascal",
Text
"pawn",
Text
"pcmk",
Text
"perl",
Text
"perl6",
Text
"php",
Text
"php3",
Text
"php4",
Text
"php5",
Text
"pig",
Text
"pike",
Text
"pkgconfig",
Text
"pl",
Text
"pl6",
Text
"plpgsql",
Text
"po",
Text
"posh",
Text
"postgres",
Text
"postgres-console",
Text
"postgresql",
Text
"postgresql-console",
Text
"postscr",
Text
"postscript",
Text
"pot",
Text
"pov",
Text
"powershell",
Text
"praat",
Text
"progress",
Text
"prolog",
Text
"properties",
Text
"proto",
Text
"protobuf",
Text
"ps1",
Text
"ps1con",
Text
"psm1",
Text
"psql",
Text
"puppet",
Text
"py",
Text
"py3",
Text
"py3tb",
Text
"pycon",
Text
"pypy",
Text
"pypylog",
Text
"pyrex",
Text
"pytb",
Text
"python",
Text
"python3",
Text
"pyx",
Text
"qbasic",
Text
"qbs",
Text
"qml",
Text
"qvt",
Text
"qvto",
Text
"r",
Text
"racket",
Text
"ragel",
Text
"ragel-c",
Text
"ragel-cpp",
Text
"ragel-d",
Text
"ragel-em",
Text
"ragel-java",
Text
"ragel-objc",
Text
"ragel-rb",
Text
"ragel-ruby",
Text
"raw",
Text
"rb",
Text
"rbcon",
Text
"rconsole",
Text
"rd",
Text
"rebol",
Text
"red",
Text
"red/system",
Text
"redcode",
Text
"registry",
Text
"resource",
Text
"resourcebundle",
Text
"rest",
Text
"restructuredtext",
Text
"rexx",
Text
"rhtml",
Text
"rkt",
Text
"roboconf-graph",
Text
"roboconf-instances",
Text
"robotframework",
Text
"rout",
Text
"rql",
Text
"rsl",
Text
"rst",
Text
"rts",
Text
"ruby",
Text
"rust",
Text
"s",
Text
"sage",
Text
"salt",
Text
"sass",
Text
"sc",
Text
"scala",
Text
"scaml",
Text
"scheme",
Text
"scilab",
Text
"scm",
Text
"scss",
Text
"sh",
Text
"shell",
Text
"shell-session",
Text
"shen",
Text
"slim",
Text
"sls",
Text
"smali",
Text
"smalltalk",
Text
"smarty",
Text
"sml",
Text
"snobol",
Text
"sources.list",
Text
"sourceslist",
Text
"sp",
Text
"sparql",
Text
"spec",
Text
"spitfire",
Text
"splus",
Text
"sql",
Text
"sqlite3",
Text
"squeak",
Text
"squid",
Text
"squid.conf",
Text
"squidconf",
Text
"ssp",
Text
"st",
Text
"stan",
Text
"supercollider",
Text
"sv",
Text
"swift",
Text
"swig",
Text
"systemverilog",
Text
"tads3",
Text
"tap",
Text
"tcl",
Text
"tcsh",
Text
"tcshcon",
Text
"tea",
Text
"termcap",
Text
"terminfo",
Text
"terraform",
Text
"tex",
Text
"text",
Text
"tf",
Text
"thrift",
Text
"todotxt",
Text
"trac-wiki",
Text
"trafficscript",
Text
"treetop",
Text
"ts",
Text
"turtle",
Text
"twig",
Text
"typescript",
Text
"udiff",
Text
"urbiscript",
Text
"v",
Text
"vala",
Text
"vapi",
Text
"vb.net",
Text
"vbnet",
Text
"vctreestatus",
Text
"velocity",
Text
"verilog",
Text
"vfp",
Text
"vgl",
Text
"vhdl",
Text
"vim",
Text
"winbatch",
Text
"winbugs",
Text
"x10",
Text
"xbase",
Text
"xml",
Text
"xml+cheetah",
Text
"xml+django",
Text
"xml+erb",
Text
"xml+evoque",
Text
"xml+genshi",
Text
"xml+jinja",
Text
"xml+kid",
Text
"xml+lasso",
Text
"xml+mako",
Text
"xml+myghty",
Text
"xml+php",
Text
"xml+ruby",
Text
"xml+smarty",
Text
"xml+spitfire",
Text
"xml+velocity",
Text
"xq",
Text
"xql",
Text
"xqm",
Text
"xquery",
Text
"xqy",
Text
"xslt",
Text
"xten",
Text
"xtend",
Text
"xul+mozpreproc",
Text
"yaml",
Text
"yaml+jinja",
Text
"zephir" ]