git.iko.soy/typeable/pandoc
on master help sign in
Adds Asciidoctor sprcific writer and tests
commit568b25d33a277b02cddbe646f3d6ec31f00ec99b authorTG <tarik.graba@telecom-paristech.fr> dateTue 5 Feb 2019, 19:12 (8 years ago) parent8fdeae2
9 files changed+794−16
MANUAL.txt+7−2 README.md+1−1 data/templates/default.asciidoctor+38 pandoc.cabal+1 src/Text/Pandoc/Writers.hs+2 src/Text/Pandoc/Writers/AsciiDoc.hs+29−12 test/Tests/Old.hs+1−1 test/tables.asciidoctor+67 test/writer.asciidoctor+648
MANUAL.txt+7−2
@@ -279,7 +279,7 @@ General options {.options}
279279: Specify output format. *FORMAT* can be:
280280
281281 ::: {#output-formats}
282− - `asciidoc` ([AsciiDoc])
282+ - `asciidoc` ([AsciiDoc]) or `asciidoctor` ([AsciiDoctor])
283283 - `beamer` ([LaTeX beamer][`beamer`] slide show)
284284 - `commonmark` ([CommonMark] Markdown)
285285 - `context` ([ConTeXt])
@@ -465,6 +465,7 @@ General options {.options}
465465[GNU Texinfo]: http://www.gnu.org/software/texinfo/
466466[Emacs Org mode]: http://orgmode.org
467467[AsciiDoc]: http://www.methods.co.nz/asciidoc/
468+[AsciiDoctor]: https://asciidoctor.org/
468469[DZSlides]: http://paulrouget.com/dzslides/
469470[Word docx]: https://en.wikipedia.org/wiki/Office_Open_XML
470471[PDF]: https://www.adobe.com/pdf/
@@ -3513,7 +3514,11 @@ reStructuredText
35133514 ~ It will be rendered using an [interpreted text role `:math:`].
35143515
35153516AsciiDoc
3516− ~ It will be rendered as `latexmath:[...]` when inline and `[latexmath]++++....++++` when in display mode.
3517+ ~ For AsciiDoc output format (`-t asciidoc`) it will appear verbatim
3518+ surrounded by `latexmath:[$...$]` (for inline math) or
3519+ `[latexmath]++++\[...\]+++` (for display math).
3520+ For AsciiDoctor output format (`-t asciidoctor`) the LaTex delimiters
3521+ (`$..$` and `\[..\]`) are omitted.
35173522
35183523Texinfo
35193524 ~ It will be rendered inside a `@math` command.
README.md+1−1
@@ -81,7 +81,7 @@ It can convert *to*
8181
8282<div id="output-formats">
8383
84− - `asciidoc` ([AsciiDoc](http://www.methods.co.nz/asciidoc/))
84+ - `asciidoc` ([AsciiDoc](http://www.methods.co.nz/asciidoc/)) or `asciidoctor` ([AsciiDoctor](https://asciidoctor.org/))
8585 - `beamer` ([LaTeX beamer](https://ctan.org/pkg/beamer) slide show)
8686 - `commonmark` ([CommonMark](http://commonmark.org) Markdown)
8787 - `context` ([ConTeXt](http://www.contextgarden.net/))
data/templates/default.asciidoctornew file+38
@@ -0,0 +1,38 @@
1+$if(titleblock)$
2+= $title$
3+$if(author)$
4+$for(author)$$author$$sep$; $endfor$
5+$endif$
6+$if(date)$
7+$date$
8+$endif$
9+$if(keywords)$
10+:keywords: $for(keywords)$$keywords$$sep$, $endfor$
11+$endif$
12+$if(lang)$
13+:lang: $lang$
14+$endif$
15+$if(toc)$
16+:toc:
17+$endif$
18+
19+$endif$
20+$if(abstract)$
21+[abstract]
22+== Abstract
23+$abstract$
24+
25+$endif$
26+$for(header-includes)$
27+$header-includes$
28+
29+$endfor$
30+$for(include-before)$
31+$include-before$
32+
33+$endfor$
34+$body$
35+$for(include-after)$
36+
37+$include-after$
38+$endfor$
pandoc.cabal+1
@@ -70,6 +70,7 @@ data-files:
7070 data/templates/default.revealjs
7171 data/templates/default.dzslides
7272 data/templates/default.asciidoc
73+ data/templates/default.asciidoctor
7374 data/templates/default.haddock
7475 data/templates/default.textile
7576 data/templates/default.org
src/Text/Pandoc/Writers.hs+2
@@ -37,6 +37,7 @@ module Text.Pandoc.Writers
3737 Writer(..)
3838 , writers
3939 , writeAsciiDoc
40+ , writeAsciiDoctor
4041 , writeBeamer
4142 , writeCommonMark
4243 , writeConTeXt
@@ -178,6 +179,7 @@ writers = [
178179 ,("rtf" , TextWriter writeRTF)
179180 ,("org" , TextWriter writeOrg)
180181 ,("asciidoc" , TextWriter writeAsciiDoc)
182+ ,("asciidoctor" , TextWriter writeAsciiDoctor)
181183 ,("haddock" , TextWriter writeHaddock)
182184 ,("commonmark" , TextWriter writeCommonMark)
183185 ,("gfm" , TextWriter writeCommonMark)
src/Text/Pandoc/Writers/AsciiDoc.hs+29−12
@@ -37,7 +37,7 @@ that it has omitted the construct.
3737
3838AsciiDoc: <http://www.methods.co.nz/asciidoc/>
3939-}
40−module Text.Pandoc.Writers.AsciiDoc (writeAsciiDoc) where
40+module Text.Pandoc.Writers.AsciiDoc (writeAsciiDoc, writeAsciiDoctor) where
4141import Prelude
4242import Control.Monad.State.Strict
4343import Data.Char (isPunctuation, isSpace, toLower)
@@ -61,18 +61,27 @@ data WriterState = WriterState { defListMarker :: String
6161 , bulletListLevel :: Int
6262 , intraword :: Bool
6363 , autoIds :: Set.Set String
64+ , asciidoctorVariant :: Bool
6465 }
6566
67+defaultWriterState :: WriterState
68+defaultWriterState = WriterState { defListMarker = "::"
69+ , orderedListLevel = 0
70+ , bulletListLevel = 0
71+ , intraword = False
72+ , autoIds = Set.empty
73+ , asciidoctorVariant = False
74+ }
75+
6676-- | Convert Pandoc to AsciiDoc.
6777writeAsciiDoc :: PandocMonad m => WriterOptions -> Pandoc -> m Text
6878writeAsciiDoc opts document =
69− evalStateT (pandocToAsciiDoc opts document) WriterState{
70− defListMarker = "::"
71− , orderedListLevel = 0
72− , bulletListLevel = 0
73− , intraword = False
74− , autoIds = Set.empty
75− }
79+ evalStateT (pandocToAsciiDoc opts document) defaultWriterState
80+
81+-- | Convert Pandoc to AsciiDoctor compatible AsciiDoc.
82+writeAsciiDoctor :: PandocMonad m => WriterOptions -> Pandoc -> m Text
83+writeAsciiDoctor opts document =
84+ evalStateT (pandocToAsciiDoc opts document) defaultWriterState{ asciidoctorVariant = True }
7685
7786type ADW = StateT WriterState
7887
@@ -411,12 +420,20 @@ inlineToAsciiDoc opts (Quoted DoubleQuote lst) =
411420inlineToAsciiDoc _ (Code _ str) = return $
412421 text "`" <> text (escapeStringUsing (backslashEscapes "`") str) <> "`"
413422inlineToAsciiDoc _ (Str str) = return $ text $ escapeString str
414−inlineToAsciiDoc _ (Math InlineMath str) =
415− return $ "latexmath:[$" <> text str <> "$]"
416−inlineToAsciiDoc _ (Math DisplayMath str) =
423+inlineToAsciiDoc _ (Math InlineMath str) = do
424+ isAsciidoctor <- gets asciidoctorVariant
425+ let content = if isAsciidoctor
426+ then text str
427+ else "$" <> text str <> "$"
428+ return $ "latexmath:[" <> content <> "]"
429+inlineToAsciiDoc _ (Math DisplayMath str) = do
430+ isAsciidoctor <- gets asciidoctorVariant
431+ let content = if isAsciidoctor
432+ then text str
433+ else "\\[" <> text str <> "\\]"
417434 return $
418435 blankline <> "[latexmath]" $$ "++++" $$
419− "\\[" <> text str <> "\\]"
436+ content
420437 $$ "++++" $$ blankline
421438inlineToAsciiDoc _ il@(RawInline f s)
422439 | f == "asciidoc" = return $ text s
test/Tests/Old.hs+1−1
@@ -159,7 +159,7 @@ tests pandocPath =
159159 "tikiwiki-reader.tikiwiki" "tikiwiki-reader.native" ]
160160 , testGroup "other writers" $ map (\f -> testGroup f $ writerTests' f)
161161 [ "opendocument" , "context" , "texinfo", "icml", "tei"
162− , "man" , "plain" , "rtf", "org", "asciidoc", "zimwiki"
162+ , "man" , "plain" , "rtf", "org", "asciidoc", "asciidoctor", "zimwiki"
163163 ]
164164 , testGroup "writers-lang-and-dir"
165165 [ test' "latex" ["-f", "native", "-t", "latex", "-s"]
test/tables.asciidoctornew file+67
@@ -0,0 +1,67 @@
1+Simple table with caption:
2+
3+.Demonstration of simple table syntax.
4+[cols=">,<,^,",options="header",]
5+|===
6+|Right |Left |Center |Default
7+|12 |12 |12 |12
8+|123 |123 |123 |123
9+|1 |1 |1 |1
10+|===
11+
12+Simple table without caption:
13+
14+[cols=">,<,^,",options="header",]
15+|===
16+|Right |Left |Center |Default
17+|12 |12 |12 |12
18+|123 |123 |123 |123
19+|1 |1 |1 |1
20+|===
21+
22+Simple table indented two spaces:
23+
24+.Demonstration of simple table syntax.
25+[cols=">,<,^,",options="header",]
26+|===
27+|Right |Left |Center |Default
28+|12 |12 |12 |12
29+|123 |123 |123 |123
30+|1 |1 |1 |1
31+|===
32+
33+Multiline table with caption:
34+
35+.Here’s the caption. It may span multiple lines.
36+[width="80%",cols="^20%,<17%,>20%,<43%",options="header",]
37+|===
38+|Centered Header |Left Aligned |Right Aligned |Default aligned
39+|First |row |12.0 |Example of a row that spans multiple lines.
40+|Second |row |5.0 |Here’s another one. Note the blank line between rows.
41+|===
42+
43+Multiline table without caption:
44+
45+[width="80%",cols="^20%,<17%,>20%,<43%",options="header",]
46+|===
47+|Centered Header |Left Aligned |Right Aligned |Default aligned
48+|First |row |12.0 |Example of a row that spans multiple lines.
49+|Second |row |5.0 |Here’s another one. Note the blank line between rows.
50+|===
51+
52+Table without column headers:
53+
54+[cols=">,<,^,>",]
55+|===
56+|12 |12 |12 |12
57+|123 |123 |123 |123
58+|1 |1 |1 |1
59+|===
60+
61+Multiline table without column headers:
62+
63+[width="80%",cols="^20%,<17%,>20%,43%",]
64+|===
65+|First |row |12.0 |Example of a row that spans multiple lines.
66+|Second |row |5.0 |Here’s another one. Note the blank line between rows.
67+|===
test/writer.asciidoctornew file+648
@@ -0,0 +1,648 @@
1+= Pandoc Test Suite
2+John MacFarlane; Anonymous
3+July 17, 2006
4+
5+This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
6+markdown test suite.
7+
8+'''''
9+
10+== Headers
11+
12+=== Level 2 with an link:/url[embedded link]
13+
14+==== Level 3 with _emphasis_
15+
16+===== Level 4
17+
18+====== Level 5
19+
20+== Level 1
21+
22+=== Level 2 with _emphasis_
23+
24+==== Level 3
25+
26+with no blank line
27+
28+=== Level 2
29+
30+with no blank line
31+
32+'''''
33+
34+== Paragraphs
35+
36+Here’s a regular paragraph.
37+
38+In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item.
39+Because a hard-wrapped line in the middle of a paragraph looked like a list
40+item.
41+
42+Here’s one with a bullet. * criminey.
43+
44+There should be a hard line break +
45+here.
46+
47+'''''
48+
49+== Block Quotes
50+
51+E-mail style:
52+
53+____
54+This is a block quote. It is pretty short.
55+____
56+
57+____
58+--
59+Code in a block quote:
60+
61+....
62+sub status {
63+ print "working";
64+}
65+....
66+
67+A list:
68+
69+[arabic]
70+. item one
71+. item two
72+
73+Nested block quotes:
74+
75+____
76+nested
77+____
78+
79+____
80+nested
81+____
82+
83+--
84+____
85+
86+This should not be a block quote: 2 > 1.
87+
88+And a following paragraph.
89+
90+'''''
91+
92+== Code Blocks
93+
94+Code:
95+
96+....
97+---- (should be four hyphens)
98+
99+sub status {
100+ print "working";
101+}
102+
103+this code block is indented by one tab
104+....
105+
106+And:
107+
108+....
109+ this code block is indented by two tabs
110+
111+These should not be escaped: \$ \\ \> \[ \{
112+....
113+
114+'''''
115+
116+== Lists
117+
118+=== Unordered
119+
120+Asterisks tight:
121+
122+* asterisk 1
123+* asterisk 2
124+* asterisk 3
125+
126+Asterisks loose:
127+
128+* asterisk 1
129+* asterisk 2
130+* asterisk 3
131+
132+Pluses tight:
133+
134+* Plus 1
135+* Plus 2
136+* Plus 3
137+
138+Pluses loose:
139+
140+* Plus 1
141+* Plus 2
142+* Plus 3
143+
144+Minuses tight:
145+
146+* Minus 1
147+* Minus 2
148+* Minus 3
149+
150+Minuses loose:
151+
152+* Minus 1
153+* Minus 2
154+* Minus 3
155+
156+=== Ordered
157+
158+Tight:
159+
160+[arabic]
161+. First
162+. Second
163+. Third
164+
165+and:
166+
167+[arabic]
168+. One
169+. Two
170+. Three
171+
172+Loose using tabs:
173+
174+[arabic]
175+. First
176+. Second
177+. Third
178+
179+and using spaces:
180+
181+[arabic]
182+. One
183+. Two
184+. Three
185+
186+Multiple paragraphs:
187+
188+[arabic]
189+. Item 1, graf one.
190++
191+Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
192+. Item 2.
193+. Item 3.
194+
195+=== Nested
196+
197+* Tab
198+** Tab
199+*** Tab
200+
201+Here’s another:
202+
203+[arabic]
204+. First
205+. Second:
206+* Fee
207+* Fie
208+* Foe
209+. Third
210+
211+Same thing but with paragraphs:
212+
213+[arabic]
214+. First
215+. Second:
216+* Fee
217+* Fie
218+* Foe
219+. Third
220+
221+=== Tabs and spaces
222+
223+* this is a list item indented with tabs
224+* this is a list item indented with spaces
225+** this is an example list item indented with tabs
226+** this is an example list item indented with spaces
227+
228+=== Fancy list markers
229+
230+[arabic, start=2]
231+. begins with 2
232+. and now 3
233++
234+with a continuation
235+[lowerroman, start=4]
236+.. sublist with roman numerals, starting with 4
237+.. more items
238+[upperalpha]
239+... a subsublist
240+... a subsublist
241+
242+Nesting:
243+
244+[upperalpha]
245+. Upper Alpha
246+[upperroman]
247+.. Upper Roman.
248+[arabic, start=6]
249+... Decimal start with 6
250+[loweralpha, start=3]
251+.... Lower alpha with paren
252+
253+Autonumbering:
254+
255+. Autonumber.
256+. More.
257+.. Nested.
258+
259+Should not be a list item:
260+
261+M.A. 2007
262+
263+B. Williams
264+
265+'''''
266+
267+== Definition Lists
268+
269+Tight using spaces:
270+
271+apple::
272+ red fruit
273+orange::
274+ orange fruit
275+banana::
276+ yellow fruit
277+
278+Tight using tabs:
279+
280+apple::
281+ red fruit
282+orange::
283+ orange fruit
284+banana::
285+ yellow fruit
286+
287+Loose:
288+
289+apple::
290+ red fruit
291+orange::
292+ orange fruit
293+banana::
294+ yellow fruit
295+
296+Multiple blocks with italics:
297+
298+_apple_::
299+ red fruit
300+ +
301+ contains seeds, crisp, pleasant to taste
302+_orange_::
303+ orange fruit
304+ +
305+....
306+{ orange code block }
307+....
308+ +
309+ ____
310+ orange block quote
311+ ____
312+
313+Multiple definitions, tight:
314+
315+apple::
316+ red fruit
317+ +
318+ computer
319+orange::
320+ orange fruit
321+ +
322+ bank
323+
324+Multiple definitions, loose:
325+
326+apple::
327+ red fruit
328+ +
329+ computer
330+orange::
331+ orange fruit
332+ +
333+ bank
334+
335+Blank line after term, indented marker, alternate markers:
336+
337+apple::
338+ red fruit
339+ +
340+ computer
341+orange::
342+ orange fruit
343+ +
344+ [arabic]
345+ . sublist
346+ . sublist
347+
348+== HTML Blocks
349+
350+Simple block on one line:
351+
352+foo
353+
354+And nested without indentation:
355+
356+foo
357+
358+bar
359+
360+Interpreted markdown in a table:
361+
362+This is _emphasized_
363+
364+And this is *strong*
365+
366+Here’s a simple block:
367+
368+foo
369+
370+This should be a code block, though:
371+
372+....
373+<div>
374+ foo
375+</div>
376+....
377+
378+As should this:
379+
380+....
381+<div>foo</div>
382+....
383+
384+Now, nested:
385+
386+foo
387+
388+This should just be an HTML comment:
389+
390+Multiline:
391+
392+Code block:
393+
394+....
395+<!-- Comment -->
396+....
397+
398+Just plain comment, with trailing spaces on the line:
399+
400+Code:
401+
402+....
403+<hr />
404+....
405+
406+Hr’s:
407+
408+'''''
409+
410+== Inline Markup
411+
412+This is _emphasized_, and so _is this_.
413+
414+This is *strong*, and so *is this*.
415+
416+An _link:/url[emphasized link]_.
417+
418+*_This is strong and em._*
419+
420+So is *_this_* word.
421+
422+*_This is strong and em._*
423+
424+So is *_this_* word.
425+
426+This is code: `>`, `$`, `\`, `\$`, `<html>`.
427+
428+[line-through]*This is _strikeout_.*
429+
430+Superscripts: a^bc^d a^_hello_^ a^hello there^.
431+
432+Subscripts: H~2~O, H~23~O, H~many of them~O.
433+
434+These should not be superscripts or subscripts, because of the unescaped
435+spaces: a^b c^d, a~b c~d.
436+
437+'''''
438+
439+== Smart quotes, ellipses, dashes
440+
441+``Hello,'' said the spider. ```Shelob' is my name.''
442+
443+`A', `B', and `C' are letters.
444+
445+`Oak,' `elm,' and `beech' are names of trees. So is `pine.'
446+
447+`He said, ``I want to go.''' Were you alive in the 70’s?
448+
449+Here is some quoted ``code`' and a ``http://example.com/?foo=1&bar=2[quoted
450+link]''.
451+
452+Some dashes: one—two — three—four — five.
453+
454+Dashes between numbers: 5–7, 255–66, 1987–1999.
455+
456+Ellipses…and…and….
457+
458+'''''
459+
460+== LaTeX
461+
462+*
463+* latexmath:[2+2=4]
464+* latexmath:[x \in y]
465+* latexmath:[\alpha \wedge \omega]
466+* latexmath:[223]
467+* latexmath:[p]-Tree
468+* Here’s some display math:
469+
470+[latexmath]
471+++++
472+\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}
473+++++
474+* Here’s one that has a line break in it:
475+latexmath:[\alpha + \omega \times x^2].
476+
477+These shouldn’t be math:
478+
479+* To get the famous equation, write `$e = mc^2$`.
480+* $22,000 is a _lot_ of money. So is $34,000. (It worked if ``lot'' is
481+emphasized.)
482+* Shoes ($20) and socks ($5).
483+* Escaped `$`: $73 _this should be emphasized_ 23$.
484+
485+Here’s a LaTeX table:
486+
487+'''''
488+
489+== Special Characters
490+
491+Here is some unicode:
492+
493+* I hat: Î
494+* o umlaut: ö
495+* section: §
496+* set membership: ∈
497+* copyright: ©
498+
499+AT&T has an ampersand in their name.
500+
501+AT&T is another way to write it.
502+
503+This & that.
504+
505+4 < 5.
506+
507+6 > 5.
508+
509+Backslash: \
510+
511+Backtick: `
512+
513+Asterisk: *
514+
515+Underscore: _
516+
517+Left brace: \{
518+
519+Right brace: }
520+
521+Left bracket: [
522+
523+Right bracket: ]
524+
525+Left paren: (
526+
527+Right paren: )
528+
529+Greater-than: >
530+
531+Hash: #
532+
533+Period: .
534+
535+Bang: !
536+
537+Plus: +
538+
539+Minus: -
540+
541+'''''
542+
543+== Links
544+
545+=== Explicit
546+
547+Just a link:/url/[URL].
548+
549+link:/url/[URL and title].
550+
551+link:/url/[URL and title].
552+
553+link:/url/[URL and title].
554+
555+link:/url/[URL and title]
556+
557+link:/url/[URL and title]
558+
559+link:/url/with_underscore[with_underscore]
560+
561+mailto:nobody@nowhere.net[Email link]
562+
563+link:[Empty].
564+
565+=== Reference
566+
567+Foo link:/url/[bar].
568+
569+With link:/url/[embedded [brackets]].
570+
571+link:/url/[b] by itself should be a link.
572+
573+Indented link:/url[once].
574+
575+Indented link:/url[twice].
576+
577+Indented link:/url[thrice].
578+
579+This should [not][] be a link.
580+
581+....
582+[not]: /url
583+....
584+
585+Foo link:/url/[bar].
586+
587+Foo link:/url/[biz].
588+
589+=== With ampersands
590+
591+Here’s a http://example.com/?foo=1&bar=2[link with an ampersand in the URL].
592+
593+Here’s a link with an amersand in the link text: http://att.com/[AT&T].
594+
595+Here’s an link:/script?foo=1&bar=2[inline link].
596+
597+Here’s an link:/script?foo=1&bar=2[inline link in pointy braces].
598+
599+=== Autolinks
600+
601+With an ampersand: http://example.com/?foo=1&bar=2
602+
603+* In a list?
604+* http://example.com/
605+* It should.
606+
607+An e-mail address: nobody@nowhere.net
608+
609+____
610+Blockquoted: http://example.com/
611+____
612+
613+Auto-links should not occur here: `<http://example.com/>`
614+
615+....
616+or here: <http://example.com/>
617+....
618+
619+'''''
620+
621+== Images
622+
623+From ``Voyage dans la Lune'' by Georges Melies (1902):
624+
625+image:lalune.jpg[lalune,title="Voyage dans la Lune"]
626+
627+Here is a movie image:movie.jpg[movie] icon.
628+
629+'''''
630+
631+== Footnotes
632+
633+Here is a footnote reference,footnote:[Here is the footnote. It can go
634+anywhere after the footnote reference. It need not be placed at the end of the
635+document.] and another.[multiblock footnote omitted] This should _not_ be a
636+footnote reference, because it contains a space.[^my note] Here is an inline
637+note.footnote:[This is _easier_ to type. Inline notes may contain
638+http://google.com[links] and `]` verbatim characters, as well as [bracketed
639+text].]
640+
641+____
642+Notes can go in quotes.footnote:[In quote.]
643+____
644+
645+[arabic]
646+. And in list items.footnote:[In list.]
647+
648+This paragraph should not be part of the note, as it is not indented.