{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Writers.Texinfo ( writeTexinfo ) where
import Control.Monad (zipWithM)
import Control.Monad.Except (throwError)
import Control.Monad.State.Strict
( StateT, MonadState(get), gets, modify, evalStateT )
import Data.Char (chr, ord, isAlphaNum)
import Data.List (maximumBy, transpose, foldl')
import Data.List.NonEmpty (nonEmpty)
import Data.Ord (comparing)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import Network.URI (unEscapeString)
import System.FilePath
import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
import Text.Pandoc.Definition
import Text.Pandoc.Error
import Text.Pandoc.ImageSize
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.DocLayout
import Text.Pandoc.Shared
import Text.Pandoc.URI
import Text.Pandoc.Templates (renderTemplate)
import Text.Pandoc.Writers.Shared
import Text.Printf (printf)
data WriterState =
WriterState { WriterState -> Bool
stStrikeout :: Bool
, WriterState -> Bool
stEscapeComma :: Bool
, WriterState -> Set Text
stIdentifiers :: Set.Set Text
, WriterState -> WriterOptions
stOptions :: WriterOptions
}
type TI m = StateT WriterState m
writeTexinfo :: PandocMonad m => WriterOptions -> Pandoc -> m Text
writeTexinfo :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> m Text
writeTexinfo WriterOptions
options Pandoc
document =
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> TI m Text
pandocToTexinfo WriterOptions
options forall a b. (a -> b) -> a -> b
$ Pandoc -> Pandoc
wrapTop Pandoc
document)
WriterState { stStrikeout :: Bool
stStrikeout = Bool
False, stEscapeComma :: Bool
stEscapeComma = Bool
False,
stIdentifiers :: Set Text
stIdentifiers = forall a. Set a
Set.empty, stOptions :: WriterOptions
stOptions = WriterOptions
options}
wrapTop :: Pandoc -> Pandoc
wrapTop :: Pandoc -> Pandoc
wrapTop (Pandoc Meta
meta [Block]
blocks) =
Meta -> [Block] -> Pandoc
Pandoc Meta
meta (Int -> Attr -> [Inline] -> Block
Header Int
0 Attr
nullAttr (Meta -> [Inline]
docTitle Meta
meta) forall a. a -> [a] -> [a]
: [Block]
blocks)
pandocToTexinfo :: PandocMonad m => WriterOptions -> Pandoc -> TI m Text
pandocToTexinfo :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> TI m Text
pandocToTexinfo WriterOptions
options (Pandoc Meta
meta [Block]
blocks) = do
let titlePage :: Bool
titlePage = Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall (t :: * -> *) a. Foldable t => t a -> Bool
null
forall a b. (a -> b) -> a -> b
$ Meta -> [Inline]
docTitle Meta
meta forall a. a -> [a] -> [a]
: Meta -> [Inline]
docDate Meta
meta forall a. a -> [a] -> [a]
: Meta -> [[Inline]]
docAuthors Meta
meta
let colwidth :: Maybe Int
colwidth = if WriterOptions -> WrapOption
writerWrapText WriterOptions
options forall a. Eq a => a -> a -> Bool
== WrapOption
WrapAuto
then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ WriterOptions -> Int
writerColumns WriterOptions
options
else forall a. Maybe a
Nothing
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
options
forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo
(forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Doc a -> Doc a
chomp forall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo)
Meta
meta
Doc Text
body <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
blocks
WriterState
st <- forall s (m :: * -> *). MonadState s m => m s
get
let context :: Context Text
context = forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"body" Doc 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
options)
forall a b. (a -> b) -> a -> b
$ forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"titlepage" Bool
titlePage
forall a b. (a -> b) -> a -> b
$ forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"strikeout" (WriterState -> Bool
stStrikeout WriterState
st) Context Text
metadata
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => Maybe Int -> Doc a -> a
render Maybe Int
colwidth forall a b. (a -> b) -> a -> b
$
case WriterOptions -> Maybe (Template Text)
writerTemplate WriterOptions
options of
Maybe (Template Text)
Nothing -> Doc Text
body
Just Template Text
tpl -> forall a b.
(TemplateTarget a, ToContext a b) =>
Template a -> b -> Doc a
renderTemplate Template Text
tpl Context Text
context
stringToTexinfo :: Text -> Text
stringToTexinfo :: Text -> Text
stringToTexinfo Text
t
| (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isAlphaNum Text
t = Text
t
| Bool
otherwise = (Char -> Text) -> Text -> Text
T.concatMap Char -> Text
escChar Text
t
where escChar :: Char -> Text
escChar Char
'{' = Text
"@{"
escChar Char
'}' = Text
"@}"
escChar Char
'@' = Text
"@@"
escChar Char
'\160' = Text
"@ "
escChar Char
'\x2014' = Text
"---"
escChar Char
'\x2013' = Text
"--"
escChar Char
'\x2026' = Text
"@dots{}"
escChar Char
'\x2019' = Text
"'"
escChar Char
c = Char -> Text
T.singleton Char
c
escapeCommas :: PandocMonad m => TI m (Doc Text) -> TI m (Doc Text)
escapeCommas :: forall (m :: * -> *).
PandocMonad m =>
TI m (Doc Text) -> TI m (Doc Text)
escapeCommas TI m (Doc Text)
parser = do
Bool
oldEscapeComma <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Bool
stEscapeComma
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
st -> WriterState
st{ stEscapeComma :: Bool
stEscapeComma = Bool
True }
Doc Text
res <- TI m (Doc Text)
parser
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
st -> WriterState
st{ stEscapeComma :: Bool
stEscapeComma = Bool
oldEscapeComma }
forall (m :: * -> *) a. Monad m => a -> m a
return Doc Text
res
inCmd :: Text -> Doc Text -> Doc Text
inCmd :: Text -> Doc Text -> Doc Text
inCmd Text
cmd Doc Text
contents = forall a. HasChars a => Char -> Doc a
char Char
'@' forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => a -> Doc a
literal Text
cmd forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Doc a -> Doc a
braces Doc Text
contents
blockToTexinfo :: PandocMonad m
=> Block
-> TI m (Doc Text)
blockToTexinfo :: forall (m :: * -> *). PandocMonad m => Block -> TI m (Doc Text)
blockToTexinfo (Div Attr
_ [Block]
bs) = forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
bs
blockToTexinfo (Plain [Inline]
lst) =
forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
blockToTexinfo (Para [Inline]
lst) =
forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
blockToTexinfo (LineBlock [[Inline]]
lns) =
forall (m :: * -> *). PandocMonad m => Block -> TI m (Doc Text)
blockToTexinfo forall a b. (a -> b) -> a -> b
$ [[Inline]] -> Block
linesToPara [[Inline]]
lns
blockToTexinfo (BlockQuote [Block]
lst) = do
Doc Text
contents <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@quotation" forall a. Doc a -> Doc a -> Doc a
$$
Doc Text
contents forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end quotation"
blockToTexinfo (CodeBlock Attr
_ Text
str) =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Doc a
blankline forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@verbatim" forall a. Doc a -> Doc a -> Doc a
$$
forall a. Doc a -> Doc a
flush (forall a. HasChars a => a -> Doc a
literal Text
str) forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end verbatim" forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
blankline
blockToTexinfo b :: Block
b@(RawBlock Format
f Text
str)
| Format
f forall a. Eq a => a -> a -> Bool
== Format
"texinfo" = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Doc a
literal Text
str
| Format
f forall a. Eq a => a -> a -> Bool
== Format
"latex" Bool -> Bool -> Bool
|| Format
f forall a. Eq a => a -> a -> Bool
== Format
"tex" =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@tex" forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
str forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end tex"
| Bool
otherwise = do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Block -> LogMessage
BlockNotRendered Block
b
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
blockToTexinfo (BulletList [[Block]]
lst) = do
[Doc Text]
items <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
listItemToTexinfo [[Block]]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@itemize" forall a. Doc a -> Doc a -> Doc a
$$
forall a. [Doc a] -> Doc a
vcat [Doc Text]
items forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end itemize" forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
blankline
blockToTexinfo (OrderedList (Int
start, ListNumberStyle
numstyle, ListNumberDelim
_) [[Block]]
lst) = do
[Doc Text]
items <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
listItemToTexinfo [[Block]]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@enumerate " forall a. Semigroup a => a -> a -> a
<> Doc Text
exemplar forall a. Doc a -> Doc a -> Doc a
$$
forall a. [Doc a] -> Doc a
vcat [Doc Text]
items forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end enumerate" forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
blankline
where
exemplar :: Doc Text
exemplar = case ListNumberStyle
numstyle of
ListNumberStyle
DefaultStyle -> Doc Text
decimal
ListNumberStyle
Decimal -> Doc Text
decimal
ListNumberStyle
Example -> Doc Text
decimal
ListNumberStyle
UpperRoman -> Doc Text
decimal
ListNumberStyle
LowerRoman -> Doc Text
decimal
ListNumberStyle
UpperAlpha -> Doc Text
upperAlpha
ListNumberStyle
LowerAlpha -> Doc Text
lowerAlpha
decimal :: Doc Text
decimal = if Int
start forall a. Eq a => a -> a -> Bool
== Int
1
then forall a. Doc a
empty
else forall a. HasChars a => [Char] -> Doc a
text (forall a. Show a => a -> [Char]
show Int
start)
upperAlpha :: Doc Text
upperAlpha = forall a. HasChars a => [Char] -> Doc a
text [Int -> Char
chr forall a b. (a -> b) -> a -> b
$ Char -> Int
ord Char
'A' forall a. Num a => a -> a -> a
+ Int
start forall a. Num a => a -> a -> a
- Int
1]
lowerAlpha :: Doc Text
lowerAlpha = forall a. HasChars a => [Char] -> Doc a
text [Int -> Char
chr forall a b. (a -> b) -> a -> b
$ Char -> Int
ord Char
'a' forall a. Num a => a -> a -> a
+ Int
start forall a. Num a => a -> a -> a
- Int
1]
blockToTexinfo (DefinitionList [([Inline], [[Block]])]
lst) = do
[Doc Text]
items <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall (m :: * -> *).
PandocMonad m =>
([Inline], [[Block]]) -> TI m (Doc Text)
defListItemToTexinfo [([Inline], [[Block]])]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@table @asis" forall a. Doc a -> Doc a -> Doc a
$$
forall a. [Doc a] -> Doc a
vcat [Doc Text]
items forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end table" forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
blankline
blockToTexinfo Block
HorizontalRule =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@iftex" forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@bigskip@hrule@bigskip" forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end iftex" forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@ifnottex" forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text (forall a. Int -> a -> [a]
replicate Int
72 Char
'-') forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end ifnottex"
blockToTexinfo (Header Int
0 Attr
_ [Inline]
lst) = do
Doc Text
txt <- if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inline]
lst
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"Top"
else forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@node Top" forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@top " forall a. Semigroup a => a -> a -> a
<> Doc Text
txt forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
blankline
blockToTexinfo (Header Int
level (Text
ident,[Text]
_,[(Text, Text)]
_) [Inline]
lst)
| Int
level forall a. Ord a => a -> a -> Bool
< Int
1 Bool -> Bool -> Bool
|| Int
level forall a. Ord a => a -> a -> Bool
> Int
4 = forall (m :: * -> *). PandocMonad m => Block -> TI m (Doc Text)
blockToTexinfo ([Inline] -> Block
Para [Inline]
lst)
| Bool
otherwise = do
Doc Text
node <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListForNode [Inline]
lst
Doc Text
txt <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
Set Text
idsUsed <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Set Text
stIdentifiers
WriterOptions
opts <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> WriterOptions
stOptions
let id' :: Text
id' = if Text -> Bool
T.null Text
ident
then Extensions -> [Inline] -> Set Text -> Text
uniqueIdent (WriterOptions -> Extensions
writerExtensions WriterOptions
opts) [Inline]
lst Set Text
idsUsed
else Text
ident
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
st -> WriterState
st{ stIdentifiers :: Set Text
stIdentifiers = forall a. Ord a => a -> Set a -> Set a
Set.insert Text
id' Set Text
idsUsed }
Text
sec <- forall (m :: * -> *). PandocMonad m => Int -> TI m Text
seccmd Int
level
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if (Int
level forall a. Ord a => a -> a -> Bool
> Int
0) Bool -> Bool -> Bool
&& (Int
level forall a. Ord a => a -> a -> Bool
<= Int
4)
then forall a. Doc a
blankline forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => [Char] -> Doc a
text [Char]
"@node " forall a. Semigroup a => a -> a -> a
<> Doc Text
node forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => a -> Doc a
literal Text
sec forall a. Semigroup a => a -> a -> a
<> Doc Text
txt forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@anchor" forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Doc a -> Doc a
braces (forall a. HasChars a => a -> Doc a
literal forall a b. (a -> b) -> a -> b
$ Text
"#" forall a. Semigroup a => a -> a -> a
<> Text
id')
else Doc Text
txt
where
seccmd :: PandocMonad m => Int -> TI m Text
seccmd :: forall (m :: * -> *). PandocMonad m => Int -> TI m Text
seccmd Int
1 = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"@chapter "
seccmd Int
2 = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"@section "
seccmd Int
3 = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"@subsection "
seccmd Int
4 = forall (m :: * -> *) a. Monad m => a -> m a
return Text
"@subsubsection "
seccmd Int
_ = forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocSomeError Text
"illegal seccmd level"
blockToTexinfo (Table Attr
_ Caption
blkCapt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot) = do
let ([Inline]
caption, [Alignment]
aligns, [Double]
widths, [[Block]]
heads, [[[Block]]]
rows) = Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> ([Inline], [Alignment], [Double], [[Block]], [[[Block]]])
toLegacyTable Caption
blkCapt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot
Doc Text
headers <- if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Block]]
heads
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
else forall (m :: * -> *).
PandocMonad m =>
[Alignment] -> [[Block]] -> TI m (Doc Text)
tableHeadToTexinfo [Alignment]
aligns [[Block]]
heads
Doc Text
captionText <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
caption
[Doc Text]
rowsText <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
[Alignment] -> [[Block]] -> TI m (Doc Text)
tableRowToTexinfo [Alignment]
aligns) [[[Block]]]
rows
[Char]
colDescriptors <-
if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
== Double
0) [Double]
widths
then do
[[[Char]]]
cols <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> [Char]
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasChars a => Maybe Int -> Doc a -> a
render forall a. Maybe a
Nothing forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [Doc a] -> Doc a
hcat) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall (m :: * -> *). PandocMonad m => Block -> TI m (Doc Text)
blockToTexinfo)) forall a b. (a -> b) -> a -> b
$
forall a. [[a]] -> [[a]]
transpose forall a b. (a -> b) -> a -> b
$ [[Block]]
heads forall a. a -> [a] -> [a]
: [[[Block]]]
rows
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap
((\[Char]
x -> [Char]
"{"forall a. [a] -> [a] -> [a]
++[Char]
xforall a. [a] -> [a] -> [a]
++[Char]
"} ") forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Char]
"" (forall (t :: * -> *) a.
Foldable t =>
(a -> a -> Ordering) -> t a -> a
maximumBy (forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing forall (t :: * -> *) a. Foldable t => t a -> Int
length)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Maybe (NonEmpty a)
nonEmpty)
[[[Char]]]
cols
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Char]
"@columnfractions " forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall r. PrintfType r => [Char] -> r
printf [Char]
"%.2f ") [Double]
widths
let tableBody :: Doc Text
tableBody = forall a. HasChars a => [Char] -> Doc a
text ([Char]
"@multitable " forall a. [a] -> [a] -> [a]
++ [Char]
colDescriptors) forall a. Doc a -> Doc a -> Doc a
$$
Doc Text
headers forall a. Doc a -> Doc a -> Doc a
$$
forall a. [Doc a] -> Doc a
vcat [Doc Text]
rowsText forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end multitable"
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if forall a. Doc a -> Bool
isEmpty Doc Text
captionText
then Doc Text
tableBody forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
blankline
else forall a. HasChars a => [Char] -> Doc a
text [Char]
"@float Table" forall a. Doc a -> Doc a -> Doc a
$$
Doc Text
tableBody forall a. Doc a -> Doc a -> Doc a
$$
Text -> Doc Text -> Doc Text
inCmd Text
"caption" Doc Text
captionText forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end float"
blockToTexinfo (Figure Attr
_ Caption
caption [SimpleFigure Attr
attr [Inline]
figCaption (Text, Text)
tgt]) = do
let capt :: [Inline]
capt = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inline]
figCaption
then let (Caption Maybe [Inline]
_ [Block]
cblks) = Caption
caption
in [Block] -> [Inline]
blocksToInlines [Block]
cblks
else [Inline]
figCaption
Doc Text
captionText <- if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inline]
capt
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
else (forall a. HasChars a => [Char] -> Doc a
text [Char]
"@caption" forall a. Semigroup a => a -> a -> a
<>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasChars a => Doc a -> Doc a
braces forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
capt
Doc Text
img <- forall (m :: * -> *). PandocMonad m => Inline -> TI m (Doc Text)
inlineToTexinfo (Attr -> [Inline] -> (Text, Text) -> Inline
Image Attr
attr [Inline]
figCaption (Text, Text)
tgt)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@float Figure" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
img forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
captionText forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end float"
blockToTexinfo (Figure Attr
_ Caption
fCaption [
Table Attr
attr tCaption :: Caption
tCaption@(Caption Maybe [Inline]
_ [Block]
cbody) [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot]) = do
let caption :: Caption
caption = case [Block]
cbody of
[] -> Caption
fCaption
[Block]
_ -> Caption
tCaption
forall (m :: * -> *). PandocMonad m => Block -> TI m (Doc Text)
blockToTexinfo (Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table Attr
attr Caption
caption [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot)
blockToTexinfo (Figure Attr
_ (Caption Maybe [Inline]
_ [Block]
caption) [Block]
body) = do
Doc Text
captionText <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo forall a b. (a -> b) -> a -> b
$ [Block] -> [Inline]
blocksToInlines [Block]
caption
Doc Text
content <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
body
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text ([Char]
"@float" forall a. [a] -> [a] -> [a]
++ forall {a}. IsString a => [Block] -> a
floatType [Block]
body) forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
content forall a. Doc a -> Doc a -> Doc a
$$ (
if forall a. Doc a -> Bool
isEmpty Doc Text
captionText
then forall a. Doc a
empty
else Text -> Doc Text -> Doc Text
inCmd Text
"caption" Doc Text
captionText
) forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end float"
where
floatType :: [Block] -> a
floatType [SimpleFigure {}] = a
" Figure"
floatType [Table {}] = a
" Table"
floatType [Block]
_ = a
""
tableHeadToTexinfo :: PandocMonad m
=> [Alignment]
-> [[Block]]
-> TI m (Doc Text)
tableHeadToTexinfo :: forall (m :: * -> *).
PandocMonad m =>
[Alignment] -> [[Block]] -> TI m (Doc Text)
tableHeadToTexinfo = forall (m :: * -> *).
PandocMonad m =>
Text -> [Alignment] -> [[Block]] -> TI m (Doc Text)
tableAnyRowToTexinfo Text
"@headitem "
tableRowToTexinfo :: PandocMonad m
=> [Alignment]
-> [[Block]]
-> TI m (Doc Text)
tableRowToTexinfo :: forall (m :: * -> *).
PandocMonad m =>
[Alignment] -> [[Block]] -> TI m (Doc Text)
tableRowToTexinfo = forall (m :: * -> *).
PandocMonad m =>
Text -> [Alignment] -> [[Block]] -> TI m (Doc Text)
tableAnyRowToTexinfo Text
"@item "
tableAnyRowToTexinfo :: PandocMonad m
=> Text
-> [Alignment]
-> [[Block]]
-> TI m (Doc Text)
tableAnyRowToTexinfo :: forall (m :: * -> *).
PandocMonad m =>
Text -> [Alignment] -> [[Block]] -> TI m (Doc Text)
tableAnyRowToTexinfo Text
itemtype [Alignment]
aligns [[Block]]
cols =
(forall a. HasChars a => a -> Doc a
literal Text
itemtype forall a. Doc a -> Doc a -> Doc a
$$) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Doc Text
row Doc Text
item -> Doc Text
row forall a. Doc a -> Doc a -> Doc a
$$
(if forall a. Doc a -> Bool
isEmpty Doc Text
row then forall a. Doc a
empty else forall a. HasChars a => [Char] -> Doc a
text [Char]
" @tab ") forall a. Semigroup a => a -> a -> a
<> Doc Text
item) forall a. Doc a
empty forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> m c) -> [a] -> [b] -> m [c]
zipWithM forall (m :: * -> *).
PandocMonad m =>
Alignment -> [Block] -> TI m (Doc Text)
alignedBlock [Alignment]
aligns [[Block]]
cols
alignedBlock :: PandocMonad m
=> Alignment
-> [Block]
-> TI m (Doc Text)
alignedBlock :: forall (m :: * -> *).
PandocMonad m =>
Alignment -> [Block] -> TI m (Doc Text)
alignedBlock Alignment
_ = forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo
blockListToTexinfo :: PandocMonad m
=> [Block]
-> TI m (Doc Text)
blockListToTexinfo :: forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [] = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
blockListToTexinfo (Block
x:[Block]
xs) = do
Doc Text
x' <- forall (m :: * -> *). PandocMonad m => Block -> TI m (Doc Text)
blockToTexinfo Block
x
case Block
x of
Header Int
level Attr
_ [Inline]
_ -> do
let ([Block]
before, [Block]
after) = forall a. (a -> Bool) -> [a] -> ([a], [a])
break Block -> Bool
isHeaderBlock [Block]
xs
Doc Text
before' <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
before
let menu :: [Block]
menu = if Int
level forall a. Ord a => a -> a -> Bool
< Int
4
then Int -> [Block] -> [Block]
collectNodes (Int
level forall a. Num a => a -> a -> a
+ Int
1) [Block]
after
else []
[Doc Text]
lines' <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall (m :: * -> *). PandocMonad m => Block -> TI m (Doc Text)
makeMenuLine [Block]
menu
let menu' :: Doc Text
menu' = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Doc Text]
lines'
then forall a. Doc a
empty
else forall a. Doc a
blankline forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@menu" forall a. Doc a -> Doc a -> Doc a
$$
forall a. [Doc a] -> Doc a
vcat [Doc Text]
lines' forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end menu"
Doc Text
after' <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
after
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Doc Text
x' forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
before' forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
menu' forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
after'
Para [Inline]
_ -> do
Doc Text
xs' <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
xs
case [Block]
xs of
(CodeBlock Attr
_ Text
_:[Block]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Doc Text
x' forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
xs'
[Block]
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Doc Text
x' forall a. Doc a -> Doc a -> Doc a
$+$ Doc Text
xs'
Block
_ -> do
Doc Text
xs' <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
xs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Doc Text
x' forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
xs'
collectNodes :: Int -> [Block] -> [Block]
collectNodes :: Int -> [Block] -> [Block]
collectNodes Int
_ [] = []
collectNodes Int
level (Block
x:[Block]
xs) =
case Block
x of
(Header Int
hl Attr
_ [Inline]
_) | Int
hl forall a. Ord a => a -> a -> Bool
< Int
level -> []
| Int
hl forall a. Eq a => a -> a -> Bool
== Int
level -> Block
x forall a. a -> [a] -> [a]
: Int -> [Block] -> [Block]
collectNodes Int
level [Block]
xs
| Bool
otherwise -> Int -> [Block] -> [Block]
collectNodes Int
level [Block]
xs
Block
_ ->
Int -> [Block] -> [Block]
collectNodes Int
level [Block]
xs
makeMenuLine :: PandocMonad m
=> Block
-> TI m (Doc Text)
(Header Int
_ Attr
_ [Inline]
lst) = do
Doc Text
txt <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListForNode [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"* " forall a. Semigroup a => a -> a -> a
<> Doc Text
txt forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => [Char] -> Doc a
text [Char]
"::"
makeMenuLine Block
_ = forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocSomeError Text
"makeMenuLine called with non-Header block"
listItemToTexinfo :: PandocMonad m
=> [Block]
-> TI m (Doc Text)
listItemToTexinfo :: forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
listItemToTexinfo [Block]
lst = do
Doc Text
contents <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
lst
let spacer :: Doc a
spacer = case forall a. [a] -> [a]
reverse [Block]
lst of
(Para{}:[Block]
_) -> forall a. Doc a
blankline
[Block]
_ -> forall a. Doc a
empty
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@item" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
contents forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
spacer
defListItemToTexinfo :: PandocMonad m
=> ([Inline], [[Block]])
-> TI m (Doc Text)
defListItemToTexinfo :: forall (m :: * -> *).
PandocMonad m =>
([Inline], [[Block]]) -> TI m (Doc Text)
defListItemToTexinfo ([Inline]
term, [[Block]]
defs) = do
Doc Text
term' <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
term
let defToTexinfo :: [Block] -> StateT WriterState m (Doc Text)
defToTexinfo [Block]
bs = do Doc Text
d <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
bs
case forall a. [a] -> [a]
reverse [Block]
bs of
(Para{}:[Block]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Doc Text
d forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
blankline
[Block]
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return Doc Text
d
[Doc Text]
defs' <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
defToTexinfo [[Block]]
defs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@item " forall a. Semigroup a => a -> a -> a
<> Doc Text
term' forall a. Doc a -> Doc a -> Doc a
$+$ forall a. [Doc a] -> Doc a
vcat [Doc Text]
defs'
inlineListToTexinfo :: PandocMonad m
=> [Inline]
-> TI m (Doc Text)
inlineListToTexinfo :: forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst = forall a. [Doc a] -> Doc a
hcat 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 -> TI m (Doc Text)
inlineToTexinfo [Inline]
lst
inlineListForNode :: PandocMonad m
=> [Inline]
-> TI m (Doc Text)
inlineListForNode :: forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListForNode = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasChars a => a -> Doc a
literal forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
stringToTexinfo forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(Char -> Bool) -> Text -> Text
T.filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
disallowedInNode) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Walkable Inline a => a -> Text
stringify
disallowedInNode :: Char -> Bool
disallowedInNode :: Char -> Bool
disallowedInNode Char
c = Char
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ([Char]
".,:()" :: String)
inlineToTexinfo :: PandocMonad m
=> Inline
-> TI m (Doc Text)
inlineToTexinfo :: forall (m :: * -> *). PandocMonad m => Inline -> TI m (Doc Text)
inlineToTexinfo (Span Attr
_ [Inline]
lst) =
forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
inlineToTexinfo (Emph [Inline]
lst) =
Text -> Doc Text -> Doc Text
inCmd Text
"emph" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
inlineToTexinfo (Underline [Inline]
lst) =
forall (m :: * -> *). PandocMonad m => Inline -> TI m (Doc Text)
inlineToTexinfo ([Inline] -> Inline
Emph [Inline]
lst)
inlineToTexinfo (Strong [Inline]
lst) =
Text -> Doc Text -> Doc Text
inCmd Text
"strong" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
inlineToTexinfo (Strikeout [Inline]
lst) = do
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
st -> WriterState
st{ stStrikeout :: Bool
stStrikeout = Bool
True }
Doc Text
contents <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@textstrikeout{" forall a. Semigroup a => a -> a -> a
<> Doc Text
contents forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => [Char] -> Doc a
text [Char]
"}"
inlineToTexinfo (Superscript [Inline]
lst) = do
Doc Text
contents <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@sup{" forall a. Semigroup a => a -> a -> a
<> Doc Text
contents forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Char -> Doc a
char Char
'}'
inlineToTexinfo (Subscript [Inline]
lst) = do
Doc Text
contents <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@sub{" forall a. Semigroup a => a -> a -> a
<> Doc Text
contents forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Char -> Doc a
char Char
'}'
inlineToTexinfo (SmallCaps [Inline]
lst) =
Text -> Doc Text -> Doc Text
inCmd Text
"sc" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
inlineToTexinfo (Code Attr
_ Text
str) =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Doc a
literal forall a b. (a -> b) -> a -> b
$ Text
"@code{" forall a. Semigroup a => a -> a -> a
<> Text -> Text
stringToTexinfo Text
str forall a. Semigroup a => a -> a -> a
<> Text
"}"
inlineToTexinfo (Quoted QuoteType
SingleQuote [Inline]
lst) = do
Doc Text
contents <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => Char -> Doc a
char Char
'`' forall a. Semigroup a => a -> a -> a
<> Doc Text
contents forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Char -> Doc a
char Char
'\''
inlineToTexinfo (Quoted QuoteType
DoubleQuote [Inline]
lst) = do
Doc Text
contents <- forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"``" forall a. Semigroup a => a -> a -> a
<> Doc Text
contents forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => [Char] -> Doc a
text [Char]
"''"
inlineToTexinfo (Cite [Citation]
_ [Inline]
lst) =
forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
lst
inlineToTexinfo (Str Text
str) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Doc a
literal (Text -> Text
stringToTexinfo Text
str)
inlineToTexinfo (Math MathType
_ Text
str) = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Doc Text -> Doc Text
inCmd Text
"math" forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Doc a
literal Text
str
inlineToTexinfo il :: Inline
il@(RawInline Format
f Text
str)
| Format
f forall a. Eq a => a -> a -> Bool
== Format
"latex" Bool -> Bool -> Bool
|| Format
f forall a. Eq a => a -> a -> Bool
== Format
"tex" =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@tex" forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
str forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@end tex"
| Format
f forall a. Eq a => a -> a -> Bool
== Format
"texinfo" = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Doc a
literal Text
str
| Bool
otherwise = do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Inline -> LogMessage
InlineNotRendered Inline
il
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
inlineToTexinfo Inline
LineBreak = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@*" forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
cr
inlineToTexinfo Inline
SoftBreak = do
WrapOption
wrapText <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (WriterOptions -> WrapOption
writerWrapText forall b c a. (b -> c) -> (a -> b) -> a -> c
. WriterState -> WriterOptions
stOptions)
case WrapOption
wrapText of
WrapOption
WrapAuto -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
space
WrapOption
WrapNone -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
space
WrapOption
WrapPreserve -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
cr
inlineToTexinfo Inline
Space = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
space
inlineToTexinfo (Link Attr
_ [Inline]
txt (Text
src, Text
_))
| Just (Char
'#', Text
_) <- Text -> Maybe (Char, Text)
T.uncons Text
src = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
TI m (Doc Text) -> TI m (Doc Text)
escapeCommas forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
txt
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@ref" forall a. Semigroup a => a -> a -> a
<>
forall a. HasChars a => Doc a -> Doc a
braces (forall a. HasChars a => a -> Doc a
literal (Text -> Text
stringToTexinfo Text
src) forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => [Char] -> Doc a
text [Char]
"," forall a. Semigroup a => a -> a -> a
<> Doc Text
contents)
| Bool
otherwise = case [Inline]
txt of
[Str Text
x] | Text -> Text
escapeURI Text
x 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
$ forall a. HasChars a => a -> Doc a
literal forall a b. (a -> b) -> a -> b
$ Text
"@url{" forall a. Semigroup a => a -> a -> a
<> Text
x forall a. Semigroup a => a -> a -> a
<> Text
"}"
[Inline]
_ -> do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
TI m (Doc Text) -> TI m (Doc Text)
escapeCommas forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
txt
let src1 :: Text
src1 = Text -> Text
stringToTexinfo Text
src
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Doc a
literal (Text
"@uref{" forall a. Semigroup a => a -> a -> a
<> Text
src1 forall a. Semigroup a => a -> a -> a
<> Text
",") forall a. Semigroup a => a -> a -> a
<> Doc Text
contents forall a. Semigroup a => a -> a -> a
<>
forall a. HasChars a => Char -> Doc a
char Char
'}'
inlineToTexinfo (Image Attr
attr [Inline]
alternate (Text
source, Text
_)) = do
Doc Text
content <- forall (m :: * -> *).
PandocMonad m =>
TI m (Doc Text) -> TI m (Doc Text)
escapeCommas forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => [Inline] -> TI m (Doc Text)
inlineListToTexinfo [Inline]
alternate
WriterOptions
opts <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> WriterOptions
stOptions
let showDim :: Direction -> Text
showDim Direction
dim = case Direction -> Attr -> Maybe Dimension
dimension Direction
dim Attr
attr of
(Just (Pixel Integer
a)) -> WriterOptions -> Dimension -> Text
showInInch WriterOptions
opts (Integer -> Dimension
Pixel Integer
a) forall a. Semigroup a => a -> a -> a
<> Text
"in"
(Just (Percent Double
_)) -> Text
""
(Just Dimension
d) -> forall a. Show a => a -> Text
tshow Dimension
d
Maybe Dimension
Nothing -> Text
""
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Doc a
literal (Text
"@image{" forall a. Semigroup a => a -> a -> a
<> Text
base forall a. Semigroup a => a -> a -> a
<> Text
"," forall a. Semigroup a => a -> a -> a
<> Direction -> Text
showDim Direction
Width forall a. Semigroup a => a -> a -> a
<> Text
"," forall a. Semigroup a => a -> a -> a
<> Direction -> Text
showDim Direction
Height forall a. Semigroup a => a -> a -> a
<> Text
",")
forall a. Semigroup a => a -> a -> a
<> Doc Text
content forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => [Char] -> Doc a
text [Char]
"," forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => a -> Doc a
literal (Text
ext forall a. Semigroup a => a -> a -> a
<> Text
"}")
where
ext :: Text
ext = Int -> Text -> Text
T.drop Int
1 forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack forall a b. (a -> b) -> a -> b
$ [Char] -> [Char]
takeExtension [Char]
source'
base :: Text
base = [Char] -> Text
T.pack forall a b. (a -> b) -> a -> b
$ [Char] -> [Char]
dropExtension [Char]
source'
source' :: [Char]
source' = if Text -> Bool
isURI Text
source
then Text -> [Char]
T.unpack Text
source
else [Char] -> [Char]
unEscapeString forall a b. (a -> b) -> a -> b
$ Text -> [Char]
T.unpack Text
source
inlineToTexinfo (Note [Block]
contents) = do
Doc Text
contents' <- forall (m :: * -> *). PandocMonad m => [Block] -> TI m (Doc Text)
blockListToTexinfo [Block]
contents
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => [Char] -> Doc a
text [Char]
"@footnote" forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Doc a -> Doc a
braces Doc Text
contents'