diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-03-21 14:39:21 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-03-21 14:43:14 +0100 |
commit | 430e2db9baa222dbf87ea664ec2d995640817b70 (patch) | |
tree | 7979df0c5aed2d7d4e102fdde137d91404d70623 | |
parent | daf8d1db18efcfbac31afd6a2323411b93ce1b62 (diff) | |
download | pandoc-430e2db9baa222dbf87ea664ec2d995640817b70.tar.gz |
Improve rendering of superscript in plain output.
We now handle a few non digit characters (+, -, =, parentheses)
for which there are superscripted unicode characters.
Closes #3518.
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 42 | ||||
-rw-r--r-- | test/command/3518.md | 6 |
2 files changed, 35 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 3a431fb02..c1a02e609 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -915,14 +915,8 @@ inlineToMarkdown opts (Superscript lst) = then "^" <> contents <> "^" else if isEnabled Ext_raw_html opts then "<sup>" <> contents <> "</sup>" - else case (render Nothing contents) of - ds | all (\d -> d >= '0' && d <= '9') ds - -> text (map toSuperscript ds) - _ -> contents - where toSuperscript '1' = '\x00B9' - toSuperscript '2' = '\x00B2' - toSuperscript '3' = '\x00B3' - toSuperscript c = chr (0x2070 + (ord c - 48)) + else text $ map toSuperscript + $ render Nothing contents inlineToMarkdown opts (Subscript lst) = local (\env -> env {envEscapeSpaces = True}) $ do contents <- inlineListToMarkdown opts lst @@ -930,11 +924,8 @@ inlineToMarkdown opts (Subscript lst) = then "~" <> contents <> "~" else if isEnabled Ext_raw_html opts then "<sub>" <> contents <> "</sub>" - else case (render Nothing contents) of - ds | all (\d -> d >= '0' && d <= '9') ds - -> text (map toSubscript ds) - _ -> contents - where toSubscript c = chr (0x2080 + (ord c - 48)) + else text $ map toSubscript + $ render Nothing contents inlineToMarkdown opts (SmallCaps lst) = do plain <- asks envPlain if not plain && @@ -1129,3 +1120,28 @@ makeMathPlainer = walk go go (Emph xs) = Span nullAttr xs go x = x +toSuperscript :: Char -> Char +toSuperscript '1' = '\x00B9' +toSuperscript '2' = '\x00B2' +toSuperscript '3' = '\x00B3' +toSuperscript '+' = '\x207A' +toSuperscript '-' = '\x207B' +toSuperscript '=' = '\x207C' +toSuperscript '(' = '\x207D' +toSuperscript ')' = '\x207E' +toSuperscript c + | c >= '0' && c <= '9' = + chr (0x2070 + (ord c - 48)) + | otherwise = c + +toSubscript :: Char -> Char +toSubscript '+' = '\x208A' +toSubscript '-' = '\x208B' +toSubscript '=' = '\x208C' +toSubscript '(' = '\x208D' +toSubscript ')' = '\x208E' +toSubscript c + | c >= '0' && c <= '9' = + chr (0x2080 + (ord c - 48)) + | otherwise = c + diff --git a/test/command/3518.md b/test/command/3518.md new file mode 100644 index 000000000..ec3322192 --- /dev/null +++ b/test/command/3518.md @@ -0,0 +1,6 @@ +``` +pandoc -f latex -t plain +$\alpha^2 \cdot \alpha^{2+3} \equiv \alpha^7$ +^D +α² ⋅ α² ⁺ ³ ≡ α⁷ +``` |