git.iko.soy/typeable/pandoc
on master help sign in
Change to footnotes in HTML writer: Instead of putting the footnote
a786f43fiddlosopher
src/Text/Pandoc/Writers/HTML.hs+18−5
@@ -363,9 +363,22 @@ inlineToHtml opts inline =
363
363
364blockListToNote :: WriterOptions -> String -> [Block] -> State WriterState Html
364blockListToNote :: WriterOptions -> String -> [Block] -> State WriterState Html
365blockListToNote opts ref blocks =
365blockListToNote opts ref blocks =
366− do contents <- blockListToHtml opts blocks
366+ -- If last block is Para or Plain, include the backlink at the end of
367+ -- that block. Otherwise, insert a new Plain block with the backlink.
367− let backlink = anchor ! [href ("#fnref" ++ ref), theclass "footnoteBacklink",
368+ let backlink = [HtmlInline $ " <a href=\"#fnref" ++ ref ++
369+ "\" class=\"footnoteBackLink\"" ++
368− title ("Jump back to footnote " ++ ref)] $
370+ " title=\"Jump back to footnote " ++ ref ++ "\">&#8617;</a>"]
369− (primHtmlChar "#8617")
371+ blocks' = if null blocks
372+ then []
373+ else let lastBlock = last blocks
374+ otherBlocks = init blocks
375+ in case lastBlock of
376+ (Para lst) -> otherBlocks ++
377+ [Para (lst ++ backlink)]
378+ (Plain lst) -> otherBlocks ++
379+ [Plain (lst ++ backlink)]
380+ _ -> otherBlocks ++ [lastBlock,
381+ Plain backlink]
382+ in do contents <- blockListToHtml opts blocks'
370− return $ li ! [identifier ("fn" ++ ref)] $ contents +++ backlink
383+ return $ li ! [identifier ("fn" ++ ref)] $ contents
371
384
tests/writer.html+5−15
@@ -976,9 +976,7 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+e+'<\/'+'a'+'>');
976 /><ol
976 /><ol
977 ><li id="fn1"
977 ><li id="fn1"
978 ><p
978 ><p
979− >Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.</p
979+ >Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document. <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></p
980− ><a href="#fnref1" class="footnoteBacklink" title="Jump back to footnote 1"
981− >&#8617;</a
982 ></li
980 ></li
983 ><li id="fn2"
981 ><li id="fn2"
984 ><p
982 ><p
@@ -991,9 +989,7 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+e+'<\/'+'a'+'>');
991</code
989</code
992 ></pre
990 ></pre
993 ><p
991 ><p
994− >If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.</p
992+ >If you want, you can indent every line, but you can also be lazy and just indent the first line of each block. <a href="#fnref2" class="footnoteBackLink" title="Jump back to footnote 2">&#8617;</a></p
995− ><a href="#fnref2" class="footnoteBacklink" title="Jump back to footnote 2"
996− >&#8617;</a
997 ></li
993 ></li
998 ><li id="fn3"
994 ><li id="fn3"
999 ><p
995 ><p
@@ -1003,21 +999,15 @@ document.write('<a h'+'ref'+'="ma'+'ilto'+':'+e+'">'+e+'<\/'+'a'+'>');
1003 >links</a
999 >links</a
1004 > and <code
1000 > and <code
1005 >]</code
1001 >]</code
1006− > verbatim characters, as well as [bracketed text].</p
1002+ > verbatim characters, as well as [bracketed text]. <a href="#fnref3" class="footnoteBackLink" title="Jump back to footnote 3">&#8617;</a></p
1007− ><a href="#fnref3" class="footnoteBacklink" title="Jump back to footnote 3"
1008− >&#8617;</a
1009 ></li
1003 ></li
1010 ><li id="fn4"
1004 ><li id="fn4"
1011 ><p
1005 ><p
1012− >In quote.</p
1013− ><a href="#fnref4" class="footnoteBacklink" title="Jump back to footnote 4"
1006+ >In quote. <a href="#fnref4" class="footnoteBackLink" title="Jump back to footnote 4">&#8617;</a></p
1014− >&#8617;</a
1015 ></li
1007 ></li
1016 ><li id="fn5"
1008 ><li id="fn5"
1017 ><p
1009 ><p
1018− >In list.</p
1019− ><a href="#fnref5" class="footnoteBacklink" title="Jump back to footnote 5"
1010+ >In list. <a href="#fnref5" class="footnoteBackLink" title="Jump back to footnote 5">&#8617;</a></p
1020− >&#8617;</a
1021 ></li
1011 ></li
1022 ></ol
1012 ></ol
1023 ></div
1013 ></div