git.iko.soy/typeable/pandoc
on master help sign in
Plain writer: don't linkify table of contents.
0d15463John MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+12−10
@@ -305,22 +305,24 @@ escapeString opts (c:cs) =
305 _ -> c : escapeString opts cs
305 _ -> c : escapeString opts cs
306
306
307-- | Construct table of contents from list of header blocks.
307-- | Construct table of contents from list of header blocks.
308−tableOfContents :: PandocMonad m => WriterOptions -> [Block] -> m Doc
308+tableOfContents :: PandocMonad m => WriterOptions -> [Block] -> MD m Doc
309−tableOfContents opts headers =
309+tableOfContents opts headers = do
310− let contents = BulletList $ map (elementToListItem opts) $ hierarchicalize headers
310+ contents <- BulletList <$> mapM (elementToListItem opts) (hierarchicalize headers)
311− in evalMD (blockToMarkdown opts contents) def def
311+ blockToMarkdown opts contents
312
312
313-- | Converts an Element to a list item for a table of contents,
313-- | Converts an Element to a list item for a table of contents,
314−elementToListItem :: WriterOptions -> Element -> [Block]
314+elementToListItem :: PandocMonad m => WriterOptions -> Element -> MD m [Block]
315elementToListItem opts (Sec lev _nums (ident,_,_) headerText subsecs)
315elementToListItem opts (Sec lev _nums (ident,_,_) headerText subsecs)
316− = Plain headerLink :
316+ = do isPlain <- asks envPlain
317− [ BulletList (map (elementToListItem opts) subsecs) |
318− not (null subsecs) && lev < writerTOCDepth opts ]
319− where headerLink = if null ident
317+ let headerLink = if null ident || isPlain
320 then walk deNote headerText
318 then walk deNote headerText
321 else [Link nullAttr (walk deNote headerText)
319 else [Link nullAttr (walk deNote headerText)
322 ('#':ident, "")]
320 ('#':ident, "")]
321+ listContents <- if null subsecs || lev >= writerTOCDepth opts
322+ then return []
323+ else mapM (elementToListItem opts) subsecs
324+ return [Plain headerLink, BulletList listContents]
323−elementToListItem _ (Blk _) = []
325+elementToListItem _ (Blk _) = return []
324
326
325attrsToMarkdown :: Attr -> Doc
327attrsToMarkdown :: Attr -> Doc
326attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
328attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]