git.iko.soy/typeable/pandoc
on master help sign in
Use unicode super/subscripts for digits in plain output.
commit047cb32dfcf182368a9de5658857e16894253285 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 15 Oct 2015, 14:35 (11 years ago) parent3f9dd65
2 files changed+16−5
src/Text/Pandoc/Writers/Markdown.hs+14−3 tests/writer.plain+2−2
src/Text/Pandoc/Writers/Markdown.hs+14−3
@@ -40,7 +40,7 @@ import Text.Pandoc.Options
4040import Text.Pandoc.Parsing hiding (blankline, blanklines, char, space)
4141import Data.Maybe (fromMaybe)
4242import Data.List ( group, stripPrefix, find, intersperse, transpose, sortBy )
43−import Data.Char ( isSpace, isPunctuation )
43+import Data.Char ( isSpace, isPunctuation, ord, chr )
4444import Data.Ord ( comparing )
4545import Text.Pandoc.Pretty
4646import Control.Monad.State
@@ -775,14 +775,25 @@ inlineToMarkdown opts (Superscript lst) = do
775775 then "^" <> contents <> "^"
776776 else if isEnabled Ext_raw_html opts
777777 then "<sup>" <> contents <> "</sup>"
778− else contents
778+ else case (render Nothing contents) of
779+ ds | all (\d -> d >= '0' && d <= '9') ds
780+ -> text (map toSuperscript ds)
781+ _ -> contents
782+ where toSuperscript '1' = '\x00B9'
783+ toSuperscript '2' = '\x00B2'
784+ toSuperscript '3' = '\x00B3'
785+ toSuperscript c = chr (0x2070 + (ord c - 48))
779786inlineToMarkdown opts (Subscript lst) = do
780787 contents <- inlineListToMarkdown opts $ walk escapeSpaces lst
781788 return $ if isEnabled Ext_subscript opts
782789 then "~" <> contents <> "~"
783790 else if isEnabled Ext_raw_html opts
784791 then "<sub>" <> contents <> "</sub>"
785− else contents
792+ else case (render Nothing contents) of
793+ ds | all (\d -> d >= '0' && d <= '9') ds
794+ -> text (map toSubscript ds)
795+ _ -> contents
796+ where toSubscript c = chr (0x2080 + (ord c - 48))
786797inlineToMarkdown opts (SmallCaps lst) = do
787798 plain <- gets stPlain
788799 if not plain &&
tests/writer.plain+2−2
@@ -451,7 +451,7 @@ This is code: >, $, \, \$, <html>.
451451
452452Superscripts: abcd a_hello_ ahello there.
453453
454−Subscripts: H2O, H23O, Hmany of themO.
454+Subscripts: H₂O, H₂₃O, Hmany of themO.
455455
456456These should not be superscripts or subscripts, because of the unescaped
457457spaces: a^b c^d, a~b c~d.
@@ -494,7 +494,7 @@ LATEX
494494- p-Tree
495495- Here’s some display math:
496496 $$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$
497−- Here’s one that has a line break in it: α + ω × x2.
497+- Here’s one that has a line break in it: α + ω × x².
498498
499499These shouldn’t be math:
500500