git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: adjust internal links to identifiers...

defined in raw HTML sections after splitting into chapters. Closes #7000.

commit1ce7db1fa67b6a9f1d354d377e3bfa548d854ee9 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 4 Jan 2021, 11:38 (6 years ago) parentf04e02d
1 file changed+20
src/Text/Pandoc/Writers/EPUB.hs+20
src/Text/Pandoc/Writers/EPUB.hs+20
@@ -561,6 +561,16 @@ pandocToEPUB version opts doc = do
561561 | not (TS.null ident) = [(ident, TS.pack (showChapter num) <> "#" <> ident)]
562562 extractLinkURL' num (Image (ident, _, _) _ _)
563563 | not (TS.null ident) = [(ident, TS.pack (showChapter num) <> "#" <> ident)]
564+ extractLinkURL' num (RawInline fmt raw)
565+ | isHtmlFormat fmt
566+ = foldr (\tag ->
567+ case tag of
568+ TagOpen{} ->
569+ case fromAttrib "id" tag of
570+ "" -> id
571+ x -> ((x, TS.pack (showChapter num) <> "#" <> x):)
572+ _ -> id)
573+ [] (parseTags raw)
564574 extractLinkURL' _ _ = []
565575
566576 let extractLinkURL :: Int -> Block -> [(TS.Text, TS.Text)]
@@ -570,6 +580,16 @@ pandocToEPUB version opts doc = do
570580 | not (TS.null ident) = [(ident, TS.pack (showChapter num) <> "#" <> ident)]
571581 extractLinkURL num (Table (ident,_,_) _ _ _ _ _)
572582 | not (TS.null ident) = [(ident, TS.pack (showChapter num) <> "#" <> ident)]
583+ extractLinkURL num (RawBlock fmt raw)
584+ | isHtmlFormat fmt
585+ = foldr (\tag ->
586+ case tag of
587+ TagOpen{} ->
588+ case fromAttrib "id" tag of
589+ "" -> id
590+ x -> ((x, TS.pack (showChapter num) <> "#" <> x):)
591+ _ -> id)
592+ [] (parseTags raw)
573593 extractLinkURL num b = query (extractLinkURL' num) b
574594
575595 let reftable = concat $ zipWith (\(Chapter bs) num ->