git.iko.soy/typeable/pandoc
on master help sign in
Merged branches/context: addition of a ConTeXt writer

<http://www.pragma-ade.nl/>. + Text.Pandoc.Writers.ConTeXt added. + Text.Pandoc modified to export the basic ConTeXt writer. + Main.hs modified to recognize 'context' as a writer. + ConTeXtHeader added to headers + DefaultHeaders.hs template modified to include ConTeXt header + Tests added (writer.context, tables.context), and runtests.pl modified to run them + pandoc.cabal updated to include Text.Pandoc.Writers.ConTeXt. git-svn-id: https://pandoc.googlecode.com/svn/trunk@716 788f1e2b-df1e-0410-8736-df70ead52e1b

commit465b2d791ef5c7b7a7ef9b53e2a4b8bb09a8c1f9 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 15 Jul 2007, 02:56 (19 years ago) parent78aeebc
10 files changed+1140−1
pandoc.cabal+1 src/Main.hs+1 src/Text/Pandoc.hs+2 src/Text/Pandoc/Writers/ConTeXt.hs+225 src/headers/ConTeXtHeader+54 src/templates/DefaultHeaders.hs+4 tests/generate.sh+1 tests/runtests.pl+9−1 tests/tables.context+135 tests/writer.context+708
pandoc.cabal+1
@@ -49,6 +49,7 @@ Exposed-Modules: Text.Pandoc,
4949 Text.Pandoc.Writers.Docbook,
5050 Text.Pandoc.Writers.HTML,
5151 Text.Pandoc.Writers.LaTeX,
52+ Text.Pandoc.Writers.ConTeXt,
5253 Text.Pandoc.Writers.Man,
5354 Text.Pandoc.Writers.Markdown,
5455 Text.Pandoc.Writers.RST,
src/Main.hs+1
@@ -72,6 +72,7 @@ writers = [("native" , (writeDoc, ""))
7272 ,("s5" , (writeS5String, defaultS5Header))
7373 ,("docbook" , (writeDocbook, defaultDocbookHeader))
7474 ,("latex" , (writeLaTeX, defaultLaTeXHeader))
75+ ,("context" , (writeConTeXt, defaultConTeXtHeader))
7576 ,("man" , (writeMan, ""))
7677 ,("markdown" , (writeMarkdown, ""))
7778 ,("rst" , (writeRST, ""))
src/Text/Pandoc.hs+2
@@ -67,6 +67,7 @@ module Text.Pandoc
6767 , writeMarkdown
6868 , writeRST
6969 , writeLaTeX
70+ , writeConTeXt
7071 , writeHtml
7172 , writeHtmlString
7273 , writeS5
@@ -92,6 +93,7 @@ import Text.Pandoc.Readers.HTML
9293import Text.Pandoc.Writers.Markdown
9394import Text.Pandoc.Writers.RST
9495import Text.Pandoc.Writers.LaTeX
96+import Text.Pandoc.Writers.ConTeXt
9597import Text.Pandoc.Writers.HTML
9698import Text.Pandoc.Writers.S5
9799import Text.Pandoc.Writers.Docbook
src/Text/Pandoc/Writers/ConTeXt.hsnew file+225
@@ -0,0 +1,225 @@
1+{-
2+Copyright (C) 2007 John MacFarlane <jgm@berkeley.edu>
3+
4+This program is free software; you can redistribute it and/or modify
5+it under the terms of the GNU General Public License as published by
6+the Free Software Foundation; either version 2 of the License, or
7+(at your option) any later version.
8+
9+This program is distributed in the hope that it will be useful,
10+but WITHOUT ANY WARRANTY; without even the implied warranty of
11+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+GNU General Public License for more details.
13+
14+You should have received a copy of the GNU General Public License
15+along with this program; if not, write to the Free Software
16+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+-}
18+
19+{- |
20+ Module : Text.Pandoc.Writers.ConTeXt
21+ Copyright : Copyright (C) 2006-7 John MacFarlane
22+ License : GNU GPL, version 2 or above
23+
24+ Maintainer : John MacFarlane <jgm@berkeley.edu>
25+ Stability : alpha
26+ Portability : portable
27+
28+Conversion of 'Pandoc' format into ConTeXt.
29+-}
30+module Text.Pandoc.Writers.ConTeXt (
31+ writeConTeXt
32+ ) where
33+import Text.Pandoc.Definition
34+import Text.Pandoc.Shared
35+import Text.Printf ( printf )
36+import Data.List ( (\\), intersperse )
37+import Control.Monad.State
38+
39+type WriterState = Int -- number of next URL reference
40+
41+-- | Convert Pandoc to ConTeXt.
42+writeConTeXt :: WriterOptions -> Pandoc -> String
43+writeConTeXt options document =
44+ evalState (pandocToConTeXt options document) 1
45+
46+pandocToConTeXt :: WriterOptions -> Pandoc -> State WriterState String
47+pandocToConTeXt options (Pandoc meta blocks) = do
48+ main <- blockListToConTeXt blocks
49+ let body = writerIncludeBefore options ++ main ++ writerIncludeAfter options
50+ head <- if writerStandalone options
51+ then contextHeader options meta
52+ else return ""
53+ let toc = if writerTableOfContents options
54+ then "\\placecontent\n\n"
55+ else ""
56+ let foot = if writerStandalone options
57+ then "\n\\stoptext\n"
58+ else ""
59+ return $ head ++ toc ++ body ++ foot
60+
61+-- | Insert bibliographic information into ConTeXt header.
62+contextHeader :: WriterOptions -- ^ Options, including ConTeXt header
63+ -> Meta -- ^ Meta with bibliographic information
64+ -> State WriterState String
65+contextHeader options (Meta title authors date) = do
66+ titletext <- if null title
67+ then return ""
68+ else inlineListToConTeXt title
69+ let authorstext = if null authors
70+ then ""
71+ else if length authors == 1
72+ then stringToConTeXt $ head authors
73+ else stringToConTeXt $ (joinWithSep ", " $
74+ init authors) ++ " & " ++ last authors
75+ let datetext = if date == ""
76+ then ""
77+ else stringToConTeXt date
78+ let titleblock = "\\doctitle{" ++ titletext ++ "}\n\
79+ \ \\author{" ++ authorstext ++ "}\n\
80+ \ \\date{" ++ datetext ++ "}\n\n"
81+ let setupheads = if (writerNumberSections options)
82+ then "\\setupheads[sectionnumber=yes, style=\\bf]\n"
83+ else "\\setupheads[sectionnumber=no, style=\\bf]\n"
84+ let header = writerHeader options
85+ return $ header ++ setupheads ++ titleblock ++ "\\starttext\n\\maketitle\n\n"
86+
87+-- escape things as needed for ConTeXt
88+
89+escapeCharForConTeXt :: Char -> String
90+escapeCharForConTeXt ch =
91+ case ch of
92+ '{' -> "\\letteropenbrace{}"
93+ '}' -> "\\letterclosebrace{}"
94+ '\\' -> "\\letterbackslash{}"
95+ '$' -> "\\$"
96+ '|' -> "\\letterbar{}"
97+ '^' -> "\\letterhat{}"
98+ '%' -> "\\%"
99+ '~' -> "\\lettertilde{}"
100+ '&' -> "\\&"
101+ '#' -> "\\#"
102+ '<' -> "\\letterless{}"
103+ '>' -> "\\lettermore{}"
104+ '_' -> "\\letterunderscore{}"
105+ x -> [x]
106+
107+-- | Escape string for ConTeXt
108+stringToConTeXt :: String -> String
109+stringToConTeXt = concatMap escapeCharForConTeXt
110+
111+-- | Convert Pandoc block element to ConTeXt.
112+blockToConTeXt :: Block -> State WriterState String
113+blockToConTeXt Null = return ""
114+blockToConTeXt (Plain lst) = inlineListToConTeXt lst >>= (return . (++ "\n"))
115+blockToConTeXt (Para lst) = inlineListToConTeXt lst >>= (return . (++ "\n\n"))
116+blockToConTeXt (BlockQuote lst) = do
117+ contents <- blockListToConTeXt lst
118+ return $ "\\startnarrower\n" ++ contents ++ "\\stopnarrower\n\n"
119+blockToConTeXt (CodeBlock str) =
120+ return $ "\\starttyping\n" ++ str ++ "\n\\stoptyping\n"
121+blockToConTeXt (RawHtml str) = return ""
122+blockToConTeXt (BulletList lst) = do
123+ contents <- mapM listItemToConTeXt lst
124+ return $ "\\startltxitem\n" ++ concat contents ++ "\\stopltxitem\n"
125+blockToConTeXt (OrderedList lst) = do
126+ contents <- mapM listItemToConTeXt lst
127+ return $ "\\startltxenum\n" ++ concat contents ++ "\\stopltxenum\n"
128+blockToConTeXt (DefinitionList lst) =
129+ mapM defListItemToConTeXt lst >>= (return . (++ "\n") . concat)
130+blockToConTeXt HorizontalRule = return "\\thinrule\n\n"
131+blockToConTeXt (Header level lst) = do
132+ contents <- inlineListToConTeXt lst
133+ return $ if (level > 0) && (level <= 3)
134+ then "\\" ++ (concat (replicate (level - 1) "sub")) ++
135+ "section{" ++ contents ++ "}\n\n"
136+ else contents ++ "\n\n"
137+blockToConTeXt (Table caption aligns widths heads rows) = do
138+ let colWidths = map printDecimal widths
139+ let colDescriptor colWidth alignment = (case alignment of
140+ AlignLeft -> 'l'
141+ AlignRight -> 'r'
142+ AlignCenter -> 'c'
143+ AlignDefault -> 'l'):
144+ "p(" ++ colWidth ++ "\\textwidth)|"
145+ let colDescriptors = "|" ++ (concat $
146+ zipWith colDescriptor colWidths aligns)
147+ headers <- tableRowToConTeXt heads
148+ captionText <- inlineListToConTeXt caption
149+ let captionText' = if null caption then "none" else captionText
150+ rows' <- mapM tableRowToConTeXt rows
151+ return $ "\\placetable[here]{" ++ captionText' ++ "}\n\\starttable[" ++
152+ colDescriptors ++ "]\n" ++ "\\HL\n" ++ headers ++ "\\HL\n" ++
153+ concat rows' ++ "\\HL\n\\stoptable\n\n"
154+
155+printDecimal :: Float -> String
156+printDecimal = printf "%.2f"
157+
158+tableRowToConTeXt cols = do
159+ cols' <- mapM blockListToConTeXt cols
160+ return $ "\\NC " ++ (concat $ intersperse "\\NC " cols') ++ "\\NC\\AR\n"
161+
162+listItemToConTeXt list = do
163+ contents <- blockListToConTeXt list
164+ return $ "\\item " ++ contents
165+
166+defListItemToConTeXt (term, def) = do
167+ term' <- inlineListToConTeXt term
168+ def' <- blockListToConTeXt def
169+ return $ "\\startdescr{" ++ term' ++ "}\n" ++
170+ def' ++ "\n\\stopdescr\n"
171+
172+-- | Convert list of block elements to ConTeXt.
173+blockListToConTeXt :: [Block] -> State WriterState String
174+blockListToConTeXt lst = mapM blockToConTeXt lst >>= (return . concat)
175+
176+-- | Convert list of inline elements to ConTeXt.
177+inlineListToConTeXt :: [Inline] -- ^ Inlines to convert
178+ -> State WriterState String
179+inlineListToConTeXt lst = mapM inlineToConTeXt lst >>= (return . concat)
180+
181+isQuoted :: Inline -> Bool
182+isQuoted (Quoted _ _) = True
183+isQuoted Apostrophe = True
184+isQuoted _ = False
185+
186+-- | Convert inline element to ConTeXt
187+inlineToConTeXt :: Inline -- ^ Inline to convert
188+ -> State WriterState String
189+inlineToConTeXt (Emph lst) = do
190+ contents <- inlineListToConTeXt lst
191+ return $ "{\\em " ++ contents ++ "}"
192+inlineToConTeXt (Strong lst) = do
193+ contents <- inlineListToConTeXt lst
194+ return $ "{\\bf " ++ contents ++ "}"
195+inlineToConTeXt (Code str) = return $ "\\type{" ++ str ++ "}"
196+inlineToConTeXt (Quoted SingleQuote lst) = do
197+ contents <- inlineListToConTeXt lst
198+ return $ "\\quote{" ++ contents ++ "}"
199+inlineToConTeXt (Quoted DoubleQuote lst) = do
200+ contents <- inlineListToConTeXt lst
201+ return $ "\\quotation{" ++ contents ++ "}"
202+inlineToConTeXt Apostrophe = return "'"
203+inlineToConTeXt EmDash = return "---"
204+inlineToConTeXt EnDash = return "--"
205+inlineToConTeXt Ellipses = return "\\ldots{}"
206+inlineToConTeXt (Str str) = return $ stringToConTeXt str
207+inlineToConTeXt (TeX str) = return str
208+inlineToConTeXt (HtmlInline str) = return ""
209+inlineToConTeXt (LineBreak) = return "\\hfil\\break\n"
210+inlineToConTeXt Space = return " "
211+inlineToConTeXt (Link text (src, _)) = do
212+ next <- get
213+ put (next + 1)
214+ let ref = show next
215+ label <- inlineListToConTeXt text
216+ return $ "\\useurl[" ++ ref ++ "][" ++ src ++ "][][" ++ label ++
217+ "]\\from[" ++ ref ++ "]"
218+inlineToConTeXt (Image alternate (src, tit)) = do
219+ alt <- inlineListToConTeXt alternate
220+ return $ "\\placefigure\n[]\n[fig:" ++ alt ++ "]\n{" ++
221+ tit ++ "}\n{\\externalfigure[" ++ src ++ "]}"
222+inlineToConTeXt (Note contents) = do
223+ contents' <- blockListToConTeXt contents
224+ return $ "\\footnote{" ++ contents' ++ "}"
225+
src/headers/ConTeXtHeadernew file+54
@@ -0,0 +1,54 @@
1+\enableregime[utf] % use UTF-8
2+
3+\setupcolors[state=start]
4+\setupinteraction[state=start, color=middlered] % needed for hyperlinks
5+
6+\setuppapersize[letter][letter] % use letter paper
7+\setuplayout[width=6in, height=9.5in] % page layout
8+\setuppagenumbering[location={footer,center}, style=bold] % number pages
9+\setupbodyfont[11pt] % 11pt font
10+\setupwhitespace[medium] % inter-paragraph spacing
11+
12+\setuphead[section][style=\tfc]
13+\setuphead[subsection][style=\tfb]
14+\setuphead[subsubsection][style=\bf]
15+
16+% define title block commands
17+\unprotect
18+\def\doctitle#1{\gdef\@title{#1}}
19+\def\author#1{\gdef\@author{#1}}
20+\def\date#1{\gdef\@date{#1}}
21+\date{\currentdate} % Default to today unless specified otherwise.
22+\def\maketitle{%
23+ \startalignment[center]
24+ \blank[2*big]
25+ {\tfd \@title}
26+ \blank[3*medium]
27+ {\tfa \@author}
28+ \blank[2*medium]
29+ {\tfa \@date}
30+ \blank[3*medium]
31+ \stopalignment}
32+\protect
33+
34+% define descr (for definition lists)
35+\definedescription[descr][
36+ headstyle=bold,style=normal,align=left,location=hanging,
37+ width=broad,margin=1cm]
38+
39+% define ltxitem (for bulleted lists)
40+\defineitemgroup[ltxitem][levels=4]
41+\setupitemgroup[ltxitem][1][1]
42+\setupitemgroup[ltxitem][2][2]
43+\setupitemgroup[ltxitem][3][3]
44+\setupitemgroup[ltxitem][4][4,packed]
45+
46+% define ltxenum (for enumerated lists)
47+\defineitemgroup[ltxenum][levels=4]
48+\setupitemgroup[ltxenum][1][n]
49+\setupitemgroup[ltxenum][2][a]
50+\setupitemgroup[ltxenum][3][r]
51+\setupitemgroup[ltxenum][4][A,packed]
52+
53+\setupthinrules[width=15em] % width of horizontal rules
54+
src/templates/DefaultHeaders.hs+4
@@ -1,6 +1,7 @@
11-- | Default headers for Pandoc writers.
22module Text.Pandoc.Writers.DefaultHeaders (
33 defaultLaTeXHeader,
4+ defaultConTeXtHeader,
45 defaultDocbookHeader,
56 defaultS5Header,
67 defaultRTFHeader
@@ -10,6 +11,9 @@ import Text.Pandoc.Writers.S5
1011defaultLaTeXHeader :: String
1112defaultLaTeXHeader = "@LaTeXHeader@"
1213
14+defaultConTeXtHeader :: String
15+defaultConTeXtHeader = "@ConTeXtHeader@"
16+
1317defaultDocbookHeader :: String
1418defaultDocbookHeader = "@DocbookHeader@"
1519
tests/generate.sh+1
@@ -8,4 +8,5 @@
88../pandoc -r native -s -w rtf testsuite.native > writer.rtf
99../pandoc -r native -s -w man testsuite.native > writer.man
1010sed -e '/^, Header 1 \[Str "HTML",Space,Str "Blocks"\]/,/^, HorizontalRule/d' testsuite.native | ../pandoc -r native -w docbook -s > writer.docbook
11+sed -e '/^, Header 1 \[Str "LaTeX"\]/,/^, HorizontalRule/d' testsuite.native | ../pandoc -r native -w context -s > writer.context
1112
tests/runtests.pl+9−1
@@ -14,7 +14,7 @@ unless (-x $script) { die "$script is not executable.\n"; }
1414
1515print "Writer tests:\n";
1616
17−my @writeformats = ("html", "latex", "rst", "rtf", "markdown", "man", "native"); # docbook and s5 handled separately
17+my @writeformats = ("html", "latex", "rst", "rtf", "markdown", "man", "native"); # docbook, context, and s5 handled separately
1818my @readformats = ("latex", "native"); # handle html,markdown & rst separately
1919my $source = "testsuite.native";
2020
@@ -61,6 +61,14 @@ test_results("docbook writer", "tmp.docbook", "writer.docbook");
6161print " docbook tables...";
6262test_results("docbook tables", "tmp.docbook", "tables.docbook");
6363
64+print "Testing context writer...";
65+# remove LaTeX tests, as this produces invalid docbook...
66+`sed -e '/^, Header 1 \\[Str "LaTeX"\\]/,/^, HorizontalRule/d' testsuite.native | $script -r native -w context -s > tmp.context`;
67+test_results("context writer", "tmp.context", "writer.context");
68+`$script -r native -w context tables.native > tmp.context`;
69+print " context tables...";
70+test_results("context tables", "tmp.context", "tables.context");
71+
6472print "Testing s5 writer (basic)...";
6573`$script -r native -w s5 -s s5.native > tmp.html`;
6674test_results("s5 writer (basic)", "tmp.html", "s5.basic.html");
tests/tables.contextnew file+135
@@ -0,0 +1,135 @@
1+Simple table with caption:
2+
3+\placetable[here]{Demonstration of simple table syntax.}
4+\starttable[|rp(0.15\textwidth)|lp(0.09\textwidth)|cp(0.16\textwidth)|lp(0.13\textwidth)|]
5+\HL
6+\NC Right
7+\NC Left
8+\NC Center
9+\NC Default
10+\NC\AR
11+\HL
12+\NC 12
13+\NC 12
14+\NC 12
15+\NC 12
16+\NC\AR
17+\NC 123
18+\NC 123
19+\NC 123
20+\NC 123
21+\NC\AR
22+\NC 1
23+\NC 1
24+\NC 1
25+\NC 1
26+\NC\AR
27+\HL
28+\stoptable
29+
30+Simple table without caption:
31+
32+\placetable[here]{none}
33+\starttable[|rp(0.15\textwidth)|lp(0.09\textwidth)|cp(0.16\textwidth)|lp(0.13\textwidth)|]
34+\HL
35+\NC Right
36+\NC Left
37+\NC Center
38+\NC Default
39+\NC\AR
40+\HL
41+\NC 12
42+\NC 12
43+\NC 12
44+\NC 12
45+\NC\AR
46+\NC 123
47+\NC 123
48+\NC 123
49+\NC 123
50+\NC\AR
51+\NC 1
52+\NC 1
53+\NC 1
54+\NC 1
55+\NC\AR
56+\HL
57+\stoptable
58+
59+Simple table indented two spaces:
60+
61+\placetable[here]{Demonstration of simple table syntax.}
62+\starttable[|rp(0.15\textwidth)|lp(0.09\textwidth)|cp(0.16\textwidth)|lp(0.13\textwidth)|]
63+\HL
64+\NC Right
65+\NC Left
66+\NC Center
67+\NC Default
68+\NC\AR
69+\HL
70+\NC 12
71+\NC 12
72+\NC 12
73+\NC 12
74+\NC\AR
75+\NC 123
76+\NC 123
77+\NC 123
78+\NC 123
79+\NC\AR
80+\NC 1
81+\NC 1
82+\NC 1
83+\NC 1
84+\NC\AR
85+\HL
86+\stoptable
87+
88+Multiline table with caption:
89+
90+\placetable[here]{Here's the caption. It may span multiple lines.}
91+\starttable[|cp(0.15\textwidth)|lp(0.14\textwidth)|rp(0.16\textwidth)|lp(0.34\textwidth)|]
92+\HL
93+\NC Centered Header
94+\NC Left Aligned
95+\NC Right Aligned
96+\NC Default aligned
97+\NC\AR
98+\HL
99+\NC First
100+\NC row
101+\NC 12.0
102+\NC Example of a row that spans multiple lines.
103+\NC\AR
104+\NC Second
105+\NC row
106+\NC 5.0
107+\NC Here's another one. Note the blank line between rows.
108+\NC\AR
109+\HL
110+\stoptable
111+
112+Multiline table without caption:
113+
114+\placetable[here]{none}
115+\starttable[|cp(0.15\textwidth)|lp(0.14\textwidth)|rp(0.16\textwidth)|lp(0.34\textwidth)|]
116+\HL
117+\NC Centered Header
118+\NC Left Aligned
119+\NC Right Aligned
120+\NC Default aligned
121+\NC\AR
122+\HL
123+\NC First
124+\NC row
125+\NC 12.0
126+\NC Example of a row that spans multiple lines.
127+\NC\AR
128+\NC Second
129+\NC row
130+\NC 5.0
131+\NC Here's another one. Note the blank line between rows.
132+\NC\AR
133+\HL
134+\stoptable
135+
tests/writer.contextnew file+708
@@ -0,0 +1,708 @@
1+\enableregime[utf] % use UTF-8
2+
3+\setupcolors[state=start]
4+\setupinteraction[state=start, color=middlered] % needed for hyperlinks
5+
6+\setuppapersize[letter][letter] % use letter paper
7+\setuplayout[width=6in, height=9.5in] % page layout
8+\setuppagenumbering[location={footer,center}, style=bold] % number pages
9+\setupbodyfont[11pt] % 11pt font
10+\setupwhitespace[medium] % inter-paragraph spacing
11+
12+\setuphead[section][style=\tfc]
13+\setuphead[subsection][style=\tfb]
14+\setuphead[subsubsection][style=\bf]
15+
16+% define title block commands
17+\unprotect
18+\def\doctitle#1{\gdef\@title{#1}}
19+\def\author#1{\gdef\@author{#1}}
20+\def\date#1{\gdef\@date{#1}}
21+\date{\currentdate} % Default to today unless specified otherwise.
22+\def\maketitle{%
23+ \startalignment[center]
24+ \blank[2*big]
25+ {\tfd \@title}
26+ \blank[3*medium]
27+ {\tfa \@author}
28+ \blank[2*medium]
29+ {\tfa \@date}
30+ \blank[3*medium]
31+ \stopalignment}
32+\protect
33+
34+% define descr (for definition lists)
35+\definedescription[descr][
36+ headstyle=bold,style=normal,align=left,location=hanging,
37+ width=broad,margin=1cm]
38+
39+% define ltxitem (for bulleted lists)
40+\defineitemgroup[ltxitem][levels=4]
41+\setupitemgroup[ltxitem][1][1]
42+\setupitemgroup[ltxitem][2][2]
43+\setupitemgroup[ltxitem][3][3]
44+\setupitemgroup[ltxitem][4][4,packed]
45+
46+% define ltxenum (for enumerated lists)
47+\defineitemgroup[ltxenum][levels=4]
48+\setupitemgroup[ltxenum][1][n]
49+\setupitemgroup[ltxenum][2][a]
50+\setupitemgroup[ltxenum][3][r]
51+\setupitemgroup[ltxenum][4][A,packed]
52+
53+\setupthinrules[width=15em] % width of horizontal rules
54+
55+\setupheads[sectionnumber=no, style=\bf]
56+\doctitle{Pandoc Test Suite}
57+ \author{John MacFarlane \& Anonymous}
58+ \date{July 17, 2006}
59+
60+\starttext
61+\maketitle
62+
63+This is a set of tests for pandoc. Most of them are adapted from John Gruber's markdown test suite.
64+
65+\thinrule
66+
67+\section{Headers}
68+
69+\subsection{Level 2 with an \useurl[1][/url][][embedded link]\from[1]}
70+
71+\subsubsection{Level 3 with {\em emphasis}}
72+
73+Level 4
74+
75+Level 5
76+
77+\section{Level 1}
78+
79+\subsection{Level 2 with {\em emphasis}}
80+
81+\subsubsection{Level 3}
82+
83+with no blank line
84+
85+\subsection{Level 2}
86+
87+with no blank line
88+
89+\thinrule
90+
91+\section{Paragraphs}
92+
93+Here's a regular paragraph.
94+
95+In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item. Because a hard-wrapped line in the middle of a paragraph looked like a list item.
96+
97+Here's one with a bullet. * criminey.
98+
99+There should be a hard line break\hfil\break
100+here.
101+
102+\thinrule
103+
104+\section{Block Quotes}
105+
106+E-mail style:
107+
108+\startnarrower
109+This is a block quote. It is pretty short.
110+
111+\stopnarrower
112+
113+\startnarrower
114+Code in a block quote:
115+
116+\starttyping
117+sub status {
118+ print "working";
119+}
120+\stoptyping
121+A list:
122+
123+\startltxenum
124+\item item one
125+\item item two
126+\stopltxenum
127+Nested block quotes:
128+
129+\startnarrower
130+nested
131+
132+\stopnarrower
133+
134+\startnarrower
135+nested
136+
137+\stopnarrower
138+
139+\stopnarrower
140+
141+This should not be a block quote: 2 \lettermore{} 1.
142+
143+Box-style:
144+
145+\startnarrower
146+Example:
147+
148+\starttyping
149+sub status {
150+ print "working";
151+}
152+\stoptyping
153+\stopnarrower
154+
155+\startnarrower
156+\startltxenum
157+\item do laundry
158+\item take out the trash
159+\stopltxenum
160+\stopnarrower
161+
162+Here's a nested one:
163+
164+\startnarrower
165+Joe said:
166+
167+\startnarrower
168+Don't quote me.
169+
170+\stopnarrower
171+
172+\stopnarrower
173+
174+And a following paragraph.
175+
176+\thinrule
177+
178+\section{Code Blocks}
179+
180+Code:
181+
182+\starttyping
183+---- (should be four hyphens)
184+
185+sub status {
186+ print "working";
187+}
188+
189+this code block is indented by one tab
190+\stoptyping
191+And:
192+
193+\starttyping
194+ this code block is indented by two tabs
195+
196+These should not be escaped: \$ \\ \> \[ \{
197+\stoptyping
198+\thinrule
199+
200+\section{Lists}
201+
202+\subsection{Unordered}
203+
204+Asterisks tight:
205+
206+\startltxitem
207+\item asterisk 1
208+\item asterisk 2
209+\item asterisk 3
210+\stopltxitem
211+Asterisks loose:
212+
213+\startltxitem
214+\item asterisk 1
215+
216+\item asterisk 2
217+
218+\item asterisk 3
219+
220+\stopltxitem
221+Pluses tight:
222+
223+\startltxitem
224+\item Plus 1
225+\item Plus 2
226+\item Plus 3
227+\stopltxitem
228+Pluses loose:
229+
230+\startltxitem
231+\item Plus 1
232+
233+\item Plus 2
234+
235+\item Plus 3
236+
237+\stopltxitem
238+Minuses tight:
239+
240+\startltxitem
241+\item Minus 1
242+\item Minus 2
243+\item Minus 3
244+\stopltxitem
245+Minuses loose:
246+
247+\startltxitem
248+\item Minus 1
249+
250+\item Minus 2
251+
252+\item Minus 3
253+
254+\stopltxitem
255+\subsection{Ordered}
256+
257+Tight:
258+
259+\startltxenum
260+\item First
261+\item Second
262+\item Third
263+\stopltxenum
264+and:
265+
266+\startltxenum
267+\item One
268+\item Two
269+\item Three
270+\stopltxenum
271+Loose using tabs:
272+
273+\startltxenum
274+\item First
275+
276+\item Second
277+
278+\item Third
279+
280+\stopltxenum
281+and using spaces:
282+
283+\startltxenum
284+\item One
285+
286+\item Two
287+
288+\item Three
289+
290+\stopltxenum
291+Multiple paragraphs:
292+
293+\startltxenum
294+\item Item 1, graf one.
295+
296+Item 1. graf two. The quick brown fox jumped over the lazy dog's back.
297+
298+\item Item 2.
299+
300+\item Item 3.
301+
302+\stopltxenum
303+\subsection{Nested}
304+
305+\startltxitem
306+\item Tab
307+\startltxitem
308+\item Tab
309+\startltxitem
310+\item Tab
311+\stopltxitem
312+\stopltxitem
313+\stopltxitem
314+Here's another:
315+
316+\startltxenum
317+\item First
318+\item Second:
319+\startltxitem
320+\item Fee
321+\item Fie
322+\item Foe
323+\stopltxitem
324+\item Third
325+\stopltxenum
326+Same thing but with paragraphs:
327+
328+\startltxenum
329+\item First
330+
331+\item Second:
332+
333+\startltxitem
334+\item Fee
335+\item Fie
336+\item Foe
337+\stopltxitem
338+\item Third
339+
340+\stopltxenum
341+\subsection{Tabs and spaces}
342+
343+\startltxitem
344+\item this is a list item indented with tabs
345+
346+\item this is a list item indented with spaces
347+
348+\startltxitem
349+\item this is an example list item indented with tabs
350+
351+\item this is an example list item indented with spaces
352+
353+\stopltxitem
354+\stopltxitem
355+\thinrule
356+
357+\section{Definition Lists}
358+
359+Tight using spaces:
360+
361+\startdescr{apple}
362+red fruit
363+
364+\stopdescr
365+\startdescr{orange}
366+orange fruit
367+
368+\stopdescr
369+\startdescr{banana}
370+yellow fruit
371+
372+\stopdescr
373+
374+Tight using tabs:
375+
376+\startdescr{apple}
377+red fruit
378+
379+\stopdescr
380+\startdescr{orange}
381+orange fruit
382+
383+\stopdescr
384+\startdescr{banana}
385+yellow fruit
386+
387+\stopdescr
388+
389+Loose:
390+
391+\startdescr{apple}
392+red fruit
393+
394+
395+\stopdescr
396+\startdescr{orange}
397+orange fruit
398+
399+
400+\stopdescr
401+\startdescr{banana}
402+yellow fruit
403+
404+
405+\stopdescr
406+
407+Multiple blocks with italics:
408+
409+\startdescr{{\em apple}}
410+red fruit
411+
412+contains seeds, crisp, pleasant to taste
413+
414+
415+\stopdescr
416+\startdescr{{\em orange}}
417+orange fruit
418+
419+\starttyping
420+{ orange code block }
421+\stoptyping
422+\startnarrower
423+orange block quote
424+
425+\stopnarrower
426+
427+
428+\stopdescr
429+
430+\section{HTML Blocks}
431+
432+Simple block on one line:
433+
434+foo
435+And nested without indentation:
436+
437+foo
438+bar
439+Interpreted markdown in a table:
440+
441+This is {\em emphasized}
442+And this is {\bf strong}
443+Here's a simple block:
444+
445+foo
446+This should be a code block, though:
447+
448+\starttyping
449+<div>
450+ foo
451+</div>
452+\stoptyping
453+As should this:
454+
455+\starttyping
456+<div>foo</div>
457+\stoptyping
458+Now, nested:
459+
460+foo
461+This should just be an HTML comment:
462+
463+Multiline:
464+
465+Code block:
466+
467+\starttyping
468+<!-- Comment -->
469+\stoptyping
470+Just plain comment, with trailing spaces on the line:
471+
472+Code:
473+
474+\starttyping
475+<hr />
476+\stoptyping
477+Hr's:
478+
479+\thinrule
480+
481+\section{Inline Markup}
482+
483+This is {\em emphasized}, and so {\em is this}.
484+
485+This is {\bf strong}, and so {\bf is this}.
486+
487+An {\em \useurl[2][/url][][emphasized link]\from[2]}.
488+
489+{\bf {\em This is strong and em.}}
490+
491+So is {\bf {\em this}} word.
492+
493+{\bf {\em This is strong and em.}}
494+
495+So is {\bf {\em this}} word.
496+
497+This is code: \type{>}, \type{$}, \type{\}, \type{\$}, \type{<html>}.
498+
499+\thinrule
500+
501+\section{Smart quotes, ellipses, dashes}
502+
503+\quotation{Hello,} said the spider. \quotation{\quote{Shelob} is my name.}
504+
505+\quote{A}, \quote{B}, and \quote{C} are letters.
506+
507+\quote{Oak,} \quote{elm,} and \quote{beech} are names of trees. So is \quote{pine.}
508+
509+\quote{He said, \quotation{I want to go.}} Were you alive in the 70's?
510+
511+Here is some quoted \quote{\type{code}} and a \quotation{\useurl[3][http://example.com/?foo=1&bar=2][][quoted link]\from[3]}.
512+
513+Some dashes: one---two---three---four---five.
514+
515+Dashes between numbers: 5--7, 255--66, 1987--1999.
516+
517+Ellipses\ldots{}and\ldots{}and\ldots{}.
518+
519+\thinrule
520+
521+\section{Special Characters}
522+
523+Here is some unicode:
524+
525+\startltxitem
526+\item I hat: Î
527+\item o umlaut: ö
528+\item section: §
529+\item set membership: ∈
530+\item copyright: ©
531+\stopltxitem
532+AT\&T has an ampersand in their name.
533+
534+AT\&T is another way to write it.
535+
536+This \& that.
537+
538+4 \letterless{} 5.
539+
540+6 \lettermore{} 5.
541+
542+Backslash: \letterbackslash{}
543+
544+Backtick: `
545+
546+Asterisk: *
547+
548+Underscore: \letterunderscore{}
549+
550+Left brace: \letteropenbrace{}
551+
552+Right brace: \letterclosebrace{}
553+
554+Left bracket: [
555+
556+Right bracket: ]
557+
558+Left paren: (
559+
560+Right paren: )
561+
562+Greater-than: \lettermore{}
563+
564+Hash: \#
565+
566+Period: .
567+
568+Bang: !
569+
570+Plus: +
571+
572+Minus: -
573+
574+\thinrule
575+
576+\section{Links}
577+
578+\subsection{Explicit}
579+
580+Just a \useurl[4][/url/][][URL]\from[4].
581+
582+\useurl[5][/url/][][URL and title]\from[5].
583+
584+\useurl[6][/url/][][URL and title]\from[6].
585+
586+\useurl[7][/url/][][URL and title]\from[7].
587+
588+\useurl[8][/url/][][URL and title]\from[8]
589+
590+\useurl[9][/url/][][URL and title]\from[9]
591+
592+\useurl[10][/url/with_underscore][][with\letterunderscore{}underscore]\from[10]
593+
594+\useurl[11][mailto:nobody@nowhere.net][][Email link]\from[11]
595+
596+\useurl[12][][][Empty]\from[12].
597+
598+\subsection{Reference}
599+
600+Foo \useurl[13][/url/][][bar]\from[13].
601+
602+Foo \useurl[14][/url/][][bar]\from[14].
603+
604+Foo \useurl[15][/url/][][bar]\from[15].
605+
606+With \useurl[16][/url/][][embedded [brackets]]\from[16].
607+
608+\useurl[17][/url/][][b]\from[17] by itself should be a link.
609+
610+Indented \useurl[18][/url][][once]\from[18].
611+
612+Indented \useurl[19][/url][][twice]\from[19].
613+
614+Indented \useurl[20][/url][][thrice]\from[20].
615+
616+This should [not][] be a link.
617+
618+\starttyping
619+[not]: /url
620+\stoptyping
621+Foo \useurl[21][/url/][][bar]\from[21].
622+
623+Foo \useurl[22][/url/][][biz]\from[22].
624+
625+\subsection{With ampersands}
626+
627+Here's a \useurl[23][http://example.com/?foo=1&bar=2][][link with an ampersand in the URL]\from[23].
628+
629+Here's a link with an amersand in the link text: \useurl[24][http://att.com/][][AT\&T]\from[24].
630+
631+Here's an \useurl[25][/script?foo=1&bar=2][][inline link]\from[25].
632+
633+Here's an \useurl[26][/script?foo=1&bar=2][][inline link in pointy braces]\from[26].
634+
635+\subsection{Autolinks}
636+
637+With an ampersand: \useurl[27][http://example.com/?foo=1&bar=2][][http://example.com/?foo=1\&bar=2]\from[27]
638+
639+\startltxitem
640+\item In a list?
641+\item \useurl[28][http://example.com/][][http://example.com/]\from[28]
642+\item It should.
643+\stopltxitem
644+An e-mail address: \useurl[29][mailto:nobody@nowhere.net][][nobody@nowhere.net]\from[29]
645+
646+\startnarrower
647+Blockquoted: \useurl[30][http://example.com/][][http://example.com/]\from[30]
648+
649+\stopnarrower
650+
651+Auto-links should not occur here: \type{<http://example.com/>}
652+
653+\starttyping
654+or here: <http://example.com/>
655+\stoptyping
656+\thinrule
657+
658+\section{Images}
659+
660+From \quotation{Voyage dans la Lune} by Georges Melies (1902):
661+
662+\placefigure
663+[]
664+[fig:lalune]
665+{Voyage dans la Lune}
666+{\externalfigure[lalune.jpg]}
667+
668+Here is a movie \placefigure
669+[]
670+[fig:movie]
671+{}
672+{\externalfigure[movie.jpg]} icon.
673+
674+\thinrule
675+
676+\section{Footnotes}
677+
678+Here is a footnote reference,\footnote{Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.
679+
680+} and another.\footnote{Here's the long note. This one contains multiple blocks.
681+
682+Subsequent blocks are indented to show that they belong to the footnote (as with list items).
683+
684+\starttyping
685+ { <code> }
686+\stoptyping
687+If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.
688+
689+} This should {\em not} be a footnote reference, because it contains a space.[\letterhat{}my note] Here is an inline note.\footnote{This is {\em easier} to type. Inline notes may contain \useurl[31][http://google.com][][links]\from[31] and \type{]} verbatim characters, as well as [bracketed text].
690+
691+}
692+
693+\startnarrower
694+Notes can go in quotes.\footnote{In quote.
695+
696+}
697+
698+\stopnarrower
699+
700+\startltxenum
701+\item And in list items.\footnote{In list.
702+
703+}
704+\stopltxenum
705+This paragraph should not be part of the note, as it is not indented.
706+
707+
708+\stoptext