Plain writer: use _(..) or ^(..) for super/subscript...
...unless unicode super/subscripted characters are available.
This commit is contained in:
parent
430e2db9ba
commit
cf306f34e5
3 changed files with 34 additions and 27 deletions
|
@ -915,8 +915,11 @@ inlineToMarkdown opts (Superscript lst) =
|
|||
then "^" <> contents <> "^"
|
||||
else if isEnabled Ext_raw_html opts
|
||||
then "<sup>" <> contents <> "</sup>"
|
||||
else text $ map toSuperscript
|
||||
$ render Nothing contents
|
||||
else
|
||||
let rendered = render Nothing contents
|
||||
in case mapM toSuperscript rendered of
|
||||
Just r -> text r
|
||||
Nothing -> text $ "^(" ++ rendered ++ ")"
|
||||
inlineToMarkdown opts (Subscript lst) =
|
||||
local (\env -> env {envEscapeSpaces = True}) $ do
|
||||
contents <- inlineListToMarkdown opts lst
|
||||
|
@ -924,8 +927,11 @@ inlineToMarkdown opts (Subscript lst) =
|
|||
then "~" <> contents <> "~"
|
||||
else if isEnabled Ext_raw_html opts
|
||||
then "<sub>" <> contents <> "</sub>"
|
||||
else text $ map toSubscript
|
||||
$ render Nothing contents
|
||||
else
|
||||
let rendered = render Nothing contents
|
||||
in case mapM toSubscript rendered of
|
||||
Just r -> text r
|
||||
Nothing -> text $ "_(" ++ rendered ++ ")"
|
||||
inlineToMarkdown opts (SmallCaps lst) = do
|
||||
plain <- asks envPlain
|
||||
if not plain &&
|
||||
|
@ -1120,28 +1126,29 @@ 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 :: Char -> Maybe Char
|
||||
toSuperscript '1' = Just '\x00B9'
|
||||
toSuperscript '2' = Just '\x00B2'
|
||||
toSuperscript '3' = Just '\x00B3'
|
||||
toSuperscript '+' = Just '\x207A'
|
||||
toSuperscript '-' = Just '\x207B'
|
||||
toSuperscript '=' = Just '\x207C'
|
||||
toSuperscript '(' = Just '\x207D'
|
||||
toSuperscript ')' = Just '\x207E'
|
||||
toSuperscript c
|
||||
| c >= '0' && c <= '9' =
|
||||
chr (0x2070 + (ord c - 48))
|
||||
| otherwise = c
|
||||
Just $ chr (0x2070 + (ord c - 48))
|
||||
| isSpace c = Just c
|
||||
| otherwise = Nothing
|
||||
|
||||
toSubscript :: Char -> Char
|
||||
toSubscript '+' = '\x208A'
|
||||
toSubscript '-' = '\x208B'
|
||||
toSubscript '=' = '\x208C'
|
||||
toSubscript '(' = '\x208D'
|
||||
toSubscript ')' = '\x208E'
|
||||
toSubscript :: Char -> Maybe Char
|
||||
toSubscript '+' = Just '\x208A'
|
||||
toSubscript '-' = Just '\x208B'
|
||||
toSubscript '=' = Just '\x208C'
|
||||
toSubscript '(' = Just '\x208D'
|
||||
toSubscript ')' = Just '\x208E'
|
||||
toSubscript c
|
||||
| c >= '0' && c <= '9' =
|
||||
chr (0x2080 + (ord c - 48))
|
||||
| otherwise = c
|
||||
|
||||
Just $ chr (0x2080 + (ord c - 48))
|
||||
| isSpace c = Just c
|
||||
| otherwise = Nothing
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
</outline>
|
||||
<outline text="HTML Blocks" _note="Simple block on one line: foo And nested without indentation: foo bar Interpreted markdown in a table: This is *emphasized* And this is **strong** Here’s a simple block: foo This should be a code block, though: <div> foo </div> As should this: <div>foo</div> Now, nested: foo This should just be an HTML comment: Multiline: Code block: <!-- Comment --> Just plain comment, with trailing spaces on the line: Code: <hr /> Hr’s: ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
<outline text="Inline Markup" _note="This is *emphasized*, and so *is this*. This is **strong**, and so **is this**. An *[emphasized link](/url)*. ***This is strong and em.*** So is ***this*** word. ***This is strong and em.*** So is ***this*** word. This is code: `>`, `$`, `\`, `\$`, `<html>`. This is *strikeout*. Superscripts: abcd a*hello* ahello there. Subscripts: H₂O, H₂₃O, Hmany of themO. These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d. ------------------------------------------------------------------------">
|
||||
<outline text="Inline Markup" _note="This is *emphasized*, and so *is this*. This is **strong**, and so **is this**. An *[emphasized link](/url)*. ***This is strong and em.*** So is ***this*** word. ***This is strong and em.*** So is ***this*** word. This is code: `>`, `$`, `\`, `\$`, `<html>`. This is *strikeout*. Superscripts: a^(bc)d a^(*hello*) a^(hello there). Subscripts: H₂O, H₂₃O, H_(many of them)O. These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d. ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
<outline text="Smart quotes, ellipses, dashes" _note="“Hello,” said the spider. “‘Shelob’ is my name.” ‘A’, ‘B’, and ‘C’ are letters. ‘Oak,’ ‘elm,’ and ‘beech’ are names of trees. So is ‘pine.’ ‘He said, “I want to go.”’ Were you alive in the 70’s? Here is some quoted ‘`code`’ and a “[quoted link](http://example.com/?foo=1&bar=2)”. Some dashes: one—two — three—four — five. Dashes between numbers: 5–7, 255–66, 1987–1999. Ellipses…and…and…. ------------------------------------------------------------------------">
|
||||
</outline>
|
||||
|
|
|
@ -448,9 +448,9 @@ This is code: >, $, \, \$, <html>.
|
|||
|
||||
~~This is _strikeout_.~~
|
||||
|
||||
Superscripts: abcd a_hello_ ahello there.
|
||||
Superscripts: a^(bc)d a^(_hello_) a^(hello there).
|
||||
|
||||
Subscripts: H₂O, H₂₃O, Hmany of themO.
|
||||
Subscripts: H₂O, H₂₃O, H_(many of them)O.
|
||||
|
||||
These should not be superscripts or subscripts, because of the unescaped
|
||||
spaces: a^b c^d, a~b c~d.
|
||||
|
|
Loading…
Add table
Reference in a new issue