{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
module Text.Pandoc.Writers.Man ( writeMan ) where
import Control.Monad ( liftM, zipWithM, forM )
import Control.Monad.State.Strict ( StateT, gets, modify, evalStateT )
import Control.Monad.Trans (MonadTrans(lift))
import Data.List (intersperse)
import Data.List.NonEmpty (nonEmpty)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import Text.Pandoc.Builder (deleteMeta)
import Text.Pandoc.Class.PandocMonad (PandocMonad, report)
import Text.Pandoc.Definition
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.Math
import Text.Pandoc.Writers.Shared
import Text.Pandoc.Writers.Roff
import Text.Printf (printf)
writeMan :: PandocMonad m => WriterOptions -> Pandoc -> m Text
writeMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> m Text
writeMan WriterOptions
opts Pandoc
document =
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> StateT WriterState m Text
pandocToMan WriterOptions
opts Pandoc
document) WriterState
defaultWriterState
pandocToMan :: PandocMonad m => WriterOptions -> Pandoc -> StateT WriterState m Text
pandocToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Pandoc -> StateT WriterState m Text
pandocToMan WriterOptions
opts (Pandoc Meta
meta [Block]
blocks) = do
let colwidth :: Maybe Int
colwidth = if WriterOptions -> WrapOption
writerWrapText WriterOptions
opts 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
opts
else forall a. Maybe a
Nothing
Doc Text
titleText <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts forall a b. (a -> b) -> a -> b
$ Meta -> [Inline]
docTitle Meta
meta
let title' :: Text
title' = forall a. HasChars a => Maybe Int -> Doc a -> a
render forall a. Maybe a
Nothing Doc Text
titleText
let setFieldsFromTitle :: Context Text -> Context Text
setFieldsFromTitle =
case (Char -> Bool) -> Text -> (Text, Text)
T.break (forall a. Eq a => a -> a -> Bool
== Char
' ') Text
title' of
(Text
cmdName, Text
rest) -> case (Char -> Bool) -> Text -> (Text, Text)
T.break (forall a. Eq a => a -> a -> Bool
==Char
'(') Text
cmdName of
(Text
xs, Text
ys) | Text
"(" Text -> Text -> Bool
`T.isPrefixOf` Text
ys
Bool -> Bool -> Bool
&& Text
")" Text -> Text -> Bool
`T.isSuffixOf` Text
ys ->
forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"title" Text
xs forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"section" (Text -> Text
T.init forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.drop Int
1 Text
ys) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
case Text -> Text -> [Text]
T.splitOn Text
"|" Text
rest of
(Text
ft:[Text]
hds) ->
forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"footer" (Text -> Text
T.strip Text
ft) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"header"
(Text -> Text
T.strip forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat [Text]
hds)
[] -> forall a. a -> a
id
(Text, Text)
_ -> forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"title" Text
title'
Context Text
metadata <- forall (m :: * -> *) a.
(Monad m, TemplateTarget a) =>
WriterOptions
-> ([Block] -> m (Doc a))
-> ([Inline] -> m (Doc a))
-> Meta
-> m (Context a)
metaToContext WriterOptions
opts
(forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts)
(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 =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts)
forall a b. (a -> b) -> a -> b
$ forall a. HasMeta a => Text -> a -> a
deleteMeta Text
"title" Meta
meta
Doc Text
body <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts [Block]
blocks
[[Block]]
notes <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> [[Block]]
stNotes
Doc Text
notes' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [[Block]] -> StateT WriterState m (Doc Text)
notesToMan WriterOptions
opts (forall a. [a] -> [a]
reverse [[Block]]
notes)
let main :: Doc Text
main = Doc Text
body forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
notes' forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => String -> Doc a
text String
""
Bool
hasTables <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> Bool
stHasTables
let context :: Context Text
context = forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"body" Doc Text
main
forall a b. (a -> b) -> a -> b
$ Context Text -> Context Text
setFieldsFromTitle
forall a b. (a -> b) -> a -> b
$ forall a b. ToContext a b => Text -> b -> Context a -> Context a
defField Text
"has-tables" Bool
hasTables
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
opts of
Maybe (Template Text)
Nothing -> Doc Text
main
Just Template Text
tpl -> forall a b.
(TemplateTarget a, ToContext a b) =>
Template a -> b -> Doc a
renderTemplate Template Text
tpl Context Text
context
escString :: WriterOptions -> Text -> Text
escString :: WriterOptions -> Text -> Text
escString WriterOptions
opts = EscapeMode -> Text -> Text
escapeString (if WriterOptions -> Bool
writerPreferAscii WriterOptions
opts
then EscapeMode
AsciiOnly
else EscapeMode
AllowUTF8)
notesToMan :: PandocMonad m => WriterOptions -> [[Block]] -> StateT WriterState m (Doc Text)
notesToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [[Block]] -> StateT WriterState m (Doc Text)
notesToMan WriterOptions
opts [[Block]]
notes =
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Block]]
notes
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
else (forall a. HasChars a => String -> Doc a
text String
".SH NOTES" forall a. Doc a -> Doc a -> Doc a
$$) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [Doc a] -> Doc a
vcat 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 =>
WriterOptions -> Int -> [Block] -> StateT WriterState m (Doc Text)
noteToMan WriterOptions
opts) [Int
1..] [[Block]]
notes
noteToMan :: PandocMonad m => WriterOptions -> Int -> [Block] -> StateT WriterState m (Doc Text)
noteToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Int -> [Block] -> StateT WriterState m (Doc Text)
noteToMan WriterOptions
opts Int
num [Block]
note = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts [Block]
note
let marker :: Doc Text
marker = forall a. Doc a
cr forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => String -> Doc a
text String
".SS " forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Doc a -> Doc a
brackets (forall a. HasChars a => String -> Doc a
text (forall a. Show a => a -> String
show Int
num))
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Doc Text
marker forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
contents
blockToMan :: PandocMonad m
=> WriterOptions
-> Block
-> StateT WriterState m (Doc Text)
blockToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> StateT WriterState m (Doc Text)
blockToMan WriterOptions
opts (Div Attr
_ [Block]
bs) = forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts [Block]
bs
blockToMan WriterOptions
opts (Plain [Inline]
inlines) =
Doc Text -> Doc Text
splitSentences forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
inlines
blockToMan WriterOptions
opts (Para [Inline]
inlines) = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
inlines
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => String -> Doc a
text String
".PP" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text -> Doc Text
splitSentences Doc Text
contents
blockToMan WriterOptions
opts (LineBlock [[Inline]]
lns) =
forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> StateT WriterState m (Doc Text)
blockToMan WriterOptions
opts forall a b. (a -> b) -> a -> b
$ [[Inline]] -> Block
linesToPara [[Inline]]
lns
blockToMan WriterOptions
_ b :: Block
b@(RawBlock Format
f Text
str)
| Format
f forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"man" = 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
$ Block -> LogMessage
BlockNotRendered Block
b
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
blockToMan WriterOptions
_ Block
HorizontalRule = 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
".PP" forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
" * * * * *"
blockToMan WriterOptions
opts (Header Int
level Attr
_ [Inline]
inlines) = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
inlines
let heading :: Text
heading = case Int
level of
Int
1 -> Text
".SH "
Int
_ -> Text
".SS "
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. IsString a => Doc a -> Doc a
nowrap forall a b. (a -> b) -> a -> b
$ forall a. HasChars a => a -> Doc a
literal Text
heading forall a. Semigroup a => a -> a -> a
<> Doc Text
contents
blockToMan WriterOptions
opts (CodeBlock 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 Text
".IP" forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => a -> Doc a
literal Text
".EX" forall a. Doc a -> Doc a -> Doc a
$$
((case Text -> Maybe (Char, Text)
T.uncons Text
str of
Just (Char
'.',Text
_) -> forall a. HasChars a => a -> Doc a
literal Text
"\\&"
Maybe (Char, Text)
_ -> forall a. Monoid a => a
mempty) forall a. Semigroup a => a -> a -> a
<>
forall a. HasChars a => a -> Doc a
literal (WriterOptions -> Text -> Text
escString WriterOptions
opts Text
str)) forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => a -> Doc a
literal Text
".EE"
blockToMan WriterOptions
opts (BlockQuote [Block]
blocks) = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts [Block]
blocks
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
".RS" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
contents forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
".RE"
blockToMan WriterOptions
opts (Table Attr
_ Caption
blkCapt [ColSpec]
specs TableHead
thead [TableBody]
tbody TableFoot
tfoot) =
let ([Inline]
caption, [Alignment]
alignments, [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
aligncode :: Alignment -> a
aligncode Alignment
AlignLeft = a
"l"
aligncode Alignment
AlignRight = a
"r"
aligncode Alignment
AlignCenter = a
"c"
aligncode Alignment
AlignDefault = a
"l"
in do
Doc Text
caption' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
caption
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
st -> WriterState
st{ stHasTables :: Bool
stHasTables = Bool
True }
let iwidths :: [Text]
iwidths = if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Eq a => a -> a -> Bool
== Double
0) [Double]
widths
then forall a. a -> [a]
repeat Text
""
else forall a b. (a -> b) -> [a] -> [b]
map (String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. PrintfType r => String -> r
printf String
"w(%0.1fn)" forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Double
70 forall a. Num a => a -> a -> a
*)) [Double]
widths
let coldescriptions :: Doc Text
coldescriptions = forall a. HasChars a => a -> Doc a
literal forall a b. (a -> b) -> a -> b
$ [Text] -> Text
T.unwords
(forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Alignment
align Text
width -> forall {a}. IsString a => Alignment -> a
aligncode Alignment
align forall a. Semigroup a => a -> a -> a
<> Text
width)
[Alignment]
alignments [Text]
iwidths) forall a. Semigroup a => a -> a -> a
<> Text
"."
[Doc Text]
colheadings <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts) [[Block]]
headers
let makeRow :: [Doc a] -> Doc a
makeRow [Doc a]
cols = forall a. HasChars a => a -> Doc a
literal a
"T{" forall a. Doc a -> Doc a -> Doc a
$$
forall a. [Doc a] -> Doc a
vcat (forall a. a -> [a] -> [a]
intersperse (forall a. HasChars a => a -> Doc a
literal a
"T}@T{") [Doc a]
cols) forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => a -> Doc a
literal a
"T}"
let colheadings' :: Doc Text
colheadings' = if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Block]]
headers
then forall a. Doc a
empty
else forall {a}. HasChars a => [Doc a] -> Doc a
makeRow [Doc Text]
colheadings forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => Char -> Doc a
char Char
'_'
[Doc Text]
body <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\[[Block]]
row -> do
[Doc Text]
cols <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts) [[Block]]
row
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall {a}. HasChars a => [Doc a] -> Doc a
makeRow [Doc Text]
cols) [[[Block]]]
rows
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
".PP" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
caption' forall a. Doc a -> Doc a -> Doc a
$$
forall a. HasChars a => a -> Doc a
literal Text
".TS" forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
"tab(@);" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
coldescriptions forall a. Doc a -> Doc a -> Doc a
$$
Doc Text
colheadings' forall a. Doc a -> Doc a -> Doc a
$$ forall a. [Doc a] -> Doc a
vcat [Doc Text]
body forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
".TE"
blockToMan WriterOptions
opts (BulletList [[Block]]
items) = do
[Doc Text]
contents <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
bulletListItemToMan WriterOptions
opts) [[Block]]
items
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. [Doc a] -> Doc a
vcat [Doc Text]
contents)
blockToMan WriterOptions
opts (OrderedList ListAttributes
attribs [[Block]]
items) = do
let markers :: [Text]
markers = forall a. Int -> [a] -> [a]
take (forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Block]]
items) forall a b. (a -> b) -> a -> b
$ ListAttributes -> [Text]
orderedListMarkers ListAttributes
attribs
let indent :: Int
indent = Int
1 forall a. Num a => a -> a -> a
+ forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum (forall a. [a] -> Maybe (NonEmpty a)
nonEmpty (forall a b. (a -> b) -> [a] -> [b]
map Text -> Int
T.length [Text]
markers))
[Doc Text]
contents <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(Text
num, [Block]
item) -> forall (m :: * -> *).
PandocMonad m =>
WriterOptions
-> Text -> Int -> [Block] -> StateT WriterState m (Doc Text)
orderedListItemToMan WriterOptions
opts Text
num Int
indent [Block]
item) forall a b. (a -> b) -> a -> b
$
forall a b. [a] -> [b] -> [(a, b)]
zip [Text]
markers [[Block]]
items
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. [Doc a] -> Doc a
vcat [Doc Text]
contents)
blockToMan WriterOptions
opts (DefinitionList [([Inline], [[Block]])]
items) = do
[Doc Text]
contents <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions
-> ([Inline], [[Block]]) -> StateT WriterState m (Doc Text)
definitionListItemToMan WriterOptions
opts) [([Inline], [[Block]])]
items
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. [Doc a] -> Doc a
vcat [Doc Text]
contents)
blockToMan WriterOptions
opts (Figure Attr
attr Caption
capt [Block]
body) = do
forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> StateT WriterState m (Doc Text)
blockToMan WriterOptions
opts (Attr -> Caption -> [Block] -> Block
figureDiv Attr
attr Caption
capt [Block]
body)
bulletListItemToMan :: PandocMonad m => WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
bulletListItemToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
bulletListItemToMan WriterOptions
_ [] = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
bulletListItemToMan WriterOptions
opts (Para [Inline]
first:[Block]
rest) =
forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
bulletListItemToMan WriterOptions
opts ([Inline] -> Block
Plain [Inline]
firstforall a. a -> [a] -> [a]
:[Block]
rest)
bulletListItemToMan WriterOptions
opts (Plain [Inline]
first:[Block]
rest) = do
Doc Text
first' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> StateT WriterState m (Doc Text)
blockToMan WriterOptions
opts ([Inline] -> Block
Plain [Inline]
first)
Doc Text
rest' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts [Block]
rest
let first'' :: Doc Text
first'' = forall a. HasChars a => a -> Doc a
literal Text
".IP \\[bu] 2" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
first'
let rest'' :: Doc Text
rest'' = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Block]
rest
then forall a. Doc a
empty
else forall a. HasChars a => a -> Doc a
literal Text
".RS 2" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
rest' forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
".RE"
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc Text
first'' forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
rest'')
bulletListItemToMan WriterOptions
opts (Block
first:[Block]
rest) = do
Doc Text
first' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> StateT WriterState m (Doc Text)
blockToMan WriterOptions
opts Block
first
Doc Text
rest' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts [Block]
rest
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
"\\[bu] .RS 2" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
first' forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
rest' forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
".RE"
orderedListItemToMan :: PandocMonad m
=> WriterOptions
-> Text
-> Int
-> [Block]
-> StateT WriterState m (Doc Text)
orderedListItemToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions
-> Text -> Int -> [Block] -> StateT WriterState m (Doc Text)
orderedListItemToMan WriterOptions
_ Text
_ Int
_ [] = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
orderedListItemToMan WriterOptions
opts Text
num Int
indent (Para [Inline]
first:[Block]
rest) =
forall (m :: * -> *).
PandocMonad m =>
WriterOptions
-> Text -> Int -> [Block] -> StateT WriterState m (Doc Text)
orderedListItemToMan WriterOptions
opts Text
num Int
indent ([Inline] -> Block
Plain [Inline]
firstforall a. a -> [a] -> [a]
:[Block]
rest)
orderedListItemToMan WriterOptions
opts Text
num Int
indent (Block
first:[Block]
rest) = do
Doc Text
first' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> StateT WriterState m (Doc Text)
blockToMan WriterOptions
opts Block
first
Doc Text
rest' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts [Block]
rest
let num' :: String
num' = forall r. PrintfType r => String -> r
printf (String
"%" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show (Int
indent forall a. Num a => a -> a -> a
- Int
1) forall a. [a] -> [a] -> [a]
++ String
"s") Text
num
let first'' :: Doc Text
first'' = forall a. HasChars a => a -> Doc a
literal (Text
".IP \"" forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack String
num' forall a. Semigroup a => a -> a -> a
<> Text
"\" " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
tshow Int
indent) forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
first'
let rest'' :: Doc Text
rest'' = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Block]
rest
then forall a. Doc a
empty
else forall a. HasChars a => a -> Doc a
literal Text
".RS 4" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
rest' forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
".RE"
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Doc Text
first'' forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
rest''
definitionListItemToMan :: PandocMonad m
=> WriterOptions
-> ([Inline],[[Block]])
-> StateT WriterState m (Doc Text)
definitionListItemToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions
-> ([Inline], [[Block]]) -> StateT WriterState m (Doc Text)
definitionListItemToMan WriterOptions
opts ([Inline]
label, [[Block]]
defs) = do
Doc Text
labelText <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
label
Doc Text
contents <- if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Block]]
defs
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
empty
else forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall a. [Doc a] -> Doc a
vcat forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [[Block]]
defs forall a b. (a -> b) -> a -> b
$ \case
(Block
x:[Block]
xs) -> do
Doc Text
first' <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> StateT WriterState m (Doc Text)
blockToMan WriterOptions
opts forall a b. (a -> b) -> a -> b
$
case Block
x of
Para [Inline]
y -> [Inline] -> Block
Plain [Inline]
y
Block
_ -> Block
x
Doc Text
rest' <- forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall a. [Doc a] -> Doc a
vcat forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM
(\Block
item -> forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> StateT WriterState m (Doc Text)
blockToMan WriterOptions
opts Block
item) [Block]
xs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Doc Text
first' forall a. Doc a -> Doc a -> Doc a
$$
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Block]
xs
then forall a. Doc a
empty
else forall a. HasChars a => a -> Doc a
literal Text
".RS" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
rest' forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
".RE"
[] -> forall (m :: * -> *) a. Monad m => a -> m a
return 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 => a -> Doc a
literal Text
".TP" forall a. Doc a -> Doc a -> Doc a
$$ forall a. IsString a => Doc a -> Doc a
nowrap Doc Text
labelText forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
contents
blockListToMan :: PandocMonad m
=> WriterOptions
-> [Block]
-> StateT WriterState m (Doc Text)
blockListToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Block] -> StateT WriterState m (Doc Text)
blockListToMan WriterOptions
opts [Block]
blocks =
forall a. [Doc a] -> Doc a
vcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Block -> StateT WriterState m (Doc Text)
blockToMan WriterOptions
opts) ([Block] -> [Block]
go [Block]
blocks)
where
go :: [Block] -> [Block]
go [] = []
go (h :: Block
h@Header{} : Para [Inline]
ils : [Block]
rest) = Block
h forall a. a -> [a] -> [a]
: [Inline] -> Block
Plain [Inline]
ils forall a. a -> [a] -> [a]
: [Block] -> [Block]
go [Block]
rest
go (Block
x : [Block]
xs) = Block
x forall a. a -> [a] -> [a]
: [Block] -> [Block]
go [Block]
xs
inlineListToMan :: PandocMonad m => WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [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 =>
WriterOptions -> Inline -> StateT WriterState m (Doc Text)
inlineToMan WriterOptions
opts) [Inline]
lst
inlineToMan :: PandocMonad m => WriterOptions -> Inline -> StateT WriterState m (Doc Text)
inlineToMan :: forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Inline -> StateT WriterState m (Doc Text)
inlineToMan WriterOptions
opts (Span Attr
_ [Inline]
ils) = forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
ils
inlineToMan WriterOptions
opts (Emph [Inline]
lst) =
forall a (m :: * -> *).
(HasChars a, IsString a, PandocMonad m) =>
Char -> MS m (Doc a) -> MS m (Doc a)
withFontFeature Char
'I' (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
lst)
inlineToMan WriterOptions
opts (Underline [Inline]
lst) =
forall a (m :: * -> *).
(HasChars a, IsString a, PandocMonad m) =>
Char -> MS m (Doc a) -> MS m (Doc a)
withFontFeature Char
'I' (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
lst)
inlineToMan WriterOptions
opts (Strong [Inline]
lst) =
forall a (m :: * -> *).
(HasChars a, IsString a, PandocMonad m) =>
Char -> MS m (Doc a) -> MS m (Doc a)
withFontFeature Char
'B' (forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
lst)
inlineToMan WriterOptions
opts (Strikeout [Inline]
lst) = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
lst
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
"[STRIKEOUT:" 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
']'
inlineToMan WriterOptions
opts (Superscript [Inline]
lst) = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [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
'^'
inlineToMan WriterOptions
opts (Subscript [Inline]
lst) = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [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
'~'
inlineToMan WriterOptions
opts (SmallCaps [Inline]
lst) = forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
lst
inlineToMan WriterOptions
opts (Quoted QuoteType
SingleQuote [Inline]
lst) = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [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
'\''
inlineToMan WriterOptions
opts (Quoted QuoteType
DoubleQuote [Inline]
lst) = do
Doc Text
contents <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
lst
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
"\\[lq]" forall a. Semigroup a => a -> a -> a
<> Doc Text
contents forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => a -> Doc a
literal Text
"\\[rq]"
inlineToMan WriterOptions
opts (Cite [Citation]
_ [Inline]
lst) =
forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
lst
inlineToMan WriterOptions
opts (Code Attr
_ Text
str) =
forall a (m :: * -> *).
(HasChars a, IsString a, PandocMonad m) =>
Char -> MS m (Doc a) -> MS m (Doc a)
withFontFeature Char
'C' (forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. HasChars a => a -> Doc a
literal forall a b. (a -> b) -> a -> b
$ WriterOptions -> Text -> Text
escString WriterOptions
opts Text
str))
inlineToMan WriterOptions
opts (Str str :: Text
str@(Text -> Maybe (Char, Text)
T.uncons -> Just (Char
'.',Text
_))) =
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Text -> Doc a
afterBreak Text
"\\&" forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => a -> Doc a
literal (WriterOptions -> Text -> Text
escString WriterOptions
opts Text
str)
inlineToMan WriterOptions
opts (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 forall a b. (a -> b) -> a -> b
$ WriterOptions -> Text -> Text
escString WriterOptions
opts Text
str
inlineToMan WriterOptions
opts (Math MathType
InlineMath Text
str) =
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall (m :: * -> *).
PandocMonad m =>
MathType -> Text -> m [Inline]
texMathToInlines MathType
InlineMath Text
str) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts
inlineToMan WriterOptions
opts (Math MathType
DisplayMath Text
str) = do
Doc Text
contents <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall (m :: * -> *).
PandocMonad m =>
MathType -> Text -> m [Inline]
texMathToInlines MathType
DisplayMath Text
str) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Doc a
cr forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => a -> Doc a
literal Text
".RS" forall a. Doc a -> Doc a -> Doc a
$$ Doc Text
contents forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
".RE"
inlineToMan WriterOptions
_ il :: Inline
il@(RawInline Format
f Text
str)
| Format
f forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"man" = 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
inlineToMan WriterOptions
_ Inline
LineBreak = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
forall a. Doc a
cr forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => a -> Doc a
literal Text
".PD 0" forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
".P" forall a. Doc a -> Doc a -> Doc a
$$ forall a. HasChars a => a -> Doc a
literal Text
".PD" forall a. Semigroup a => a -> a -> a
<> forall a. Doc a
cr
inlineToMan WriterOptions
_ Inline
SoftBreak = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
space
inlineToMan WriterOptions
_ Inline
Space = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Doc a
space
inlineToMan WriterOptions
opts (Link Attr
_ [Inline]
txt (Text
src, Text
_))
| Bool -> Bool
not (Text -> Bool
isURI Text
src) = forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
txt
| Bool
otherwise = do
Doc Text
linktext <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> [Inline] -> StateT WriterState m (Doc Text)
inlineListToMan WriterOptions
opts [Inline]
txt
let srcSuffix :: Text
srcSuffix = forall a. a -> Maybe a -> a
fromMaybe Text
src (Text -> Text -> Maybe Text
T.stripPrefix Text
"mailto:" Text
src)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case [Inline]
txt of
[Str Text
s]
| Text -> Text
escapeURI Text
s forall a. Eq a => a -> a -> Bool
== Text
srcSuffix ->
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
srcSuffix forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Char -> Doc a
char Char
'>'
[Inline]
_ -> Doc Text
linktext forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => a -> Doc a
literal Text
" (" forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => a -> Doc a
literal Text
src forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Char -> Doc a
char Char
')'
inlineToMan WriterOptions
opts (Image Attr
attr [Inline]
alternate (Text
source, Text
tit)) = do
let txt :: [Inline]
txt = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Inline]
alternate Bool -> Bool -> Bool
|| ([Inline]
alternate forall a. Eq a => a -> a -> Bool
== [Text -> Inline
Str Text
""]) Bool -> Bool -> Bool
||
([Inline]
alternate forall a. Eq a => a -> a -> Bool
== [Text -> Inline
Str Text
source])
then [Text -> Inline
Str Text
"image"]
else [Inline]
alternate
Doc Text
linkPart <- forall (m :: * -> *).
PandocMonad m =>
WriterOptions -> Inline -> StateT WriterState m (Doc Text)
inlineToMan WriterOptions
opts (Attr -> [Inline] -> (Text, Text) -> Inline
Link Attr
attr [Inline]
txt (Text
source, Text
tit))
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
<> forall a. HasChars a => a -> Doc a
literal Text
"IMAGE: " forall a. Semigroup a => a -> a -> a
<> Doc Text
linkPart forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Char -> Doc a
char Char
']'
inlineToMan WriterOptions
_ (Note [Block]
contents) = do
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify forall a b. (a -> b) -> a -> b
$ \WriterState
st -> WriterState
st{ stNotes :: [[Block]]
stNotes = [Block]
contents forall a. a -> [a] -> [a]
: WriterState -> [[Block]]
stNotes WriterState
st }
[[Block]]
notes <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets WriterState -> [[Block]]
stNotes
let ref :: Text
ref = forall a. Show a => a -> Text
tshow (forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Block]]
notes)
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
<> forall a. HasChars a => a -> Doc a
literal Text
ref forall a. Semigroup a => a -> a -> a
<> forall a. HasChars a => Char -> Doc a
char Char
']'