diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-09-22 10:57:48 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-09-22 11:33:09 -0700 |
commit | d247e9f72e9c9a86cb0053cffc607b5f84f8b3a4 (patch) | |
tree | 21c5e7806e205c2b2489d24b88cae09ebde560ac /src/Text | |
parent | a9d106d1d1a91e4ce3dce955c1c5423903edae8c (diff) | |
download | pandoc-d247e9f72e9c9a86cb0053cffc607b5f84f8b3a4.tar.gz |
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.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Extensions.hs | 1 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 21 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs index 6cb87eef6..121b60e7b 100644 --- a/src/Text/Pandoc/Extensions.hs +++ b/src/Text/Pandoc/Extensions.hs @@ -155,6 +155,7 @@ data Extension = | Ext_tex_math_double_backslash -- ^ TeX math btw \\(..\\) \\[..\\] | Ext_tex_math_single_backslash -- ^ TeX math btw \(..\) \[..\] | Ext_yaml_metadata_block -- ^ YAML metadata block + | Ext_gutenberg -- ^ Use Project Gutenberg conventions for plain deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic) -- | Extensions to be used with pandoc-flavored markdown. diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index e298fafe9..fc25cde44 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -523,16 +523,22 @@ blockToMarkdown' opts (Header level attr inlines) = do contents <- inlineListToMarkdown opts $ -- ensure no newlines; see #3736 walk lineBreakToSpace $ - if level == 1 && plain + if level == 1 && plain && isEnabled Ext_gutenberg opts then capitalize inlines else inlines let setext = writerSetextHeaders opts hdr = nowrap $ case level of - 1 | plain -> blanklines 3 <> contents <> blanklines 2 + 1 | plain -> + if isEnabled Ext_gutenberg opts + then blanklines 3 <> contents <> blanklines 2 + else contents <> blankline | setext -> contents <> attr' <> cr <> text (replicate (offset contents) '=') <> blankline - 2 | plain -> blanklines 2 <> contents <> blankline + 2 | plain -> + if isEnabled Ext_gutenberg opts + then blanklines 2 <> contents <> blankline + else contents <> blankline | setext -> contents <> attr' <> cr <> text (replicate (offset contents) '-') <> blankline @@ -1036,13 +1042,18 @@ inlineToMarkdown opts (Emph lst) = do plain <- asks envPlain contents <- inlineListToMarkdown opts lst return $ if plain - then "_" <> contents <> "_" + then if isEnabled Ext_gutenberg opts + then "_" <> contents <> "_" + else contents else "*" <> contents <> "*" inlineToMarkdown _ (Strong []) = return empty inlineToMarkdown opts (Strong lst) = do plain <- asks envPlain if plain - then inlineListToMarkdown opts $ capitalize lst + then inlineListToMarkdown opts $ + if isEnabled Ext_gutenberg opts + then capitalize lst + else lst else do contents <- inlineListToMarkdown opts lst return $ "**" <> contents <> "**" |