aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-21 14:39:21 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-21 14:43:14 +0100
commit430e2db9baa222dbf87ea664ec2d995640817b70 (patch)
tree7979df0c5aed2d7d4e102fdde137d91404d70623 /src
parentdaf8d1db18efcfbac31afd6a2323411b93ce1b62 (diff)
downloadpandoc-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.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs42
1 files changed, 29 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
+