git.iko.soy/typeable/pandoc
on master help sign in
Writers/Shared: add missing function docs

Ensure that all functions in the module have a haddock comment.

commitaff582d9b5bcd0653bfb11f13c1fec7c16a34aa7 authorAlbert Krewinkel <albert@zeitkraut.de> dateWed 29 Jul 2020, 18:32 (6 years ago) parent857eb46
1 file changed+21−7
src/Text/Pandoc/Writers/Shared.hs+21−7
src/Text/Pandoc/Writers/Shared.hs+21−7
@@ -78,8 +78,8 @@ metaToContext opts blockWriter inlineWriter meta =
7878-- | Like 'metaToContext, but does not include variables and is
7979-- not sensitive to 'writerTemplate'.
8080metaToContext' :: (Monad m, TemplateTarget a)
81− => ([Block] -> m (Doc a))
82− -> ([Inline] -> m (Doc a))
81+ => ([Block] -> m (Doc a)) -- ^ block writer
82+ -> ([Inline] -> m (Doc a)) -- ^ inline writer
8383 -> Meta
8484 -> m (Context a)
8585metaToContext' blockWriter inlineWriter (Meta metamap) =
@@ -98,9 +98,11 @@ addVariablesToContext opts c1 =
9898 mempty
9999 jsonrep = UTF8.toText $ BL.toStrict $ encode $ toJSON c1
100100
101+-- | Converts a 'MetaValue' into a doctemplate 'Val', using the given
102+-- converter functions.
101103metaValueToVal :: (Monad m, TemplateTarget a)
102− => ([Block] -> m (Doc a))
103− -> ([Inline] -> m (Doc a))
104+ => ([Block] -> m (Doc a)) -- ^ block writer
105+ -> ([Inline] -> m (Doc a)) -- ^ inline writer
104106 -> MetaValue
105107 -> m (Val a)
106108metaValueToVal blockWriter inlineWriter (MetaMap metamap) =
@@ -145,7 +147,7 @@ defField field val (Context m) =
145147 where
146148 f _newval oldval = oldval
147149
148−-- Produce an HTML tag with the given pandoc attributes.
150+-- | Produce an HTML tag with the given pandoc attributes.
149151tagWithAttrs :: HasChars a => T.Text -> Attr -> Doc a
150152tagWithAttrs tag (ident,classes,kvs) = hsep
151153 ["<" <> text (T.unpack tag)
@@ -159,18 +161,21 @@ tagWithAttrs tag (ident,classes,kvs) = hsep
159161 doubleQuotes (text $ T.unpack (escapeStringForXML v))) kvs)
160162 ] <> ">"
161163
164+-- | Returns 'True' iff the argument is an inline 'Math' element of type
165+-- 'DisplayMath'.
162166isDisplayMath :: Inline -> Bool
163167isDisplayMath (Math DisplayMath _) = True
164168isDisplayMath (Span _ [Math DisplayMath _]) = True
165169isDisplayMath _ = False
166170
171+-- | Remove leading and trailing 'Space' and 'SoftBreak' elements.
167172stripLeadingTrailingSpace :: [Inline] -> [Inline]
168173stripLeadingTrailingSpace = go . reverse . go . reverse
169174 where go (Space:xs) = xs
170175 go (SoftBreak:xs) = xs
171176 go xs = xs
172177
173−-- Put display math in its own block (for ODT/DOCX).
178+-- | Put display math in its own block (for ODT/DOCX).
174179fixDisplayMath :: Block -> Block
175180fixDisplayMath (Plain lst)
176181 | any isDisplayMath lst && not (all isDisplayMath lst) =
@@ -192,6 +197,8 @@ fixDisplayMath (Para lst)
192197 not (isDisplayMath x || isDisplayMath y)) lst
193198fixDisplayMath x = x
194199
200+-- | Converts a Unicode character into the ASCII sequence used to
201+-- represent the character in "smart" Markdown.
195202unsmartify :: WriterOptions -> T.Text -> T.Text
196203unsmartify opts = T.concatMap $ \c -> case c of
197204 '\8217' -> "'"
@@ -366,6 +373,8 @@ lookupMetaString key meta =
366373 Just (MetaBool b) -> T.pack (show b)
367374 _ -> ""
368375
376+-- | Tries to convert a character into a unicode superscript version of
377+-- the character.
369378toSuperscript :: Char -> Maybe Char
370379toSuperscript '1' = Just '\x00B9'
371380toSuperscript '2' = Just '\x00B2'
@@ -381,6 +390,8 @@ toSuperscript c
381390 | isSpace c = Just c
382391 | otherwise = Nothing
383392
393+-- | Tries to convert a character into a unicode subscript version of
394+-- the character.
384395toSubscript :: Char -> Maybe Char
385396toSubscript '+' = Just '\x208A'
386397toSubscript '-' = Just '\x208B'
@@ -402,7 +413,8 @@ toTableOfContents opts bs =
402413 $ map (sectionToListItem opts)
403414 $ makeSections (writerNumberSections opts) Nothing bs
404415
405−-- | Converts an Element to a list item for a table of contents,
416+-- | Converts a section Div to a list item for a table of contents;
417+-- returns an empty list if the given block is not a section Div.
406418sectionToListItem :: WriterOptions -> Block -> [Block]
407419sectionToListItem opts (Div (ident,_,_)
408420 (Header lev (_,classes,kvs) ils : subsecs))
@@ -422,6 +434,8 @@ sectionToListItem opts (Div (ident,_,_)
422434 listContents = filter (not . null) $ map (sectionToListItem opts) subsecs
423435sectionToListItem _ _ = []
424436
437+-- | Returns 'True' iff the list of blocks has a @'Plain'@ as its last
438+-- element.
425439endsWithPlain :: [Block] -> Bool
426440endsWithPlain xs =
427441 case lastMay xs of