git.iko.soy/typeable/pandoc
on master help sign in
Make `plain` output plainer.

Previously we used the following Project Gutenberg conventions for plain output: - extra space before and after level 1 and 2 headings - all-caps for strong emphasis `LIKE THIS` - underscores surrounding regular emphasis `_like this_` This commit makes `plain` output plainer. Strong and Emph inlines are rendered without special formatting. Headings are also rendered without special formatting, and with only one blank line following. To restore the former behavior, use `-t plain+gutenberg`. API change: Add `Ext_gutenberg` constructor to `Extension`. See #5741.

commitd247e9f72e9c9a86cb0053cffc607b5f84f8b3a4 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 22 Sep 2019, 10:57 (7 years ago) parenta9d106d
6 files changed+64−96
MANUAL.txt+8 src/Text/Pandoc/Extensions.hs+1 src/Text/Pandoc/Writers/Markdown.hs+16−5 test/Tests/Writers/Plain.hs+3−1 test/command/4529.md+1−1 test/writer.plain+35−89
MANUAL.txt+8
@@ -4544,6 +4544,14 @@ in several respects:
45444544 we must either disallow lazy wrapping or require a blank line between
45454545 list items.
45464546
4547+#### Extension: `gutenberg` ####
4548+
4549+Use [Project Gutenberg] conventions for `plain` output:
4550+all-caps for strong emphasis, surround by underscores
4551+for regular emphasis, add extra blank space around headings.
4552+
4553+ [Project Gutenberg]: https://www.gutenberg.org
4554+
45474555Markdown variants
45484556-----------------
45494557
src/Text/Pandoc/Extensions.hs+1
@@ -155,6 +155,7 @@ data Extension =
155155 | Ext_tex_math_double_backslash -- ^ TeX math btw \\(..\\) \\[..\\]
156156 | Ext_tex_math_single_backslash -- ^ TeX math btw \(..\) \[..\]
157157 | Ext_yaml_metadata_block -- ^ YAML metadata block
158+ | Ext_gutenberg -- ^ Use Project Gutenberg conventions for plain
158159 deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic)
159160
160161-- | Extensions to be used with pandoc-flavored markdown.
src/Text/Pandoc/Writers/Markdown.hs+16−5
@@ -523,16 +523,22 @@ blockToMarkdown' opts (Header level attr inlines) = do
523523 contents <- inlineListToMarkdown opts $
524524 -- ensure no newlines; see #3736
525525 walk lineBreakToSpace $
526− if level == 1 && plain
526+ if level == 1 && plain && isEnabled Ext_gutenberg opts
527527 then capitalize inlines
528528 else inlines
529529 let setext = writerSetextHeaders opts
530530 hdr = nowrap $ case level of
531− 1 | plain -> blanklines 3 <> contents <> blanklines 2
531+ 1 | plain ->
532+ if isEnabled Ext_gutenberg opts
533+ then blanklines 3 <> contents <> blanklines 2
534+ else contents <> blankline
532535 | setext ->
533536 contents <> attr' <> cr <> text (replicate (offset contents) '=') <>
534537 blankline
535− 2 | plain -> blanklines 2 <> contents <> blankline
538+ 2 | plain ->
539+ if isEnabled Ext_gutenberg opts
540+ then blanklines 2 <> contents <> blankline
541+ else contents <> blankline
536542 | setext ->
537543 contents <> attr' <> cr <> text (replicate (offset contents) '-') <>
538544 blankline
@@ -1036,13 +1042,18 @@ inlineToMarkdown opts (Emph lst) = do
10361042 plain <- asks envPlain
10371043 contents <- inlineListToMarkdown opts lst
10381044 return $ if plain
1039− then "_" <> contents <> "_"
1045+ then if isEnabled Ext_gutenberg opts
1046+ then "_" <> contents <> "_"
1047+ else contents
10401048 else "*" <> contents <> "*"
10411049inlineToMarkdown _ (Strong []) = return empty
10421050inlineToMarkdown opts (Strong lst) = do
10431051 plain <- asks envPlain
10441052 if plain
1045− then inlineListToMarkdown opts $ capitalize lst
1053+ then inlineListToMarkdown opts $
1054+ if isEnabled Ext_gutenberg opts
1055+ then capitalize lst
1056+ else lst
10461057 else do
10471058 contents <- inlineListToMarkdown opts lst
10481059 return $ "**" <> contents <> "**"
test/Tests/Writers/Plain.hs+3−1
@@ -13,7 +13,9 @@ import Text.Pandoc.Builder
1313infix 4 =:
1414(=:) :: (ToString a, ToPandoc a)
1515 => String -> (a, String) -> TestTree
16−(=:) = test (purely (writePlain def) . toPandoc)
16+(=:) = test (purely (writePlain def{ writerExtensions =
17+ enableExtension Ext_gutenberg plainExtensions }) .
18+ toPandoc)
1719
1820
1921tests :: [TestTree]
test/command/4529.md+1−1
@@ -1,5 +1,5 @@
11```
2−% pandoc -f latex -t plain
2+% pandoc -f latex -t plain+gutenberg
33\chapter{First chapter}\label{sec:chp1}
44The next chapter is Chapter~\ref{sec:chp2}.
55\section{First section}\label{sec:chp1sec1}
test/writer.plain+35−89
@@ -7,41 +7,31 @@ markdown test suite.
77
88------------------------------------------------------------------------------
99
10−
11−
12−HEADERS
13−
10+Headers
1411
1512Level 2 with an embedded link
1613
17−Level 3 with _emphasis_
14+Level 3 with emphasis
1815
1916Level 4
2017
2118Level 5
2219
20+Level 1
2321
24−
25−LEVEL 1
26−
27−
28−Level 2 with _emphasis_
22+Level 2 with emphasis
2923
3024Level 3
3125
3226with no blank line
3327
34−
3528Level 2
3629
3730with no blank line
3831
3932------------------------------------------------------------------------------
4033
41−
42−
43−PARAGRAPHS
44−
34+Paragraphs
4535
4636Here’s a regular paragraph.
4737
@@ -56,10 +46,7 @@ here.
5646
5747------------------------------------------------------------------------------
5848
59−
60−
61−BLOCK QUOTES
62−
49+Block Quotes
6350
6451E-mail style:
6552
@@ -88,10 +75,7 @@ And a following paragraph.
8875
8976------------------------------------------------------------------------------
9077
91−
92−
93−CODE BLOCKS
94−
78+Code Blocks
9579
9680Code:
9781
@@ -111,10 +95,7 @@ And:
11195
11296------------------------------------------------------------------------------
11397
114−
115−
116−LISTS
117−
98+Lists
11899
119100Unordered
120101
@@ -160,7 +141,6 @@ Minuses loose:
160141
161142- Minus 3
162143
163−
164144Ordered
165145
166146Tight:
@@ -201,7 +181,6 @@ Multiple paragraphs:
201181
2021823. Item 3.
203183
204−
205184Nested
206185
207186- Tab
@@ -229,7 +208,6 @@ Same thing but with paragraphs:
229208
2302093. Third
231210
232−
233211Tabs and spaces
234212
235213- this is a list item indented with tabs
@@ -240,7 +218,6 @@ Tabs and spaces
240218
241219 - this is an example list item indented with spaces
242220
243−
244221Fancy list markers
245222
246223(2) begins with 2
@@ -275,10 +252,7 @@ B. Williams
275252
276253------------------------------------------------------------------------------
277254
278−
279−
280−DEFINITION LISTS
281−
255+Definition Lists
282256
283257Tight using spaces:
284258
@@ -318,13 +292,13 @@ banana
318292
319293Multiple blocks with italics:
320294
321−_apple_
295+apple
322296
323297 red fruit
324298
325299 contains seeds, crisp, pleasant to taste
326300
327−_orange_
301+orange
328302
329303 orange fruit
330304
@@ -371,10 +345,7 @@ orange
371345 1. sublist
372346 2. sublist
373347
374−
375−
376−HTML BLOCKS
377−
348+HTML Blocks
378349
379350Simple block on one line:
380351
@@ -388,8 +359,8 @@ bar
388359
389360Interpreted markdown in a table:
390361
391−This is _emphasized_
392−And this is STRONG
362+This is emphasized
363+And this is strong
393364Here’s a simple block:
394365
395366foo
@@ -426,30 +397,27 @@ Hr’s:
426397
427398------------------------------------------------------------------------------
428399
400+Inline Markup
429401
402+This is emphasized, and so is this.
430403
431−INLINE MARKUP
432−
404+This is strong, and so is this.
433405
434−This is _emphasized_, and so _is this_.
406+An emphasized link.
435407
436−This is STRONG, and so IS THIS.
408+This is strong and em.
437409
438−An _emphasized link_.
410+So is this word.
439411
440−_THIS IS STRONG AND EM._
412+This is strong and em.
441413
442−So is _THIS_ word.
443−
444−_THIS IS STRONG AND EM._
445−
446−So is _THIS_ word.
414+So is this word.
447415
448416This is code: >, $, \, \$, <html>.
449417
450−~~This is _strikeout_.~~
418+~~This is strikeout.~~
451419
452−Superscripts: a^(bc)d a^(_hello_) a^(hello there).
420+Superscripts: a^(bc)d a^(hello) a^(hello there).
453421
454422Subscripts: H₂O, H₂₃O, H_(many of them)O.
455423
@@ -458,10 +426,7 @@ spaces: a^b c^d, a~b c~d.
458426
459427------------------------------------------------------------------------------
460428
461−
462−
463−SMART QUOTES, ELLIPSES, DASHES
464−
429+Smart quotes, ellipses, dashes
465430
466431“Hello,” said the spider. “‘Shelob’ is my name.”
467432
@@ -481,10 +446,7 @@ Ellipses…and…and….
481446
482447------------------------------------------------------------------------------
483448
484−
485−
486−LATEX
487−
449+LaTeX
488450
489451-
490452- 2 + 2 = 4
@@ -499,19 +461,16 @@ LATEX
499461These shouldn’t be math:
500462
501463- To get the famous equation, write $e = mc^2$.
502−- $22,000 is a _lot_ of money. So is $34,000. (It worked if “lot” is
464+- $22,000 is a lot of money. So is $34,000. (It worked if “lot” is
503465 emphasized.)
504466- Shoes ($20) and socks ($5).
505−- Escaped $: $73 _this should be emphasized_ 23$.
467+- Escaped $: $73 this should be emphasized 23$.
506468
507469Here’s a LaTeX table:
508470
509471------------------------------------------------------------------------------
510472
511−
512−
513−SPECIAL CHARACTERS
514−
473+Special Characters
515474
516475Here is some unicode:
517476
@@ -565,10 +524,7 @@ Minus: -
565524
566525------------------------------------------------------------------------------
567526
568−
569−
570−LINKS
571−
527+Links
572528
573529Explicit
574530
@@ -590,7 +546,6 @@ Email link
590546
591547Empty.
592548
593−
594549Reference
595550
596551Foo bar.
@@ -613,7 +568,6 @@ Foo bar.
613568
614569Foo biz.
615570
616−
617571With ampersands
618572
619573Here’s a link with an ampersand in the URL.
@@ -624,7 +578,6 @@ Here’s an inline link.
624578
625579Here’s an inline link in pointy braces.
626580
627−
628581Autolinks
629582
630583With an ampersand: http://example.com/?foo=1&bar=2
@@ -643,10 +596,7 @@ Auto-links should not occur here: <http://example.com/>
643596
644597------------------------------------------------------------------------------
645598
646−
647−
648−IMAGES
649−
599+Images
650600
651601From “Voyage dans la Lune” by Georges Melies (1902):
652602
@@ -656,14 +606,10 @@ Here is a movie [movie] icon.
656606
657607------------------------------------------------------------------------------
658608
609+Footnotes
659610
660−
661−FOOTNOTES
662−
663−
664−Here is a footnote reference,[1] and another.[2] This should _not_ be a
665−footnote reference, because it contains a space.[^my note] Here is an inline
666−note.[3]
611+Here is a footnote reference,[1] and another.[2] This should not be a footnote
612+reference, because it contains a space.[^my note] Here is an inline note.[3]
667613
668614 Notes can go in quotes.[4]
669615
@@ -684,7 +630,7 @@ with list items).
684630If you want, you can indent every line, but you can also be lazy and just
685631indent the first line of each block.
686632
687−[3] This is _easier_ to type. Inline notes may contain links and ] verbatim
633+[3] This is easier to type. Inline notes may contain links and ] verbatim
688634characters, as well as [bracketed text].
689635
690636[4] In quote.