From 741b1f7fb4f974a0fc2a9abe410007b27078e129 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 11 Nov 2019 09:05:35 -0800 Subject: [PATCH] Markdown reader: fix small super/subscript issue. Superscripts and subscripts cannot contain spaces, but newlines were previously allowed (unintentionally). This led to bad interactions in some cases with footnotes. E.g. ``` foo^[note] bar^[note] ``` With this change newlines are also not allowed inside super/subscripts. Closes #5878. --- MANUAL.txt | 13 +++++++------ src/Text/Pandoc/Readers/Markdown.hs | 8 ++++++-- test/command/5878.md | 7 +++++++ 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 test/command/5878.md diff --git a/MANUAL.txt b/MANUAL.txt index 207f5a5ae..3b7bb544c 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -4042,12 +4042,13 @@ text by `~` characters. Thus, for example, H~2~O is a liquid. 2^10^ is 1024. -If the superscripted or subscripted text contains spaces, these spaces -must be escaped with backslashes. (This is to prevent accidental -superscripting and subscripting through the ordinary use of `~` and `^`.) -Thus, if you want the letter P with 'a cat' in subscripts, use -`P~a\ cat~`, not `P~a cat~`. - +The text between `^...^` or `~...~` may not contain spaces or +newlines. If the superscripted or subscripted text contains +spaces, these spaces must be escaped with backslashes. (This is +to prevent accidental superscripting and subscripting through +the ordinary use of `~` and `^`, and also bad interactions with +footnotes.) Thus, if you want the letter P with 'a cat' in +subscripts, use `P~a\ cat~`, not `P~a cat~`. ### Verbatim ### diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 46220acc8..4807baada 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1700,13 +1700,17 @@ superscript :: PandocMonad m => MarkdownParser m (F Inlines) superscript = fmap B.superscript <$> try (do guardEnabled Ext_superscript char '^' - mconcat <$> many1Till (notFollowedBy spaceChar >> inline) (char '^')) + mconcat <$> many1Till (do notFollowedBy spaceChar + notFollowedBy newline + inline) (char '^')) subscript :: PandocMonad m => MarkdownParser m (F Inlines) subscript = fmap B.subscript <$> try (do guardEnabled Ext_subscript char '~' - mconcat <$> many1Till (notFollowedBy spaceChar >> inline) (char '~')) + mconcat <$> many1Till (do notFollowedBy spaceChar + notFollowedBy newline + inline) (char '~')) whitespace :: PandocMonad m => MarkdownParser m (F Inlines) whitespace = spaceChar >> return <$> (lb <|> regsp) "whitespace" diff --git a/test/command/5878.md b/test/command/5878.md new file mode 100644 index 000000000..9e0f6bde3 --- /dev/null +++ b/test/command/5878.md @@ -0,0 +1,7 @@ +``` +% pandoc -t native +Zozime^[], +Synésius^[] +^D +[Para [Str "Zozime",Note [Para []],Str ",",SoftBreak,Str "Syn\233sius",Note [Para []]]] +```