git.iko.soy/typeable/pandoc
on master help sign in
Render numbers in YAML metadata without decimals when possible.
d16775eJohn MacFarlane
pandoc.cabal+1
@@ -233,6 +233,7 @@ Library
233 blaze-markup >= 0.5.1 && < 0.7,
233 blaze-markup >= 0.5.1 && < 0.7,
234 attoparsec >= 0.10 && < 0.12,
234 attoparsec >= 0.10 && < 0.12,
235 yaml >= 0.8.8.2 && < 0.9,
235 yaml >= 0.8.8.2 && < 0.9,
236+ scientific >= 0.2 && < 0.3,
236 vector >= 0.10 && < 0.11,
237 vector >= 0.10 && < 0.11,
237 hslua >= 0.3 && < 0.4,
238 hslua >= 0.3 && < 0.4,
238 binary >= 0.5 && < 0.8
239 binary >= 0.5 && < 0.8
src/Text/Pandoc/Readers/Markdown.hs+6−1
@@ -33,6 +33,7 @@ module Text.Pandoc.Readers.Markdown ( readMarkdown,
33
33
34import Data.List ( transpose, sortBy, findIndex, intersperse, intercalate )
34import Data.List ( transpose, sortBy, findIndex, intersperse, intercalate )
35import qualified Data.Map as M
35import qualified Data.Map as M
36+import Data.Scientific (coefficient, base10Exponent)
36import Data.Ord ( comparing )
37import Data.Ord ( comparing )
37import Data.Char ( isAlphaNum, toLower )
38import Data.Char ( isAlphaNum, toLower )
38import Data.Maybe
39import Data.Maybe
@@ -285,7 +286,11 @@ toMetaValue opts x =
285
286
286yamlToMeta :: ReaderOptions -> Yaml.Value -> MetaValue
287yamlToMeta :: ReaderOptions -> Yaml.Value -> MetaValue
287yamlToMeta opts (Yaml.String t) = toMetaValue opts t
288yamlToMeta opts (Yaml.String t) = toMetaValue opts t
288−yamlToMeta _ (Yaml.Number n) = MetaString $ show n
289+yamlToMeta _ (Yaml.Number n)
290+ -- avoid decimal points for numbers that don't need them:
291+ | base10Exponent n >= 0 = MetaString $ show
292+ $ coefficient n * (10 ^ base10Exponent n)
293+ | otherwise = MetaString $ show n
289yamlToMeta _ (Yaml.Bool b) = MetaBool b
294yamlToMeta _ (Yaml.Bool b) = MetaBool b
290yamlToMeta opts (Yaml.Array xs) = B.toMetaValue $ map (yamlToMeta opts)
295yamlToMeta opts (Yaml.Array xs) = B.toMetaValue $ map (yamlToMeta opts)
291 $ V.toList xs
296 $ V.toList xs