2017-03-04 13:03:41 +01:00
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
|
|
|
{-# LANGUAGE TupleSections #-}
|
2014-06-18 15:32:13 -07:00
|
|
|
|
{-
|
2017-05-13 23:30:13 +02:00
|
|
|
|
Copyright (C) 2014-2015, 2017 John MacFarlane <jgm@berkeley.edu>
|
2014-06-18 15:32:13 -07:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
{- |
|
|
|
|
|
Module : Text.Pandoc.Writers.Haddock
|
2017-05-13 23:30:13 +02:00
|
|
|
|
Copyright : Copyright (C) 2014-2015,2017 John MacFarlane
|
2014-06-18 15:32:13 -07:00
|
|
|
|
License : GNU GPL, version 2 or above
|
|
|
|
|
|
|
|
|
|
Maintainer : John MacFarlane <jgm@berkeley.edu>
|
|
|
|
|
Stability : alpha
|
|
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
|
|
Conversion of 'Pandoc' documents to haddock markup.
|
|
|
|
|
|
|
|
|
|
Haddock: <http://www.haskell.org/haddock/doc/html/>
|
|
|
|
|
-}
|
|
|
|
|
module Text.Pandoc.Writers.Haddock (writeHaddock) where
|
2017-06-16 23:29:37 +02:00
|
|
|
|
import Control.Monad.State.Strict
|
2014-06-18 15:32:13 -07:00
|
|
|
|
import Data.Default
|
2017-06-10 23:39:49 +02:00
|
|
|
|
import Data.Text (Text)
|
2017-03-04 13:03:41 +01:00
|
|
|
|
import Data.List (intersperse, transpose)
|
2017-02-17 23:11:31 +01:00
|
|
|
|
import Text.Pandoc.Class (PandocMonad, report)
|
2017-03-04 13:03:41 +01:00
|
|
|
|
import Text.Pandoc.Definition
|
2017-02-17 23:11:31 +01:00
|
|
|
|
import Text.Pandoc.Logging
|
2017-03-04 13:03:41 +01:00
|
|
|
|
import Text.Pandoc.Options
|
|
|
|
|
import Text.Pandoc.Pretty
|
|
|
|
|
import Text.Pandoc.Shared
|
|
|
|
|
import Text.Pandoc.Templates (renderTemplate')
|
|
|
|
|
import Text.Pandoc.Writers.Math (texMathToInlines)
|
2017-03-21 10:20:18 +01:00
|
|
|
|
import Text.Pandoc.Writers.Shared
|
2014-06-18 15:32:13 -07:00
|
|
|
|
|
|
|
|
|
type Notes = [[Block]]
|
|
|
|
|
data WriterState = WriterState { stNotes :: Notes }
|
|
|
|
|
instance Default WriterState
|
|
|
|
|
where def = WriterState{ stNotes = [] }
|
|
|
|
|
|
|
|
|
|
-- | Convert Pandoc to Haddock.
|
2017-06-10 23:39:49 +02:00
|
|
|
|
writeHaddock :: PandocMonad m => WriterOptions -> Pandoc -> m Text
|
2016-12-03 16:15:13 +01:00
|
|
|
|
writeHaddock opts document =
|
|
|
|
|
evalStateT (pandocToHaddock opts{
|
2014-06-18 15:32:13 -07:00
|
|
|
|
writerWrapText = writerWrapText opts } document) def
|
|
|
|
|
|
|
|
|
|
-- | Return haddock representation of document.
|
2016-12-03 16:15:13 +01:00
|
|
|
|
pandocToHaddock :: PandocMonad m
|
2017-06-10 23:39:49 +02:00
|
|
|
|
=> WriterOptions -> Pandoc -> StateT WriterState m Text
|
2014-06-18 15:32:13 -07:00
|
|
|
|
pandocToHaddock opts (Pandoc meta blocks) = do
|
2015-12-11 15:58:11 -08:00
|
|
|
|
let colwidth = if writerWrapText opts == WrapAuto
|
2014-06-18 15:32:13 -07:00
|
|
|
|
then Just $ writerColumns opts
|
|
|
|
|
else Nothing
|
|
|
|
|
body <- blockListToHaddock opts blocks
|
|
|
|
|
st <- get
|
|
|
|
|
notes' <- notesToHaddock opts (reverse $ stNotes st)
|
2017-06-10 23:39:49 +02:00
|
|
|
|
let render' :: Doc -> Text
|
2014-06-18 15:32:13 -07:00
|
|
|
|
render' = render colwidth
|
|
|
|
|
let main = render' $ body <>
|
|
|
|
|
(if isEmpty notes' then empty else blankline <> notes')
|
|
|
|
|
metadata <- metaToJSON opts
|
2017-06-10 23:39:49 +02:00
|
|
|
|
(fmap render' . blockListToHaddock opts)
|
|
|
|
|
(fmap render' . inlineListToHaddock opts)
|
2014-06-18 15:32:13 -07:00
|
|
|
|
meta
|
|
|
|
|
let context = defField "body" main
|
|
|
|
|
$ metadata
|
2016-11-30 15:34:58 +01:00
|
|
|
|
case writerTemplate opts of
|
|
|
|
|
Nothing -> return main
|
2017-06-20 22:43:48 +02:00
|
|
|
|
Just tpl -> renderTemplate' tpl context
|
2014-06-18 15:32:13 -07:00
|
|
|
|
|
|
|
|
|
-- | Return haddock representation of notes.
|
2016-12-03 16:15:13 +01:00
|
|
|
|
notesToHaddock :: PandocMonad m
|
|
|
|
|
=> WriterOptions -> [[Block]] -> StateT WriterState m Doc
|
2014-06-18 15:32:13 -07:00
|
|
|
|
notesToHaddock opts notes =
|
2014-06-18 17:49:59 -07:00
|
|
|
|
if null notes
|
|
|
|
|
then return empty
|
|
|
|
|
else do
|
|
|
|
|
contents <- blockToHaddock opts $ OrderedList (1,DefaultStyle,DefaultDelim) notes
|
|
|
|
|
return $ text "#notes#" <> blankline <> contents
|
2014-06-18 15:32:13 -07:00
|
|
|
|
|
|
|
|
|
-- | Escape special characters for Haddock.
|
|
|
|
|
escapeString :: String -> String
|
|
|
|
|
escapeString = escapeStringUsing haddockEscapes
|
|
|
|
|
where haddockEscapes = backslashEscapes "\\/'`\"@<"
|
|
|
|
|
|
|
|
|
|
-- | Convert Pandoc block element to haddock.
|
2016-12-03 16:15:13 +01:00
|
|
|
|
blockToHaddock :: PandocMonad m
|
|
|
|
|
=> WriterOptions -- ^ Options
|
|
|
|
|
-> Block -- ^ Block element
|
|
|
|
|
-> StateT WriterState m Doc
|
2014-06-18 15:32:13 -07:00
|
|
|
|
blockToHaddock _ Null = return empty
|
|
|
|
|
blockToHaddock opts (Div _ ils) = do
|
|
|
|
|
contents <- blockListToHaddock opts ils
|
|
|
|
|
return $ contents <> blankline
|
|
|
|
|
blockToHaddock opts (Plain inlines) = do
|
|
|
|
|
contents <- inlineListToHaddock opts inlines
|
|
|
|
|
return $ contents <> cr
|
|
|
|
|
-- title beginning with fig: indicates figure
|
2015-04-02 21:09:08 -07:00
|
|
|
|
blockToHaddock opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
|
|
|
|
|
blockToHaddock opts (Para [Image attr alt (src,tit)])
|
2014-06-18 15:32:13 -07:00
|
|
|
|
blockToHaddock opts (Para inlines) =
|
|
|
|
|
-- TODO: if it contains linebreaks, we need to use a @...@ block
|
|
|
|
|
(<> blankline) `fmap` blockToHaddock opts (Plain inlines)
|
2016-10-13 08:46:44 +02:00
|
|
|
|
blockToHaddock opts (LineBlock lns) =
|
|
|
|
|
blockToHaddock opts $ linesToPara lns
|
2017-02-17 23:11:31 +01:00
|
|
|
|
blockToHaddock _ b@(RawBlock f str)
|
2014-06-18 15:32:13 -07:00
|
|
|
|
| f == "haddock" = do
|
|
|
|
|
return $ text str <> text "\n"
|
2017-02-17 23:11:31 +01:00
|
|
|
|
| otherwise = do
|
|
|
|
|
report $ BlockNotRendered b
|
|
|
|
|
return empty
|
2014-06-19 00:28:23 -07:00
|
|
|
|
blockToHaddock opts HorizontalRule =
|
|
|
|
|
return $ blankline <> text (replicate (writerColumns opts) '_') <> blankline
|
2014-06-18 15:32:13 -07:00
|
|
|
|
blockToHaddock opts (Header level (ident,_,_) inlines) = do
|
|
|
|
|
contents <- inlineListToHaddock opts inlines
|
|
|
|
|
let attr' = if null ident
|
|
|
|
|
then empty
|
|
|
|
|
else cr <> text "#" <> text ident <> text "#"
|
|
|
|
|
return $ nowrap (text (replicate level '=') <> space <> contents)
|
|
|
|
|
<> attr' <> blankline
|
|
|
|
|
blockToHaddock _ (CodeBlock (_,_,_) str) =
|
|
|
|
|
return $ prefixed "> " (text str) <> blankline
|
|
|
|
|
-- Nothing in haddock corresponds to block quotes:
|
|
|
|
|
blockToHaddock opts (BlockQuote blocks) =
|
|
|
|
|
blockListToHaddock opts blocks
|
|
|
|
|
-- Haddock doesn't have tables. Use haddock tables in code.
|
|
|
|
|
blockToHaddock opts (Table caption aligns widths headers rows) = do
|
|
|
|
|
caption' <- inlineListToHaddock opts caption
|
2014-06-18 18:08:41 -07:00
|
|
|
|
let caption'' = if null caption
|
2014-06-18 15:32:13 -07:00
|
|
|
|
then empty
|
|
|
|
|
else blankline <> caption' <> blankline
|
|
|
|
|
rawHeaders <- mapM (blockListToHaddock opts) headers
|
|
|
|
|
rawRows <- mapM (mapM (blockListToHaddock opts)) rows
|
|
|
|
|
let isSimple = all (==0) widths
|
|
|
|
|
let isPlainBlock (Plain _) = True
|
|
|
|
|
isPlainBlock _ = False
|
|
|
|
|
let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
|
|
|
|
|
(nst,tbl) <- case True of
|
|
|
|
|
_ | isSimple -> fmap (nest 2,) $
|
|
|
|
|
pandocTable opts (all null headers) aligns widths
|
|
|
|
|
rawHeaders rawRows
|
|
|
|
|
| not hasBlocks -> fmap (nest 2,) $
|
|
|
|
|
pandocTable opts (all null headers) aligns widths
|
|
|
|
|
rawHeaders rawRows
|
|
|
|
|
| otherwise -> fmap (id,) $
|
2017-03-21 10:20:18 +01:00
|
|
|
|
gridTable opts blockListToHaddock
|
|
|
|
|
(all null headers) aligns widths headers rows
|
2014-06-18 18:08:41 -07:00
|
|
|
|
return $ (prefixed "> " $ nst $ tbl $$ blankline $$ caption'') $$ blankline
|
2014-06-18 15:32:13 -07:00
|
|
|
|
blockToHaddock opts (BulletList items) = do
|
|
|
|
|
contents <- mapM (bulletListItemToHaddock opts) items
|
|
|
|
|
return $ cat contents <> blankline
|
2014-06-18 18:11:01 -07:00
|
|
|
|
blockToHaddock opts (OrderedList (start,_,delim) items) = do
|
|
|
|
|
let attribs = (start, Decimal, delim)
|
2014-06-18 15:32:13 -07:00
|
|
|
|
let markers = orderedListMarkers attribs
|
|
|
|
|
let markers' = map (\m -> if length m < 3
|
|
|
|
|
then m ++ replicate (3 - length m) ' '
|
|
|
|
|
else m) markers
|
|
|
|
|
contents <- mapM (\(item, num) -> orderedListItemToHaddock opts item num) $
|
|
|
|
|
zip markers' items
|
|
|
|
|
return $ cat contents <> blankline
|
|
|
|
|
blockToHaddock opts (DefinitionList items) = do
|
|
|
|
|
contents <- mapM (definitionListItemToHaddock opts) items
|
|
|
|
|
return $ cat contents <> blankline
|
|
|
|
|
|
2016-12-03 16:15:13 +01:00
|
|
|
|
pandocTable :: PandocMonad m
|
|
|
|
|
=> WriterOptions -> Bool -> [Alignment] -> [Double]
|
|
|
|
|
-> [Doc] -> [[Doc]] -> StateT WriterState m Doc
|
2014-06-18 15:32:13 -07:00
|
|
|
|
pandocTable opts headless aligns widths rawHeaders rawRows = do
|
|
|
|
|
let isSimple = all (==0) widths
|
|
|
|
|
let alignHeader alignment = case alignment of
|
|
|
|
|
AlignLeft -> lblock
|
|
|
|
|
AlignCenter -> cblock
|
|
|
|
|
AlignRight -> rblock
|
|
|
|
|
AlignDefault -> lblock
|
|
|
|
|
let numChars = maximum . map offset
|
|
|
|
|
let widthsInChars = if isSimple
|
|
|
|
|
then map ((+2) . numChars)
|
|
|
|
|
$ transpose (rawHeaders : rawRows)
|
|
|
|
|
else map
|
|
|
|
|
(floor . (fromIntegral (writerColumns opts) *))
|
|
|
|
|
widths
|
|
|
|
|
let makeRow = hcat . intersperse (lblock 1 (text " ")) .
|
|
|
|
|
(zipWith3 alignHeader aligns widthsInChars)
|
|
|
|
|
let rows' = map makeRow rawRows
|
|
|
|
|
let head' = makeRow rawHeaders
|
|
|
|
|
let maxRowHeight = maximum $ map height (head':rows')
|
|
|
|
|
let underline = cat $ intersperse (text " ") $
|
|
|
|
|
map (\width -> text (replicate width '-')) widthsInChars
|
|
|
|
|
let border = if maxRowHeight > 1
|
|
|
|
|
then text (replicate (sum widthsInChars +
|
|
|
|
|
length widthsInChars - 1) '-')
|
|
|
|
|
else if headless
|
|
|
|
|
then underline
|
|
|
|
|
else empty
|
|
|
|
|
let head'' = if headless
|
|
|
|
|
then empty
|
|
|
|
|
else border <> cr <> head'
|
|
|
|
|
let body = if maxRowHeight > 1
|
|
|
|
|
then vsep rows'
|
|
|
|
|
else vcat rows'
|
|
|
|
|
let bottom = if headless
|
|
|
|
|
then underline
|
|
|
|
|
else border
|
|
|
|
|
return $ head'' $$ underline $$ body $$ bottom
|
|
|
|
|
|
|
|
|
|
-- | Convert bullet list item (list of blocks) to haddock
|
2016-12-03 16:15:13 +01:00
|
|
|
|
bulletListItemToHaddock :: PandocMonad m
|
|
|
|
|
=> WriterOptions -> [Block] -> StateT WriterState m Doc
|
2014-06-18 15:32:13 -07:00
|
|
|
|
bulletListItemToHaddock opts items = do
|
|
|
|
|
contents <- blockListToHaddock opts items
|
|
|
|
|
let sps = replicate (writerTabStop opts - 2) ' '
|
|
|
|
|
let start = text ('-' : ' ' : sps)
|
|
|
|
|
-- remove trailing blank line if it is a tight list
|
|
|
|
|
let contents' = case reverse items of
|
|
|
|
|
(BulletList xs:_) | isTightList xs ->
|
|
|
|
|
chomp contents <> cr
|
|
|
|
|
(OrderedList _ xs:_) | isTightList xs ->
|
|
|
|
|
chomp contents <> cr
|
|
|
|
|
_ -> contents
|
|
|
|
|
return $ hang (writerTabStop opts) start $ contents' <> cr
|
|
|
|
|
|
|
|
|
|
-- | Convert ordered list item (a list of blocks) to haddock
|
2016-12-03 16:15:13 +01:00
|
|
|
|
orderedListItemToHaddock :: PandocMonad m
|
|
|
|
|
=> WriterOptions -- ^ options
|
|
|
|
|
-> String -- ^ list item marker
|
|
|
|
|
-> [Block] -- ^ list item (list of blocks)
|
|
|
|
|
-> StateT WriterState m Doc
|
2014-06-18 15:32:13 -07:00
|
|
|
|
orderedListItemToHaddock opts marker items = do
|
|
|
|
|
contents <- blockListToHaddock opts items
|
|
|
|
|
let sps = case length marker - writerTabStop opts of
|
|
|
|
|
n | n > 0 -> text $ replicate n ' '
|
2017-03-04 13:03:41 +01:00
|
|
|
|
_ -> text " "
|
2014-06-18 15:32:13 -07:00
|
|
|
|
let start = text marker <> sps
|
|
|
|
|
return $ hang (writerTabStop opts) start $ contents <> cr
|
|
|
|
|
|
|
|
|
|
-- | Convert definition list item (label, list of blocks) to haddock
|
2016-12-03 16:15:13 +01:00
|
|
|
|
definitionListItemToHaddock :: PandocMonad m
|
|
|
|
|
=> WriterOptions
|
|
|
|
|
-> ([Inline],[[Block]])
|
|
|
|
|
-> StateT WriterState m Doc
|
2014-06-18 15:32:13 -07:00
|
|
|
|
definitionListItemToHaddock opts (label, defs) = do
|
|
|
|
|
labelText <- inlineListToHaddock opts label
|
|
|
|
|
defs' <- mapM (mapM (blockToHaddock opts)) defs
|
|
|
|
|
let contents = vcat $ map (\d -> hang 4 empty $ vcat d <> cr) defs'
|
|
|
|
|
return $ nowrap (brackets labelText) <> cr <> contents <> cr
|
|
|
|
|
|
|
|
|
|
-- | Convert list of Pandoc block elements to haddock
|
2016-12-03 16:15:13 +01:00
|
|
|
|
blockListToHaddock :: PandocMonad m
|
|
|
|
|
=> WriterOptions -- ^ Options
|
|
|
|
|
-> [Block] -- ^ List of block elements
|
|
|
|
|
-> StateT WriterState m Doc
|
2014-06-18 15:32:13 -07:00
|
|
|
|
blockListToHaddock opts blocks =
|
|
|
|
|
mapM (blockToHaddock opts) blocks >>= return . cat
|
|
|
|
|
|
|
|
|
|
-- | Convert list of Pandoc inline elements to haddock.
|
2016-12-03 16:15:13 +01:00
|
|
|
|
inlineListToHaddock :: PandocMonad m
|
|
|
|
|
=> WriterOptions -> [Inline] -> StateT WriterState m Doc
|
2014-06-18 15:32:13 -07:00
|
|
|
|
inlineListToHaddock opts lst =
|
|
|
|
|
mapM (inlineToHaddock opts) lst >>= return . cat
|
|
|
|
|
|
|
|
|
|
-- | Convert Pandoc inline element to haddock.
|
2016-12-03 16:15:13 +01:00
|
|
|
|
inlineToHaddock :: PandocMonad m
|
|
|
|
|
=> WriterOptions -> Inline -> StateT WriterState m Doc
|
2014-06-18 15:32:13 -07:00
|
|
|
|
inlineToHaddock opts (Span (ident,_,_) ils) = do
|
|
|
|
|
contents <- inlineListToHaddock opts ils
|
|
|
|
|
if not (null ident) && null ils
|
|
|
|
|
then return $ "#" <> text ident <> "#"
|
|
|
|
|
else return contents
|
|
|
|
|
inlineToHaddock opts (Emph lst) = do
|
|
|
|
|
contents <- inlineListToHaddock opts lst
|
|
|
|
|
return $ "/" <> contents <> "/"
|
|
|
|
|
inlineToHaddock opts (Strong lst) = do
|
|
|
|
|
contents <- inlineListToHaddock opts lst
|
|
|
|
|
return $ "__" <> contents <> "__"
|
|
|
|
|
inlineToHaddock opts (Strikeout lst) = do
|
|
|
|
|
contents <- inlineListToHaddock opts lst
|
|
|
|
|
-- not supported in haddock, but we fake it:
|
|
|
|
|
return $ "~~" <> contents <> "~~"
|
|
|
|
|
-- not supported in haddock:
|
|
|
|
|
inlineToHaddock opts (Superscript lst) = inlineListToHaddock opts lst
|
|
|
|
|
-- not supported in haddock:
|
|
|
|
|
inlineToHaddock opts (Subscript lst) = inlineListToHaddock opts lst
|
|
|
|
|
-- not supported in haddock:
|
|
|
|
|
inlineToHaddock opts (SmallCaps lst) = inlineListToHaddock opts lst
|
|
|
|
|
inlineToHaddock opts (Quoted SingleQuote lst) = do
|
|
|
|
|
contents <- inlineListToHaddock opts lst
|
|
|
|
|
return $ "‘" <> contents <> "’"
|
|
|
|
|
inlineToHaddock opts (Quoted DoubleQuote lst) = do
|
|
|
|
|
contents <- inlineListToHaddock opts lst
|
|
|
|
|
return $ "“" <> contents <> "”"
|
|
|
|
|
inlineToHaddock _ (Code _ str) =
|
|
|
|
|
return $ "@" <> text (escapeString str) <> "@"
|
|
|
|
|
inlineToHaddock _ (Str str) = do
|
|
|
|
|
return $ text $ escapeString str
|
|
|
|
|
inlineToHaddock opts (Math mt str) = do
|
|
|
|
|
let adjust x = case mt of
|
|
|
|
|
DisplayMath -> cr <> x <> cr
|
|
|
|
|
InlineMath -> x
|
2016-12-03 16:15:13 +01:00
|
|
|
|
adjust <$> (lift (texMathToInlines mt str) >>= inlineListToHaddock opts)
|
2017-02-17 23:11:31 +01:00
|
|
|
|
inlineToHaddock _ il@(RawInline f str)
|
2014-06-18 15:32:13 -07:00
|
|
|
|
| f == "haddock" = return $ text str
|
2017-02-17 23:11:31 +01:00
|
|
|
|
| otherwise = do
|
|
|
|
|
report $ InlineNotRendered il
|
|
|
|
|
return empty
|
2014-06-18 15:32:13 -07:00
|
|
|
|
-- no line break in haddock (see above on CodeBlock)
|
2016-11-11 13:09:49 +01:00
|
|
|
|
inlineToHaddock _ LineBreak = return cr
|
2015-12-11 15:58:11 -08:00
|
|
|
|
inlineToHaddock opts SoftBreak =
|
|
|
|
|
case writerWrapText opts of
|
|
|
|
|
WrapAuto -> return space
|
|
|
|
|
WrapNone -> return space
|
|
|
|
|
WrapPreserve -> return cr
|
2014-06-18 15:32:13 -07:00
|
|
|
|
inlineToHaddock _ Space = return space
|
|
|
|
|
inlineToHaddock opts (Cite _ lst) = inlineListToHaddock opts lst
|
2015-11-19 22:41:12 -08:00
|
|
|
|
inlineToHaddock _ (Link _ txt (src, _)) = do
|
2015-11-16 20:53:01 -08:00
|
|
|
|
let linktext = text $ escapeString $ stringify txt
|
2014-06-18 15:32:13 -07:00
|
|
|
|
let useAuto = isURI src &&
|
|
|
|
|
case txt of
|
|
|
|
|
[Str s] | escapeURI s == src -> True
|
2017-03-04 13:03:41 +01:00
|
|
|
|
_ -> False
|
2014-06-18 15:32:13 -07:00
|
|
|
|
return $ nowrap $ "<" <> text src <>
|
|
|
|
|
(if useAuto then empty else space <> linktext) <> ">"
|
2015-07-26 18:30:47 +02:00
|
|
|
|
inlineToHaddock opts (Image attr alternate (source, tit)) = do
|
|
|
|
|
linkhaddock <- inlineToHaddock opts (Link attr alternate (source, tit))
|
2014-06-18 15:32:13 -07:00
|
|
|
|
return $ "<" <> linkhaddock <> ">"
|
|
|
|
|
-- haddock doesn't have notes, but we can fake it:
|
|
|
|
|
inlineToHaddock opts (Note contents) = do
|
|
|
|
|
modify (\st -> st{ stNotes = contents : stNotes st })
|
|
|
|
|
st <- get
|
|
|
|
|
let ref = text $ writerIdentifierPrefix opts ++ show (length $ stNotes st)
|
2014-06-18 17:49:59 -07:00
|
|
|
|
return $ "<#notes [" <> ref <> "]>"
|