git.iko.soy/typeable/pandoc
on master help sign in
Docbook writer: add ids to sections. Use link for internal links.

See Issue #60. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1651 788f1e2b-df1e-0410-8736-df70ead52e1b

commitde38adc7f3d63038b7c72856d25d6e03b2930f8d authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 5 Dec 2009, 18:26 (17 years ago) parent7847549
2 files changed+37−34
src/Text/Pandoc/Writers/Docbook.hs+6−3 tests/writer.docbook+31−31
src/Text/Pandoc/Writers/Docbook.hs+6−3
@@ -82,12 +82,12 @@ writeDocbook opts (Pandoc (Meta title authors date) blocks) =
8282-- | Convert an Element to Docbook.
8383elementToDocbook :: WriterOptions -> Element -> Doc
8484elementToDocbook opts (Blk block) = blockToDocbook opts block
85−elementToDocbook opts (Sec _ _ title elements) =
85+elementToDocbook opts (Sec _ id' title elements) =
8686 -- Docbook doesn't allow sections with no content, so insert some if needed
8787 let elements' = if null elements
8888 then [Blk (Para [])]
8989 else elements
90− in inTagsIndented "section" $
90+ in inTags True "section" [("id",id')] $
9191 inTagsSimple "title" (wrap opts title) $$
9292 vcat (map (elementToDocbook opts) elements')
9393
@@ -262,7 +262,10 @@ inlineToDocbook opts (Link txt (src, _)) =
262262 then emailLink
263263 else inlinesToDocbook opts txt <+> char '(' <> emailLink <>
264264 char ')'
265− else inTags False "ulink" [("url", src)] $ inlinesToDocbook opts txt
265+ else (if isPrefixOf "#" src
266+ then inTags False "link" [("linkend", drop 1 src)]
267+ else inTags False "ulink" [("url", src)]) $
268+ inlinesToDocbook opts txt
266269inlineToDocbook _ (Image _ (src, tit)) =
267270 let titleDoc = if null tit
268271 then empty
tests/writer.docbook+31−31
@@ -19,16 +19,16 @@
1919 This is a set of tests for pandoc. Most of them are adapted from
2020 John Gruber's markdown test suite.
2121 </para>
22− <section>
22+ <section id="headers">
2323 <title>Headers</title>
24− <section>
24+ <section id="level-2-with-an-embedded-link">
2525 <title>Level 2 with an
2626 <ulink url="/url">embedded link</ulink></title>
27− <section>
27+ <section id="level-3-with-emphasis">
2828 <title>Level 3 with <emphasis>emphasis</emphasis></title>
29− <section>
29+ <section id="level-4">
3030 <title>Level 4</title>
31− <section>
31+ <section id="level-5">
3232 <title>Level 5</title>
3333 <para>
3434 </para>
@@ -37,25 +37,25 @@
3737 </section>
3838 </section>
3939 </section>
40− <section>
40+ <section id="level-1">
4141 <title>Level 1</title>
42− <section>
42+ <section id="level-2-with-emphasis">
4343 <title>Level 2 with <emphasis>emphasis</emphasis></title>
44− <section>
44+ <section id="level-3">
4545 <title>Level 3</title>
4646 <para>
4747 with no blank line
4848 </para>
4949 </section>
5050 </section>
51− <section>
51+ <section id="level-2">
5252 <title>Level 2</title>
5353 <para>
5454 with no blank line
5555 </para>
5656 </section>
5757 </section>
58− <section>
58+ <section id="paragraphs">
5959 <title>Paragraphs</title>
6060 <para>
6161 Here's a regular paragraph.
@@ -73,7 +73,7 @@
7373 break<literallayout></literallayout>here.
7474 </para>
7575 </section>
76− <section>
76+ <section id="block-quotes">
7777 <title>Block Quotes</title>
7878 <para>
7979 E-mail style:
@@ -128,7 +128,7 @@ sub status {
128128 And a following paragraph.
129129 </para>
130130 </section>
131− <section>
131+ <section id="code-blocks">
132132 <title>Code Blocks</title>
133133 <para>
134134 Code:
@@ -151,9 +151,9 @@ this code block is indented by one tab
151151These should not be escaped: \$ \\ \&gt; \[ \{
152152</screen>
153153 </section>
154− <section>
154+ <section id="lists">
155155 <title>Lists</title>
156− <section>
156+ <section id="unordered">
157157 <title>Unordered</title>
158158 <para>
159159 Asterisks tight:
@@ -276,7 +276,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
276276 </listitem>
277277 </itemizedlist>
278278 </section>
279− <section>
279+ <section id="ordered">
280280 <title>Ordered</title>
281281 <para>
282282 Tight:
@@ -383,7 +383,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
383383 </listitem>
384384 </orderedlist>
385385 </section>
386− <section>
386+ <section id="nested">
387387 <title>Nested</title>
388388 <itemizedlist>
389389 <listitem>
@@ -481,7 +481,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
481481 </listitem>
482482 </orderedlist>
483483 </section>
484− <section>
484+ <section id="tabs-and-spaces">
485485 <title>Tabs and spaces</title>
486486 <itemizedlist>
487487 <listitem>
@@ -508,7 +508,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
508508 </listitem>
509509 </itemizedlist>
510510 </section>
511− <section>
511+ <section id="fancy-list-markers">
512512 <title>Fancy list markers</title>
513513 <orderedlist numeration="arabic">
514514 <listitem override="2">
@@ -613,7 +613,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
613613 </para>
614614 </section>
615615 </section>
616− <section>
616+ <section id="definition-lists">
617617 <title>Definition Lists</title>
618618 <para>
619619 Tight using spaces:
@@ -757,7 +757,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
757757 </varlistentry>
758758 </variablelist>
759759 </section>
760− <section>
760+ <section id="html-blocks">
761761 <title>HTML Blocks</title>
762762 <para>
763763 Simple block on one line:
@@ -886,7 +886,7 @@ Blah
886886<hr class="foo" id="bar">
887887
888888 </section>
889− <section>
889+ <section id="inline-markup">
890890 <title>Inline Markup</title>
891891 <para>
892892 This is <emphasis>emphasized</emphasis>, and so
@@ -936,7 +936,7 @@ Blah
936936 unescaped spaces: a^b c^d, a~b c~d.
937937 </para>
938938 </section>
939− <section>
939+ <section id="smart-quotes-ellipses-dashes">
940940 <title>Smart quotes, ellipses, dashes</title>
941941 <para>
942942 <quote>Hello,</quote> said the spider.
@@ -968,7 +968,7 @@ Blah
968968 Ellipses&#8230;and&#8230;and&#8230;.
969969 </para>
970970 </section>
971− <section>
971+ <section id="latex">
972972 <title>LaTeX</title>
973973 <itemizedlist>
974974 <listitem>
@@ -1046,7 +1046,7 @@ Blah
10461046 <para>
10471047 </para>
10481048 </section>
1049− <section>
1049+ <section id="special-characters">
10501050 <title>Special Characters</title>
10511051 <para>
10521052 Here is some unicode:
@@ -1142,9 +1142,9 @@ Blah
11421142 Minus: -
11431143 </para>
11441144 </section>
1145− <section>
1145+ <section id="links">
11461146 <title>Links</title>
1147− <section>
1147+ <section id="explicit">
11481148 <title>Explicit</title>
11491149 <para>
11501150 Just a <ulink url="/url/">URL</ulink>.
@@ -1174,7 +1174,7 @@ Blah
11741174 <ulink url="">Empty</ulink>.
11751175 </para>
11761176 </section>
1177− <section>
1177+ <section id="reference">
11781178 <title>Reference</title>
11791179 <para>
11801180 Foo <ulink url="/url/">bar</ulink>.
@@ -1213,7 +1213,7 @@ Blah
12131213 Foo <ulink url="/url/">biz</ulink>.
12141214 </para>
12151215 </section>
1216− <section>
1216+ <section id="with-ampersands">
12171217 <title>With ampersands</title>
12181218 <para>
12191219 Here's a
@@ -1231,7 +1231,7 @@ Blah
12311231 <ulink url="/script?foo=1&amp;bar=2">inline link in pointy braces</ulink>.
12321232 </para>
12331233 </section>
1234− <section>
1234+ <section id="autolinks">
12351235 <title>Autolinks</title>
12361236 <para>
12371237 With an ampersand:
@@ -1272,7 +1272,7 @@ or here: &lt;http://example.com/&gt;
12721272</screen>
12731273 </section>
12741274 </section>
1275− <section>
1275+ <section id="images">
12761276 <title>Images</title>
12771277 <para>
12781278 From <quote>Voyage dans la Lune</quote> by Georges Melies (1902):
@@ -1299,7 +1299,7 @@ or here: &lt;http://example.com/&gt;
12991299 icon.
13001300 </para>
13011301 </section>
1302− <section>
1302+ <section id="footnotes">
13031303 <title>Footnotes</title>
13041304 <para>
13051305 Here is a footnote