@@ -915,8 +915,11 @@ inlineToMarkdown opts (Superscript lst) =
915 then "^" <> contents <> "^"
915 then "^" <> contents <> "^"
916 else if isEnabled Ext_raw_html opts
916 else if isEnabled Ext_raw_html opts
917 then "<sup>" <> contents <> "</sup>"
917 then "<sup>" <> contents <> "</sup>"
918− else text $ map toSuperscript
918+ else
919− $ render Nothing contents
919+ let rendered = render Nothing contents
920+ in case mapM toSuperscript rendered of
922+ Nothing -> text $ "^(" ++ rendered ++ ")"
920inlineToMarkdown opts (Subscript lst) =
923inlineToMarkdown opts (Subscript lst) =
921 local (\env -> env {envEscapeSpaces = True}) $ do
924 local (\env -> env {envEscapeSpaces = True}) $ do
922 contents <- inlineListToMarkdown opts lst
925 contents <- inlineListToMarkdown opts lst
@@ -924,8 +927,11 @@ inlineToMarkdown opts (Subscript lst) =
924 then "~" <> contents <> "~"
927 then "~" <> contents <> "~"
925 else if isEnabled Ext_raw_html opts
928 else if isEnabled Ext_raw_html opts
926 then "<sub>" <> contents <> "</sub>"
929 then "<sub>" <> contents <> "</sub>"
927− else text $ map toSubscript
930+ else
928− $ render Nothing contents
931+ let rendered = render Nothing contents
932+ in case mapM toSubscript rendered of
934+ Nothing -> text $ "_(" ++ rendered ++ ")"
929inlineToMarkdown opts (SmallCaps lst) = do
935inlineToMarkdown opts (SmallCaps lst) = do
930 plain <- asks envPlain
936 plain <- asks envPlain
931 if not plain &&
937 if not plain &&
@@ -1120,28 +1126,29 @@ makeMathPlainer = walk go
1120 go (Emph xs) = Span nullAttr xs
1126 go (Emph xs) = Span nullAttr xs
1121 go x = x
1127 go x = x
1123−toSuperscript :: Char -> Char
1129+toSuperscript :: Char -> Maybe Char
1124−toSuperscript '1' = '\x00B9'
1130+toSuperscript '1' = Just '\x00B9'
1125−toSuperscript '2' = '\x00B2'
1131+toSuperscript '2' = Just '\x00B2'
1126−toSuperscript '3' = '\x00B3'
1132+toSuperscript '3' = Just '\x00B3'
1127−toSuperscript '+' = '\x207A'
1133+toSuperscript '+' = Just '\x207A'
1128−toSuperscript '-' = '\x207B'
1134+toSuperscript '-' = Just '\x207B'
1129−toSuperscript '=' = '\x207C'
1135+toSuperscript '=' = Just '\x207C'
1130−toSuperscript '(' = '\x207D'
1136+toSuperscript '(' = Just '\x207D'
1131−toSuperscript ')' = '\x207E'
1137+toSuperscript ')' = Just '\x207E'
1132toSuperscript c
1138toSuperscript c
1133 | c >= '0' && c <= '9' =
1139 | c >= '0' && c <= '9' =
1134− chr (0x2070 + (ord c - 48))
1140+ Just $ chr (0x2070 + (ord c - 48))
1141+ | isSpace c = Just c
1135− | otherwise = c
1142+ | otherwise = Nothing
1137−toSubscript :: Char -> Char
1144+toSubscript :: Char -> Maybe Char
1138−toSubscript '+' = '\x208A'
1145+toSubscript '+' = Just '\x208A'
1139−toSubscript '-' = '\x208B'
1146+toSubscript '-' = Just '\x208B'
1140−toSubscript '=' = '\x208C'
1147+toSubscript '=' = Just '\x208C'
1141−toSubscript '(' = '\x208D'
1148+toSubscript '(' = Just '\x208D'
1142−toSubscript ')' = '\x208E'
1149+toSubscript ')' = Just '\x208E'
1143toSubscript c
1150toSubscript c
1144 | c >= '0' && c <= '9' =
1151 | c >= '0' && c <= '9' =
1145− chr (0x2080 + (ord c - 48))
1152+ Just $ chr (0x2080 + (ord c - 48))
1153+ | isSpace c = Just c
1146− | otherwise = c
1154+ | otherwise = Nothing