From 430e2db9baa222dbf87ea664ec2d995640817b70 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 21 Mar 2017 14:39:21 +0100 Subject: 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. --- src/Text/Pandoc/Writers/Markdown.hs | 42 +++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'src') 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 "" <> contents <> "" - 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 "" <> contents <> "" - 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 + -- cgit v1.2.3