From e6b94df64a233c1e427b54ca1eaada3b23e00da9 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Wed, 2 Feb 2022 23:20:25 +0100 Subject: [PATCH] ConTeXt writer: tag paragraphs Paragraphs are enclosed by `\startparagraph` and `\stopparagraph` commands. This ensures better tagging results in PDF output. --- src/Text/Pandoc/Writers/ConTeXt.hs | 2 +- test/tables.context | 14 ++ test/writer.context | 386 ++++++++++++++++++++++++++++- test/writers-lang-and-dir.context | 28 +++ 4 files changed, 418 insertions(+), 12 deletions(-) diff --git a/src/Text/Pandoc/Writers/ConTeXt.hs b/src/Text/Pandoc/Writers/ConTeXt.hs index 51674da87a5a..719fbd134ec0 100644 --- a/src/Text/Pandoc/Writers/ConTeXt.hs +++ b/src/Text/Pandoc/Writers/ConTeXt.hs @@ -173,7 +173,7 @@ blockToConTeXt (SimpleFigure attr txt (src, _)) = do return $ blankline $$ "\\placefigure" <> label <> braces capt <> img <> blankline blockToConTeXt (Para lst) = do contents <- inlineListToConTeXt lst - return $ contents <> blankline + return $ "\\bpar" $$ contents $$ "\\epar" <> blankline blockToConTeXt (LineBlock lns) = do let emptyToBlankline doc = if isEmpty doc then blankline diff --git a/test/tables.context b/test/tables.context index 556d2c216390..ede39b168a53 100644 --- a/test/tables.context +++ b/test/tables.context @@ -1,4 +1,6 @@ +\bpar Simple table with caption: +\epar \startplacetable[title={Demonstration of simple table syntax.}] \startxtable @@ -35,7 +37,9 @@ Simple table with caption: \stopxtable \stopplacetable +\bpar Simple table without caption: +\epar \startplacetable[location=none] \startxtable @@ -72,7 +76,9 @@ Simple table without caption: \stopxtable \stopplacetable +\bpar Simple table indented two spaces: +\epar \startplacetable[title={Demonstration of simple table syntax.}] \startxtable @@ -109,7 +115,9 @@ Simple table indented two spaces: \stopxtable \stopplacetable +\bpar Multiline table with caption: +\epar \startplacetable[title={Here's the caption. It may span multiple lines.}] \startxtable @@ -142,7 +150,9 @@ blank line between rows. \stopxcell \stopxtable \stopplacetable +\bpar Multiline table without caption: +\epar \startplacetable[location=none] \startxtable @@ -175,7 +185,9 @@ blank line between rows. \stopxcell \stopxtable \stopplacetable +\bpar Table without column headers: +\epar \startplacetable[location=none] \startxtable @@ -204,7 +216,9 @@ Table without column headers: \stopxtable \stopplacetable +\bpar Multiline table without column headers: +\epar \startplacetable[location=none] \startxtable diff --git a/test/writer.context b/test/writer.context index 32a8f80042bd..a83170e09ce6 100644 --- a/test/writer.context +++ b/test/writer.context @@ -71,8 +71,10 @@ \bigskip \stopalignment +\bpar This is a set of tests for pandoc. Most of them are adapted from John Gruber's markdown test suite. +\epar \thinrule @@ -95,39 +97,57 @@ link}[url(/url)]},reference={level-2-with-an-embedded-link}] \subsubsection[title={Level 3},reference={level-3}] +\bpar with no blank line +\epar \subsection[title={Level 2},reference={level-2}] +\bpar with no blank line +\epar \thinrule \section[title={Paragraphs},reference={paragraphs}] +\bpar Here's a regular paragraph. +\epar +\bpar 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. +\epar +\bpar Here's one with a bullet. * criminey. +\epar +\bpar There should be a hard line break\crlf here. +\epar \thinrule \section[title={Block Quotes},reference={block-quotes}] +\bpar E-mail style: +\epar \startblockquote +\bpar This is a block quote. It is pretty short. +\epar \stopblockquote \startblockquote +\bpar Code in a block quote: +\epar \starttyping sub status { @@ -135,7 +155,9 @@ sub status { } \stoptyping +\bpar A list: +\epar \startenumerate[n,packed][stopper=.] \item @@ -144,26 +166,38 @@ A list: item two \stopenumerate +\bpar Nested block quotes: +\epar \startblockquote +\bpar nested +\epar \stopblockquote \startblockquote +\bpar nested +\epar \stopblockquote \stopblockquote +\bpar This should not be a block quote: 2 > 1. +\epar +\bpar And a following paragraph. +\epar \thinrule \section[title={Code Blocks},reference={code-blocks}] +\bpar Code: +\epar \starttyping ---- (should be four hyphens) @@ -175,7 +209,9 @@ sub status { this code block is indented by one tab \stoptyping +\bpar And: +\epar \starttyping this code block is indented by two tabs @@ -189,7 +225,9 @@ These should not be escaped: \$ \\ \> \[ \{ \subsection[title={Unordered},reference={unordered}] +\bpar Asterisks tight: +\epar \startitemize[packed] \item @@ -200,18 +238,28 @@ Asterisks tight: asterisk 3 \stopitemize +\bpar Asterisks loose: +\epar \startitemize \item + \bpar asterisk 1 + \epar \item + \bpar asterisk 2 + \epar \item + \bpar asterisk 3 + \epar \stopitemize +\bpar Pluses tight: +\epar \startitemize[packed] \item @@ -222,18 +270,28 @@ Pluses tight: Plus 3 \stopitemize +\bpar Pluses loose: +\epar \startitemize \item + \bpar Plus 1 + \epar \item + \bpar Plus 2 + \epar \item + \bpar Plus 3 + \epar \stopitemize +\bpar Minuses tight: +\epar \startitemize[packed] \item @@ -244,20 +302,30 @@ Minuses tight: Minus 3 \stopitemize +\bpar Minuses loose: +\epar \startitemize \item + \bpar Minus 1 + \epar \item + \bpar Minus 2 + \epar \item + \bpar Minus 3 + \epar \stopitemize \subsection[title={Ordered},reference={ordered}] +\bpar Tight: +\epar \startenumerate[n,packed][stopper=.] \item @@ -268,7 +336,9 @@ Tight: Third \stopenumerate +\bpar and: +\epar \startenumerate[n,packed][stopper=.] \item @@ -279,39 +349,65 @@ and: Three \stopenumerate +\bpar Loose using tabs: +\epar \startenumerate[n][stopper=.] \item + \bpar First + \epar \item + \bpar Second + \epar \item + \bpar Third + \epar \stopenumerate +\bpar and using spaces: +\epar \startenumerate[n][stopper=.] \item + \bpar One + \epar \item + \bpar Two + \epar \item + \bpar Three + \epar \stopenumerate +\bpar Multiple paragraphs: +\epar \startenumerate[n][stopper=.] \item + \bpar Item 1, graf one. + \epar + \bpar Item 1. graf two. The quick brown fox jumped over the lazy dog's back. + \epar \item + \bpar Item 2. + \epar \item + \bpar Item 3. + \epar \stopenumerate \subsection[title={Nested},reference={nested}] @@ -329,7 +425,9 @@ Multiple paragraphs: \stopitemize \stopitemize +\bpar Here's another: +\epar \startenumerate[n,packed][stopper=.] \item @@ -348,13 +446,19 @@ Here's another: Third \stopenumerate +\bpar Same thing but with paragraphs: +\epar \startenumerate[n][stopper=.] \item + \bpar First + \epar \item + \bpar Second: + \epar \startitemize[packed] \item @@ -365,22 +469,32 @@ Same thing but with paragraphs: Foe \stopitemize \item + \bpar Third + \epar \stopenumerate \subsection[title={Tabs and spaces},reference={tabs-and-spaces}] \startitemize \item + \bpar this is a list item indented with tabs + \epar \item + \bpar this is a list item indented with spaces + \epar \startitemize \item + \bpar this is an example list item indented with tabs + \epar \item + \bpar this is an example list item indented with spaces + \epar \stopitemize \stopitemize @@ -388,11 +502,17 @@ Same thing but with paragraphs: \startenumerate[n][start=2,left=(,stopper=)] \item + \bpar begins with 2 + \epar \item + \bpar and now 3 + \epar + \bpar with a continuation + \epar \startenumerate[r,packed][start=4,stopper=.] \item @@ -408,7 +528,9 @@ Same thing but with paragraphs: \stopenumerate \stopenumerate +\bpar Nesting: +\epar \startenumerate[A,packed][stopper=.] \item @@ -427,7 +549,9 @@ Nesting: \stopenumerate \stopenumerate +\bpar Autonumbering: +\epar \startenumerate[n,packed] \item @@ -440,17 +564,25 @@ Autonumbering: \stopenumerate \stopenumerate +\bpar Should not be a list item: +\epar +\bpar M.A.~2007 +\epar +\bpar B. Williams +\epar \thinrule \section[title={Definition Lists},reference={definition-lists}] +\bpar Tight using spaces: +\epar \startdescription{apple} red fruit @@ -464,7 +596,9 @@ Tight using spaces: yellow fruit \stopdescription +\bpar Tight using tabs: +\epar \startdescription{apple} red fruit @@ -478,41 +612,61 @@ Tight using tabs: yellow fruit \stopdescription +\bpar Loose: +\epar \startdescription{apple} + \bpar red fruit + \epar \stopdescription \startdescription{orange} + \bpar orange fruit + \epar \stopdescription \startdescription{banana} + \bpar yellow fruit + \epar \stopdescription +\bpar Multiple blocks with italics: +\epar \startdescription{{\em apple}} + \bpar red fruit + \epar + \bpar contains seeds, crisp, pleasant to taste + \epar \stopdescription \startdescription{{\em orange}} + \bpar orange fruit + \epar \starttyping { orange code block } \stoptyping \startblockquote + \bpar orange block quote + \epar \stopblockquote \stopdescription +\bpar Multiple definitions, tight: +\epar \startdescription{apple} red fruit @@ -526,30 +680,48 @@ Multiple definitions, tight: bank \stopdescription +\bpar Multiple definitions, loose: +\epar \startdescription{apple} + \bpar red fruit + \epar + \bpar computer + \epar \stopdescription \startdescription{orange} + \bpar orange fruit + \epar + \bpar bank + \epar \stopdescription +\bpar Blank line after term, indented marker, alternate markers: +\epar \startdescription{apple} + \bpar red fruit + \epar + \bpar computer + \epar \stopdescription \startdescription{orange} + \bpar orange fruit + \epar \startenumerate[n,packed][stopper=.] \item @@ -561,25 +733,39 @@ Blank line after term, indented marker, alternate markers: \section[title={HTML Blocks},reference={html-blocks}] +\bpar Simple block on one line: +\epar foo +\bpar And nested without indentation: +\epar +\bpar foo +\epar bar +\bpar Interpreted markdown in a table: +\epar This is {\em emphasized} And this is {\bf strong} +\bpar Here's a simple block: +\epar +\bpar foo +\epar +\bpar This should be a code block, though: +\epar \starttyping
@@ -587,87 +773,143 @@ This should be a code block, though:
\stoptyping +\bpar As should this: +\epar \starttyping
foo
\stoptyping +\bpar Now, nested: +\epar foo +\bpar This should just be an HTML comment: +\epar +\bpar Multiline: +\epar +\bpar Code block: +\epar \starttyping \stoptyping +\bpar Just plain comment, with trailing spaces on the line: +\epar +\bpar Code: +\epar \starttyping
\stoptyping +\bpar Hr's: +\epar \thinrule \section[title={Inline Markup},reference={inline-markup}] +\bpar This is {\em emphasized}, and so {\em is this}. +\epar +\bpar This is {\bf strong}, and so {\bf is this}. +\epar +\bpar An {\em \goto{emphasized link}[url(/url)]}. +\epar +\bpar {\bf {\em This is strong and em.}} +\epar +\bpar So is {\bf {\em this}} word. +\epar +\bpar {\bf {\em This is strong and em.}} +\epar +\bpar So is {\bf {\em this}} word. +\epar +\bpar This is code: \type{>}, \type{$}, \type{\}, \type{\$}, \type{}. +\epar +\bpar \overstrikes{This is {\em strikeout}.} +\epar +\bpar Superscripts: a\high{bc}d a\high{{\em hello}} a\high{hello~there}. +\epar +\bpar Subscripts: H\low{2}O, H\low{23}O, H\low{many~of~them}O. +\epar +\bpar These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a\lettertilde{}b c\lettertilde{}d. +\epar \thinrule \section[title={Smart quotes, ellipses, dashes},reference={smart-quotes-ellipses-dashes}] +\bpar \quotation{Hello,} said the spider. \quotation{\quote{Shelob} is my name.} +\epar +\bpar \quote{A}, \quote{B}, and \quote{C} are letters. +\epar +\bpar \quote{Oak,} \quote{elm,} and \quote{beech} are names of trees. So is \quote{pine.} +\epar +\bpar \quote{He said, \quotation{I want to go.}} Were you alive in the 70's? +\epar +\bpar Here is some quoted \quote{\type{code}} and a \quotation{\goto{quoted link}[url(http://example.com/?foo=1&bar=2)]}. +\epar +\bpar Some dashes: one---two --- three---four --- five. +\epar +\bpar Dashes between numbers: 5--7, 255--66, 1987--1999. +\epar +\bpar Ellipses\ldots{}and\ldots{}and\ldots{}. +\epar \thinrule @@ -693,7 +935,9 @@ Ellipses\ldots{}and\ldots{}and\ldots{}. Here's one that has a line break in it: $\alpha + \omega \times x^2$. \stopitemize +\bpar These shouldn't be math: +\epar \startitemize[packed] \item @@ -707,7 +951,9 @@ These shouldn't be math: Escaped \type{$}: \$73 {\em this should be emphasized} 23\$. \stopitemize +\bpar Here's a LaTeX table: +\epar \begin{tabular}{|l|l|}\hline Animal & Number \\ \hline @@ -719,7 +965,9 @@ Cat & 1 \\ \hline \section[title={Special Characters},reference={special-characters}] +\bpar Here is some unicode: +\epar \startitemize[packed] \item @@ -734,47 +982,89 @@ Here is some unicode: copyright: © \stopitemize +\bpar AT&T has an ampersand in their name. +\epar +\bpar AT&T is another way to write it. +\epar +\bpar This & that. +\epar +\bpar 4 < 5. +\epar +\bpar 6 > 5. +\epar +\bpar Backslash: \letterbackslash{} +\epar +\bpar Backtick: ` +\epar +\bpar Asterisk: * +\epar +\bpar Underscore: _ +\epar +\bpar Left brace: \{ +\epar +\bpar Right brace: \} +\epar +\bpar Left bracket: {[} +\epar +\bpar Right bracket: {]} +\epar +\bpar Left paren: ( +\epar +\bpar Right paren: ) +\epar +\bpar Greater-than: > +\epar +\bpar Hash: \# +\epar +\bpar Period: . +\epar +\bpar Bang: ! +\epar +\bpar Plus: + +\epar +\bpar Minus: - +\epar \thinrule @@ -782,63 +1072,109 @@ Minus: - \subsection[title={Explicit},reference={explicit}] +\bpar Just a \goto{URL}[url(/url/)]. +\epar +\bpar \goto{URL and title}[url(/url/)]. +\epar +\bpar \goto{URL and title}[url(/url/)]. +\epar +\bpar \goto{URL and title}[url(/url/)]. +\epar +\bpar \goto{URL and title}[url(/url/)] +\epar +\bpar \goto{URL and title}[url(/url/)] +\epar +\bpar \goto{with_underscore}[url(/url/with_underscore)] +\epar +\bpar \goto{Email link}[url(mailto:nobody@nowhere.net)] +\epar +\bpar \goto{Empty}[url()]. +\epar \subsection[title={Reference},reference={reference}] +\bpar Foo \goto{bar}[url(/url/)]. +\epar +\bpar With \goto{embedded {[}brackets{]}}[url(/url/)]. +\epar +\bpar \goto{b}[url(/url/)] by itself should be a link. +\epar +\bpar Indented \goto{once}[url(/url)]. +\epar +\bpar Indented \goto{twice}[url(/url)]. +\epar +\bpar Indented \goto{thrice}[url(/url)]. +\epar +\bpar This should {[}not{]}{[}{]} be a link. +\epar \starttyping [not]: /url \stoptyping +\bpar Foo \goto{bar}[url(/url/)]. +\epar +\bpar Foo \goto{biz}[url(/url/)]. +\epar \subsection[title={With ampersands},reference={with-ampersands}] +\bpar Here's a \goto{link with an ampersand in the URL}[url(http://example.com/?foo=1&bar=2)]. +\epar +\bpar Here's a link with an amersand in the link text: \goto{AT&T}[url(http://att.com/)]. +\epar +\bpar Here's an \goto{inline link}[url(/script?foo=1&bar=2)]. +\epar +\bpar Here's an \goto{inline link in pointy braces}[url(/script?foo=1&bar=2)]. +\epar \subsection[title={Autolinks},reference={autolinks}] +\bpar With an ampersand: \useURL[url1][http://example.com/?foo=1&bar=2]\from[url1] +\epar \startitemize[packed] \item @@ -849,13 +1185,19 @@ With an ampersand: \useURL[url1][http://example.com/?foo=1&bar=2]\from[url1] It should. \stopitemize +\bpar An e-mail address: \goto{nobody@nowhere.net}[url(mailto:nobody@nowhere.net)] +\epar \startblockquote +\bpar Blockquoted: \useURL[url3][http://example.com/]\from[url3] +\epar \stopblockquote +\bpar Auto-links should not occur here: \type{} +\epar \starttyping or here: @@ -865,44 +1207,66 @@ or here: \section[title={Images},reference={images}] +\bpar From \quotation{Voyage dans la Lune} by Georges Melies (1902): +\epar \placefigure{lalune}{\externalfigure[lalune.jpg]} +\bpar Here is a movie {\externalfigure[movie.jpg]} icon. +\epar \thinrule \section[title={Footnotes},reference={footnotes}] -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.} and another.\startbuffer Here's the long note. This one contains - multiple blocks. +\bpar +Here is a footnote reference,\footnote{\bpar + Here is the footnote. It can go anywhere after the footnote reference. It need + not be placed at the end of the document. + \epar} and another.\startbuffer \bpar + Here's the long note. This one contains multiple blocks. + \epar + \bpar Subsequent blocks are indented to show that they belong to the footnote (as with list items). + \epar \starttyping { } \stoptyping + \bpar If you want, you can indent every line, but you can also be lazy and just - indent the first line of each block.\stopbuffer\footnote{\getbuffer} This -should {\em not} be a footnote reference, because it contains a space.{[}^my -note{]} Here is an inline note.\footnote{This is {\em easier} to type. Inline - notes may contain \goto{links}[url(http://google.com)] and \type{]} verbatim - characters, as well as {[}bracketed text{]}.} + indent the first line of each block. + \epar\stopbuffer\footnote{\getbuffer} This should {\em not} be a footnote +reference, because it contains a space.{[}^my note{]} Here is an inline +note.\footnote{\bpar + This is {\em easier} to type. Inline notes may contain + \goto{links}[url(http://google.com)] and \type{]} verbatim characters, as well + as {[}bracketed text{]}. + \epar} +\epar \startblockquote -Notes can go in quotes.\footnote{In quote.} +\bpar +Notes can go in quotes.\footnote{\bpar + In quote. + \epar} +\epar \stopblockquote \startenumerate[n,packed][stopper=.] \item - And in list items.\footnote{In list.} + And in list items.\footnote{\bpar + In list. + \epar} \stopenumerate +\bpar This paragraph should not be part of the note, as it is not indented. +\epar \stoptext diff --git a/test/writers-lang-and-dir.context b/test/writers-lang-and-dir.context index ecb04d20836a..835170f5a20b 100644 --- a/test/writers-lang-and-dir.context +++ b/test/writers-lang-and-dir.context @@ -65,46 +65,68 @@ Some text and +\bpar div contents +\epar +\bpar and more text. +\epar +\bpar Next paragraph with a span and a word-thatincludesaspanright? +\epar \section[title={Directionality},reference={directionality}] Some text and \startalignment[righttoleft] +\bpar rtl div contents +\epar \stopalignment +\bpar and more text. +\epar \startalignment[lefttoright] +\bpar and a ltr div. with a {\righttoleft rtl span}. +\epar \stopalignment +\bpar Next paragraph with a {\righttoleft rtl span} and a word-that-includesa{\lefttoright ltrspan}right? +\epar \section[title={Languages},reference={languages}] Some text and \start\language[de] +\bpar German div contents +\epar \stop +\bpar and more text. +\epar +\bpar Next paragraph with a {\language[en-gb]British span} and a word-that-includesa{\language[de-ch]Swiss German span}right? +\epar +\bpar Some {\language[es]Spanish text}. +\epar \section[title={Combined},reference={combined}] @@ -112,15 +134,21 @@ Some text and \start\language[fr] \startalignment[righttoleft] +\bpar French rtl div contents +\epar \stopalignment \stop +\bpar and more text. +\epar +\bpar Next paragraph with a {\language[en-gb]{\lefttoright British ltr span}} and a word-that-includesa{\language[de-ch]{\lefttoright Swiss German ltr span}}right? +\epar \stoptext