git.iko.soy/typeable/pandoc
on master help sign in
Plain writer: use _(..) or ^(..) for super/subscript...
cf306f3John MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+31−24
@@ -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
921+ Just r -> text r
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
933+ Just r -> text r
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
1122
1128
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
1136
1143
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
1147−
test/writer.opml+1−1
@@ -46,7 +46,7 @@
46</outline>
46</outline>
47<outline text="HTML Blocks" _note="Simple block on one line:&#10;&#10;foo&#10;&#10;And nested without indentation:&#10;&#10;foo&#10;&#10;bar&#10;&#10;Interpreted markdown in a table:&#10;&#10;This is *emphasized*&#10;And this is **strong**&#10;Here’s a simple block:&#10;&#10;foo&#10;&#10;This should be a code block, though:&#10;&#10; &lt;div&gt;&#10; foo&#10; &lt;/div&gt;&#10;&#10;As should this:&#10;&#10; &lt;div&gt;foo&lt;/div&gt;&#10;&#10;Now, nested:&#10;&#10;foo&#10;&#10;This should just be an HTML comment:&#10;&#10;Multiline:&#10;&#10;Code block:&#10;&#10; &lt;!-- Comment --&gt;&#10;&#10;Just plain comment, with trailing spaces on the line:&#10;&#10;Code:&#10;&#10; &lt;hr /&gt;&#10;&#10;Hr’s:&#10;&#10;------------------------------------------------------------------------">
47<outline text="HTML Blocks" _note="Simple block on one line:&#10;&#10;foo&#10;&#10;And nested without indentation:&#10;&#10;foo&#10;&#10;bar&#10;&#10;Interpreted markdown in a table:&#10;&#10;This is *emphasized*&#10;And this is **strong**&#10;Here’s a simple block:&#10;&#10;foo&#10;&#10;This should be a code block, though:&#10;&#10; &lt;div&gt;&#10; foo&#10; &lt;/div&gt;&#10;&#10;As should this:&#10;&#10; &lt;div&gt;foo&lt;/div&gt;&#10;&#10;Now, nested:&#10;&#10;foo&#10;&#10;This should just be an HTML comment:&#10;&#10;Multiline:&#10;&#10;Code block:&#10;&#10; &lt;!-- Comment --&gt;&#10;&#10;Just plain comment, with trailing spaces on the line:&#10;&#10;Code:&#10;&#10; &lt;hr /&gt;&#10;&#10;Hr’s:&#10;&#10;------------------------------------------------------------------------">
48</outline>
48</outline>
49−<outline text="Inline Markup" _note="This is *emphasized*, and so *is this*.&#10;&#10;This is **strong**, and so **is this**.&#10;&#10;An *[emphasized link](/url)*.&#10;&#10;***This is strong and em.***&#10;&#10;So is ***this*** word.&#10;&#10;***This is strong and em.***&#10;&#10;So is ***this*** word.&#10;&#10;This is code: `&gt;`, `$`, `\`, `\$`, `&lt;html&gt;`.&#10;&#10;This is *strikeout*.&#10;&#10;Superscripts: abcd a*hello* ahello there.&#10;&#10;Subscripts: H₂O, H₂₃O, Hmany of themO.&#10;&#10;These should not be superscripts or subscripts, because of the unescaped&#10;spaces: a^b c^d, a~b c~d.&#10;&#10;------------------------------------------------------------------------">
49+<outline text="Inline Markup" _note="This is *emphasized*, and so *is this*.&#10;&#10;This is **strong**, and so **is this**.&#10;&#10;An *[emphasized link](/url)*.&#10;&#10;***This is strong and em.***&#10;&#10;So is ***this*** word.&#10;&#10;***This is strong and em.***&#10;&#10;So is ***this*** word.&#10;&#10;This is code: `&gt;`, `$`, `\`, `\$`, `&lt;html&gt;`.&#10;&#10;This is *strikeout*.&#10;&#10;Superscripts: a^(bc)d a^(*hello*) a^(hello there).&#10;&#10;Subscripts: H₂O, H₂₃O, H_(many of them)O.&#10;&#10;These should not be superscripts or subscripts, because of the unescaped&#10;spaces: a^b c^d, a~b c~d.&#10;&#10;------------------------------------------------------------------------">
50</outline>
50</outline>
51<outline text="Smart quotes, ellipses, dashes" _note="“Hello,” said the spider. “‘Shelob’ is my name.”&#10;&#10;‘A’, ‘B’, and ‘C’ are letters.&#10;&#10;‘Oak,’ ‘elm,’ and ‘beech’ are names of trees. So is ‘pine.’&#10;&#10;‘He said, “I want to go.”’ Were you alive in the 70’s?&#10;&#10;Here is some quoted ‘`code`’ and a “[quoted&#10;link](http://example.com/?foo=1&amp;bar=2)”.&#10;&#10;Some dashes: one—two — three—four — five.&#10;&#10;Dashes between numbers: 5–7, 255–66, 1987–1999.&#10;&#10;Ellipses…and…and….&#10;&#10;------------------------------------------------------------------------">
51<outline text="Smart quotes, ellipses, dashes" _note="“Hello,” said the spider. “‘Shelob’ is my name.”&#10;&#10;‘A’, ‘B’, and ‘C’ are letters.&#10;&#10;‘Oak,’ ‘elm,’ and ‘beech’ are names of trees. So is ‘pine.’&#10;&#10;‘He said, “I want to go.”’ Were you alive in the 70’s?&#10;&#10;Here is some quoted ‘`code`’ and a “[quoted&#10;link](http://example.com/?foo=1&amp;bar=2)”.&#10;&#10;Some dashes: one—two — three—four — five.&#10;&#10;Dashes between numbers: 5–7, 255–66, 1987–1999.&#10;&#10;Ellipses…and…and….&#10;&#10;------------------------------------------------------------------------">
52</outline>
52</outline>
test/writer.plain+2−2
@@ -448,9 +448,9 @@ This is code: >, $, \, \$, <html>.
448
448
449~~This is _strikeout_.~~
449~~This is _strikeout_.~~
450
450
451−Superscripts: abcd a_hello_ ahello there.
451+Superscripts: a^(bc)d a^(_hello_) a^(hello there).
452
452
453−Subscripts: H₂O, H₂₃O, Hmany of themO.
453+Subscripts: H₂O, H₂₃O, H_(many of them)O.
454
454
455These should not be superscripts or subscripts, because of the unescaped
455These should not be superscripts or subscripts, because of the unescaped
456spaces: a^b c^d, a~b c~d.
456spaces: a^b c^d, a~b c~d.