git.iko.soy/typeable/pandoc
on master help sign in
Removed writerIgnoreNotes.

Instead, just temporarily remove notes when generating TOC lists in HTML and Markdown (as we already did in LaTeX). Also export deNote from Text.Pandoc.Shared. API change in Shared and Options.WriterOptions.

commit4007d6a89749ff6576e65bb08631ff14a6d0ee20 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 15 Jan 2017, 22:34 (10 years ago) parent2d04922
6 files changed+10−18
pandoc.hs−1 src/Text/Pandoc/Options.hs−2 src/Text/Pandoc/Shared.hs+1 src/Text/Pandoc/Writers/HTML.hs+4−6 src/Text/Pandoc/Writers/LaTeX.hs−4 src/Text/Pandoc/Writers/Markdown.hs+5−5
pandoc.hs−1
@@ -306,7 +306,6 @@ convertWithOpts opts args = do
306306 writerHTMLMathMethod = mathMethod,
307307 writerIncremental = incremental,
308308 writerCiteMethod = citeMethod,
309− writerIgnoreNotes = False,
310309 writerNumberSections = numberSections,
311310 writerNumberOffset = numberFrom,
312311 writerSectionDivs = sectionDivs,
src/Text/Pandoc/Options.hs−2
@@ -151,7 +151,6 @@ data WriterOptions = WriterOptions
151151 , writerSlideVariant :: HTMLSlideVariant -- ^ Are we writing S5, Slidy or Slideous?
152152 , writerIncremental :: Bool -- ^ True if lists should be incremental
153153 , writerHTMLMathMethod :: HTMLMathMethod -- ^ How to print math in HTML
154− , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
155154 , writerNumberSections :: Bool -- ^ Number sections in LaTeX
156155 , writerNumberOffset :: [Int] -- ^ Starting number for section, subsection, ...
157156 , writerSectionDivs :: Bool -- ^ Put sections in div tags in HTML
@@ -197,7 +196,6 @@ instance Default WriterOptions where
197196 , writerSlideVariant = NoSlides
198197 , writerIncremental = False
199198 , writerHTMLMathMethod = PlainMath
200− , writerIgnoreNotes = False
201199 , writerNumberSections = False
202200 , writerNumberOffset = [0,0,0,0,0,0]
203201 , writerSectionDivs = False
src/Text/Pandoc/Shared.hs+1
@@ -56,6 +56,7 @@ module Text.Pandoc.Shared (
5656 normalizeSpaces,
5757 extractSpaces,
5858 removeFormatting,
59+ deNote,
5960 stringify,
6061 capitalize,
6162 compactify,
src/Text/Pandoc/Writers/HTML.hs+4−6
@@ -30,6 +30,7 @@ Conversion of 'Pandoc' documents to HTML.
3030-}
3131module Text.Pandoc.Writers.HTML ( writeHtml , writeHtmlString ) where
3232import Text.Pandoc.Definition
33+import Text.Pandoc.Walk
3334import Data.Monoid ((<>))
3435import Text.Pandoc.Shared
3536import Text.Pandoc.Writers.Shared
@@ -228,8 +229,7 @@ defList opts items = toList H.dl opts (items ++ [nl opts])
228229tableOfContents :: PandocMonad m => WriterOptions -> [Element] -> StateT WriterState m (Maybe Html)
229230tableOfContents _ [] = return Nothing
230231tableOfContents opts sects = do
231− let opts' = opts { writerIgnoreNotes = True }
232− contents <- mapM (elementToListItem opts') sects
232+ contents <- mapM (elementToListItem opts) sects
233233 let tocList = catMaybes contents
234234 return $ if null tocList
235235 then Nothing
@@ -253,7 +253,7 @@ elementToListItem opts (Sec lev num (id',classes,_) headerText subsecs)
253253 then (H.span ! A.class_ "toc-section-number"
254254 $ toHtml $ showSecNum num') >> preEscapedString " "
255255 else mempty
256− txt <- liftM (sectnum >>) $ inlineListToHtml opts headerText
256+ txt <- liftM (sectnum >>) $ inlineListToHtml opts $ walk deNote headerText
257257 subHeads <- mapM (elementToListItem opts) subsecs >>= return . catMaybes
258258 let subList = if null subHeads
259259 then mempty
@@ -852,9 +852,7 @@ inlineToHtml opts inline =
852852 imgAttrsToHtml opts attr
853853 return $ foldl (!) H5.embed attributes
854854 -- note: null title included, as in Markdown.pl
855− (Note contents)
856− | writerIgnoreNotes opts -> return mempty
857− | otherwise -> do
855+ (Note contents) -> do
858856 notes <- gets stNotes
859857 let number = (length notes) + 1
860858 let ref = show number
src/Text/Pandoc/Writers/LaTeX.hs−4
@@ -1318,10 +1318,6 @@ commonFromBcp47 x = fromIso $ head x
13181318 fromIso "vi" = "vietnamese"
13191319 fromIso _ = ""
13201320
1321−deNote :: Inline -> Inline
1322−deNote (Note _) = RawInline (Format "latex") ""
1323−deNote x = x
1324−
13251321pDocumentOptions :: P.Parsec String () [String]
13261322pDocumentOptions = do
13271323 P.char '['
src/Text/Pandoc/Writers/Markdown.hs+5−5
@@ -288,9 +288,8 @@ escapeString opts = escapeStringUsing markdownEscapes
288288-- | Construct table of contents from list of header blocks.
289289tableOfContents :: PandocMonad m => WriterOptions -> [Block] -> m Doc
290290tableOfContents opts headers =
291− let opts' = opts { writerIgnoreNotes = True }
292− contents = BulletList $ map (elementToListItem opts) $ hierarchicalize headers
293− in evalMD (blockToMarkdown opts' contents) def def
291+ let contents = BulletList $ map (elementToListItem opts) $ hierarchicalize headers
292+ in evalMD (blockToMarkdown opts contents) def def
294293
295294-- | Converts an Element to a list item for a table of contents,
296295elementToListItem :: WriterOptions -> Element -> [Block]
@@ -299,8 +298,9 @@ elementToListItem opts (Sec lev _nums (ident,_,_) headerText subsecs)
299298 [ BulletList (map (elementToListItem opts) subsecs) |
300299 not (null subsecs) && lev < writerTOCDepth opts ]
301300 where headerLink = if null ident
302− then headerText
303− else [Link nullAttr headerText ('#':ident, "")]
301+ then walk deNote headerText
302+ else [Link nullAttr (walk deNote headerText)
303+ ('#':ident, "")]
304304elementToListItem _ (Blk _) = []
305305
306306attrsToMarkdown :: Attr -> Doc