git.iko.soy/typeable/pandoc
on master help sign in
FB2 writer: output links inline instead of producing notes

Previously all links were turned into footnotes with unclickable URLs inside.

commitf9aa2eb35368724609ba624f00aed8d033159fcf authorAlexander Krotov <ilabdsf@gmail.com> dateSat 7 Apr 2018, 00:50 (9 years ago) parent394f453
3 files changed+61−343
src/Text/Pandoc/Writers/FB2.hs+2−19 test/fb2/basic.fb2+1−1 test/writer.fb2+58−323
src/Text/Pandoc/Writers/FB2.hs+2−19
@@ -311,9 +311,6 @@ isMimeType s =
311311footnoteID :: Int -> String
312312footnoteID i = "n" ++ show i
313313
314−linkID :: Int -> String
315−linkID i = "l" ++ show i
316−
317314-- | Convert a block-level Pandoc's element to FictionBook XML representation.
318315blockToXml :: PandocMonad m => Block -> FBM m [Content]
319316blockToXml (Plain ss) = cMapM toXml ss -- FIXME: can lead to malformed FB2
@@ -455,23 +452,9 @@ toXml (Math _ formula) = insertMath InlineImage formula
455452toXml il@(RawInline _ _) = do
456453 report $ InlineNotRendered il
457454 return [] -- raw TeX and raw HTML are suppressed
458−toXml (Link _ text (url,ttl)) = do
459− fns <- footnotes `liftM` get
460− let n = 1 + length fns
461− let ln_id = linkID n
462− let ln_ref = list . el "sup" . txt $ "[" ++ show n ++ "]"
455+toXml (Link _ text (url,_)) = do
463456 ln_text <- cMapM toXml text
464− let ln_desc =
465− let ttl' = dropWhile isSpace ttl
466− in if null ttl'
467− then list . el "p" $ el "code" url
468− else list . el "p" $ [ txt (ttl' ++ ": "), el "code" url ]
469− modify (\s -> s { footnotes = (n, ln_id, ln_desc) : fns })
470− return $ ln_text ++
471− [ el "a"
472− ( [ attr ("l","href") ('#':ln_id)
473− , uattr "type" "note" ]
474− , ln_ref) ]
457+ return [ el "a" ( [ attr ("l","href") url ], ln_text) ]
475458toXml img@Image{} = insertImage InlineImage img
476459toXml (Note bs) = do
477460 fns <- footnotes `liftM` get
test/fb2/basic.fb2+1−1
@@ -1,3 +1,3 @@
11<?xml version="1.0" encoding="UTF-8"?>
2−<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink"><description><title-info><genre>unrecognised</genre></title-info><document-info><program-used>pandoc</program-used></document-info></description><body><title><p /></title><section><title><p>Top-level title</p></title><section><title><p>Section</p></title><section><title><p>Subsection</p></title><p>This <emphasis>emphasized</emphasis> <strong>strong</strong> <code>verbatim</code> markdown. See this link<a l:href="#l1" type="note"><sup>[1]</sup></a>.</p><p>Ordered list:</p><p>1. one</p><p>2. two</p><p>3. three</p><cite><p>Blockquote is for citatons.</p></cite><empty-line /><p><code>Code</code></p><p><code>block</code></p><p><code>is</code></p><p><code>for</code></p><p><code>code.</code></p><empty-line /><p><strikethrough>Strikeout</strikethrough> is Pandoc’s extension. Superscript and subscripts too: H<sub>2</sub>O is a liquid<a l:href="#n2" type="note"><sup>[2]</sup></a>. 2<sup>10</sup> is 1024.</p><p>Math is another Pandoc extension: <code>E = m c^2</code>.</p></section></section></section></body><body name="notes"><section id="l1"><title><p>1</p></title><p><code>http://example.com/</code></p></section><section id="n2"><title><p>2</p></title><p>Sometimes.</p></section></body></FictionBook>
2+<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink"><description><title-info><genre>unrecognised</genre></title-info><document-info><program-used>pandoc</program-used></document-info></description><body><title><p /></title><section><title><p>Top-level title</p></title><section><title><p>Section</p></title><section><title><p>Subsection</p></title><p>This <emphasis>emphasized</emphasis> <strong>strong</strong> <code>verbatim</code> markdown. See this <a l:href="http://example.com/">link</a>.</p><p>Ordered list:</p><p>1. one</p><p>2. two</p><p>3. three</p><cite><p>Blockquote is for citatons.</p></cite><empty-line /><p><code>Code</code></p><p><code>block</code></p><p><code>is</code></p><p><code>for</code></p><p><code>code.</code></p><empty-line /><p><strikethrough>Strikeout</strikethrough> is Pandoc’s extension. Superscript and subscripts too: H<sub>2</sub>O is a liquid<a l:href="#n1" type="note"><sup>[1]</sup></a>. 2<sup>10</sup> is 1024.</p><p>Math is another Pandoc extension: <code>E = m c^2</code>.</p></section></section></section></body><body name="notes"><section id="n1"><title><p>1</p></title><p>Sometimes.</p></section></body></FictionBook>
33
test/writer.fb2+58−323
@@ -33,9 +33,7 @@
3333</title>
3434<section>
3535<title>
36−<p>Level 2 with an embedded link<a l:href="#l1" type="note">
37−<sup>[1]</sup>
38−</a>
36+<p>Level 2 with an <a l:href="/url">embedded link</a>
3937</p>
4038</title>
4139<section>
@@ -490,9 +488,8 @@
490488</title>
491489<p>This is <emphasis>emphasized</emphasis>, and so <emphasis>is this</emphasis>.</p>
492490<p>This is <strong>strong</strong>, and so <strong>is this</strong>.</p>
493−<p>An <emphasis>emphasized link<a l:href="#l2" type="note">
494−<sup>[2]</sup>
495−</a>
491+<p>An <emphasis>
492+<a l:href="/url">emphasized link</a>
496493</emphasis>.</p>
497494<p>
498495<strong>
@@ -531,9 +528,7 @@
531528<p>‘A’, ‘B’, and ‘C’ are letters.</p>
532529<p>‘Oak,’ ‘elm,’ and ‘beech’ are names of trees. So is ‘pine.’</p>
533530<p>‘He said, “I want to go.”’ Were you alive in the 70’s?</p>
534−<p>Here is some quoted ‘<code>code</code>’ and a “quoted link<a l:href="#l3" type="note">
535−<sup>[3]</sup>
536−</a>”.</p>
531+<p>Here is some quoted ‘<code>code</code>’ and a “<a l:href="http://example.com/?foo=1&amp;bar=2">quoted link</a>”.</p>
537532<p>Some dashes: one—two — three—four — five.</p>
538533<p>Dashes between numbers: 5–7, 255–66, 1987–1999.</p>
539534<p>Ellipses…and…and….</p>
@@ -611,112 +606,71 @@
611606<title>
612607<p>Explicit</p>
613608</title>
614−<p>Just a URL<a l:href="#l4" type="note">
615−<sup>[4]</sup>
616−</a>.</p>
617−<p>URL and title<a l:href="#l5" type="note">
618−<sup>[5]</sup>
619−</a>.</p>
620−<p>URL and title<a l:href="#l6" type="note">
621−<sup>[6]</sup>
622−</a>.</p>
623−<p>URL and title<a l:href="#l7" type="note">
624−<sup>[7]</sup>
625−</a>.</p>
626−<p>URL and title<a l:href="#l8" type="note">
627−<sup>[8]</sup>
628−</a>
609+<p>Just a <a l:href="/url/">URL</a>.</p>
610+<p>
611+<a l:href="/url/">URL and title</a>.</p>
612+<p>
613+<a l:href="/url/">URL and title</a>.</p>
614+<p>
615+<a l:href="/url/">URL and title</a>.</p>
616+<p>
617+<a l:href="/url/">URL and title</a>
629618</p>
630−<p>URL and title<a l:href="#l9" type="note">
631−<sup>[9]</sup>
632−</a>
619+<p>
620+<a l:href="/url/">URL and title</a>
633621</p>
634−<p>with_underscore<a l:href="#l10" type="note">
635−<sup>[10]</sup>
636−</a>
622+<p>
623+<a l:href="/url/with_underscore">with_underscore</a>
637624</p>
638−<p>Email link<a l:href="#l11" type="note">
639−<sup>[11]</sup>
640−</a>
625+<p>
626+<a l:href="mailto:nobody@nowhere.net">Email link</a>
641627</p>
642−<p>Empty<a l:href="#l12" type="note">
643−<sup>[12]</sup>
644−</a>.</p>
628+<p>
629+<a l:href="">Empty</a>.</p>
645630</section>
646631<section>
647632<title>
648633<p>Reference</p>
649634</title>
650−<p>Foo bar<a l:href="#l13" type="note">
651−<sup>[13]</sup>
652−</a>.</p>
653−<p>With embedded [brackets]<a l:href="#l14" type="note">
654−<sup>[14]</sup>
655−</a>.</p>
656−<p>b<a l:href="#l15" type="note">
657−<sup>[15]</sup>
658−</a> by itself should be a link.</p>
659−<p>Indented once<a l:href="#l16" type="note">
660−<sup>[16]</sup>
661−</a>.</p>
662−<p>Indented twice<a l:href="#l17" type="note">
663−<sup>[17]</sup>
664−</a>.</p>
665−<p>Indented thrice<a l:href="#l18" type="note">
666−<sup>[18]</sup>
667−</a>.</p>
635+<p>Foo <a l:href="/url/">bar</a>.</p>
636+<p>With <a l:href="/url/">embedded [brackets]</a>.</p>
637+<p>
638+<a l:href="/url/">b</a> by itself should be a link.</p>
639+<p>Indented <a l:href="/url">once</a>.</p>
640+<p>Indented <a l:href="/url">twice</a>.</p>
641+<p>Indented <a l:href="/url">thrice</a>.</p>
668642<p>This should [not][] be a link.</p>
669643<empty-line />
670644<p>
671645<code>[not]: /url</code>
672646</p>
673647<empty-line />
674−<p>Foo bar<a l:href="#l19" type="note">
675−<sup>[19]</sup>
676−</a>.</p>
677−<p>Foo biz<a l:href="#l20" type="note">
678−<sup>[20]</sup>
679−</a>.</p>
648+<p>Foo <a l:href="/url/">bar</a>.</p>
649+<p>Foo <a l:href="/url/">biz</a>.</p>
680650</section>
681651<section>
682652<title>
683653<p>With ampersands</p>
684654</title>
685−<p>Here’s a link with an ampersand in the URL<a l:href="#l21" type="note">
686−<sup>[21]</sup>
687−</a>.</p>
688−<p>Here’s a link with an amersand in the link text: AT&amp;T<a l:href="#l22" type="note">
689−<sup>[22]</sup>
690−</a>.</p>
691−<p>Here’s an inline link<a l:href="#l23" type="note">
692−<sup>[23]</sup>
693−</a>.</p>
694−<p>Here’s an inline link in pointy braces<a l:href="#l24" type="note">
695−<sup>[24]</sup>
696−</a>.</p>
655+<p>Here’s a <a l:href="http://example.com/?foo=1&amp;bar=2">link with an ampersand in the URL</a>.</p>
656+<p>Here’s a link with an amersand in the link text: <a l:href="http://att.com/">AT&amp;T</a>.</p>
657+<p>Here’s an <a l:href="/script?foo=1&amp;bar=2">inline link</a>.</p>
658+<p>Here’s an <a l:href="/script?foo=1&amp;bar=2">inline link in pointy braces</a>.</p>
697659</section>
698660<section>
699661<title>
700662<p>Autolinks</p>
701663</title>
702−<p>With an ampersand: http://example.com/?foo=1&amp;bar=2<a l:href="#l25" type="note">
703−<sup>[25]</sup>
704−</a>
664+<p>With an ampersand: <a l:href="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</a>
705665</p>
706666<p>• In a list?</p>
707−<p>• http://example.com/<a l:href="#l26" type="note">
708−<sup>[26]</sup>
709−</a>
667+<p>• <a l:href="http://example.com/">http://example.com/</a>
710668</p>
711669<p>• It should.</p>
712−<p>An e-mail address: nobody@nowhere.net<a l:href="#l27" type="note">
713−<sup>[27]</sup>
714−</a>
670+<p>An e-mail address: <a l:href="mailto:nobody@nowhere.net">nobody@nowhere.net</a>
715671</p>
716672<cite>
717−<p>Blockquoted: http://example.com/<a l:href="#l28" type="note">
718−<sup>[28]</sup>
719−</a>
673+<p>Blockquoted: <a l:href="http://example.com/">http://example.com/</a>
720674</p>
721675</cite>
722676<p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code>
@@ -746,254 +700,37 @@
746700<title>
747701<p>Footnotes</p>
748702</title>
749−<p>Here is a footnote reference,<a l:href="#n29" type="note">
750−<sup>[29]</sup>
751−</a> and another.<a l:href="#n30" type="note">
752−<sup>[30]</sup>
753−</a> This should <emphasis>not</emphasis> be a footnote reference, because it contains a space.[^my note] Here is an inline note.<a l:href="#n31" type="note">
754−<sup>[31]</sup>
703+<p>Here is a footnote reference,<a l:href="#n1" type="note">
704+<sup>[1]</sup>
705+</a> and another.<a l:href="#n2" type="note">
706+<sup>[2]</sup>
707+</a> This should <emphasis>not</emphasis> be a footnote reference, because it contains a space.[^my note] Here is an inline note.<a l:href="#n3" type="note">
708+<sup>[3]</sup>
755709</a>
756710</p>
757711<cite>
758−<p>Notes can go in quotes.<a l:href="#n32" type="note">
759−<sup>[32]</sup>
712+<p>Notes can go in quotes.<a l:href="#n4" type="note">
713+<sup>[4]</sup>
760714</a>
761715</p>
762716</cite>
763−<p>1. And in list items.<a l:href="#n33" type="note">
764−<sup>[33]</sup>
717+<p>1. And in list items.<a l:href="#n5" type="note">
718+<sup>[5]</sup>
765719</a>
766720</p>
767721<p>This paragraph should not be part of the note, as it is not indented.</p>
768722</section>
769723</body>
770724<body name="notes">
771−<section id="l1">
725+<section id="n1">
772726<title>
773727<p>1</p>
774728</title>
775−<p>
776−<code>/url</code>
777−</p>
778−</section>
779−<section id="l2">
780−<title>
781−<p>2</p>
782−</title>
783−<p>
784−<code>/url</code>
785−</p>
786−</section>
787−<section id="l3">
788−<title>
789−<p>3</p>
790−</title>
791−<p>
792−<code>http://example.com/?foo=1&amp;bar=2</code>
793−</p>
794−</section>
795−<section id="l4">
796−<title>
797−<p>4</p>
798−</title>
799−<p>
800−<code>/url/</code>
801−</p>
802−</section>
803−<section id="l5">
804−<title>
805−<p>5</p>
806−</title>
807−<p>title: <code>/url/</code>
808−</p>
809−</section>
810−<section id="l6">
811−<title>
812−<p>6</p>
813−</title>
814−<p>title preceded by two spaces: <code>/url/</code>
815−</p>
816−</section>
817−<section id="l7">
818−<title>
819−<p>7</p>
820−</title>
821−<p>title preceded by a tab: <code>/url/</code>
822−</p>
823−</section>
824−<section id="l8">
825−<title>
826−<p>8</p>
827−</title>
828−<p>title with &quot;quotes&quot; in it: <code>/url/</code>
829−</p>
830−</section>
831−<section id="l9">
832−<title>
833−<p>9</p>
834−</title>
835−<p>title with single quotes: <code>/url/</code>
836−</p>
837−</section>
838−<section id="l10">
839−<title>
840−<p>10</p>
841−</title>
842−<p>
843−<code>/url/with_underscore</code>
844−</p>
845−</section>
846−<section id="l11">
847−<title>
848−<p>11</p>
849−</title>
850−<p>
851−<code>mailto:nobody@nowhere.net</code>
852−</p>
853−</section>
854−<section id="l12">
855−<title>
856−<p>12</p>
857−</title>
858−<p>
859−<code>
860−</code>
861−</p>
862−</section>
863−<section id="l13">
864−<title>
865−<p>13</p>
866−</title>
867−<p>
868−<code>/url/</code>
869−</p>
870−</section>
871−<section id="l14">
872−<title>
873−<p>14</p>
874−</title>
875−<p>
876−<code>/url/</code>
877−</p>
878−</section>
879−<section id="l15">
880−<title>
881−<p>15</p>
882−</title>
883−<p>
884−<code>/url/</code>
885−</p>
886−</section>
887−<section id="l16">
888−<title>
889−<p>16</p>
890−</title>
891−<p>
892−<code>/url</code>
893−</p>
894−</section>
895−<section id="l17">
896−<title>
897−<p>17</p>
898−</title>
899−<p>
900−<code>/url</code>
901−</p>
902−</section>
903−<section id="l18">
904−<title>
905−<p>18</p>
906−</title>
907−<p>
908−<code>/url</code>
909−</p>
910−</section>
911−<section id="l19">
912−<title>
913−<p>19</p>
914−</title>
915−<p>Title with &quot;quotes&quot; inside: <code>/url/</code>
916−</p>
917−</section>
918−<section id="l20">
919−<title>
920−<p>20</p>
921−</title>
922−<p>Title with &quot;quote&quot; inside: <code>/url/</code>
923−</p>
924−</section>
925−<section id="l21">
926−<title>
927−<p>21</p>
928−</title>
929−<p>
930−<code>http://example.com/?foo=1&amp;bar=2</code>
931−</p>
932−</section>
933−<section id="l22">
934−<title>
935−<p>22</p>
936−</title>
937−<p>AT&amp;T: <code>http://att.com/</code>
938−</p>
939−</section>
940−<section id="l23">
941−<title>
942−<p>23</p>
943−</title>
944−<p>
945−<code>/script?foo=1&amp;bar=2</code>
946−</p>
947−</section>
948−<section id="l24">
949−<title>
950−<p>24</p>
951−</title>
952−<p>
953−<code>/script?foo=1&amp;bar=2</code>
954−</p>
955−</section>
956−<section id="l25">
957−<title>
958−<p>25</p>
959−</title>
960−<p>
961−<code>http://example.com/?foo=1&amp;bar=2</code>
962−</p>
963−</section>
964−<section id="l26">
965−<title>
966−<p>26</p>
967−</title>
968−<p>
969−<code>http://example.com/</code>
970−</p>
971−</section>
972−<section id="l27">
973−<title>
974−<p>27</p>
975−</title>
976−<p>
977−<code>mailto:nobody@nowhere.net</code>
978−</p>
979−</section>
980−<section id="l28">
981−<title>
982−<p>28</p>
983−</title>
984−<p>
985−<code>http://example.com/</code>
986−</p>
987−</section>
988−<section id="n29">
989−<title>
990−<p>29</p>
991−</title>
992729<p>Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.</p>
993730</section>
994−<section id="n30">
731+<section id="n2">
995732<title>
996−<p>30</p>
733+<p>2</p>
997734</title>
998735<p>Here’s the long note. This one contains multiple blocks.</p>
999736<p>Subsequent blocks are indented to show that they belong to the footnote (as with list items).</p>
@@ -1004,23 +741,21 @@
1004741<empty-line />
1005742<p>If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.</p>
1006743</section>
1007−<section id="n31">
744+<section id="n3">
1008745<title>
1009−<p>31</p>
746+<p>3</p>
1010747</title>
1011−<p>This is <emphasis>easier</emphasis> to type. Inline notes may contain links<a l:href="#l31" type="note">
1012−<sup>[31]</sup>
1013−</a> and <code>]</code> verbatim characters, as well as [bracketed text].</p>
748+<p>This is <emphasis>easier</emphasis> to type. Inline notes may contain <a l:href="http://google.com">links</a> and <code>]</code> verbatim characters, as well as [bracketed text].</p>
1014749</section>
1015−<section id="n32">
750+<section id="n4">
1016751<title>
1017−<p>32</p>
752+<p>4</p>
1018753</title>
1019754<p>In quote.</p>
1020755</section>
1021−<section id="n33">
756+<section id="n5">
1022757<title>
1023−<p>33</p>
758+<p>5</p>
1024759</title>
1025760<p>In list.</p>
1026761</section>