git.iko.soy/typeable/pandoc
on master help sign in
Render numbers in YAML metadata without decimals when possible.

The change to aeson > 0.7 caused numbers to be rendered with decimals. This change causes them to be rendered without decimals wehn possible.

commitd16775e1c7ba248e693817a8d53ebcb9a8332ed5 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 24 Apr 2014, 11:09 (13 years ago) parente068871
2 files changed+7−1
pandoc.cabal+1 src/Text/Pandoc/Readers/Markdown.hs+6−1
pandoc.cabal+1
@@ -233,6 +233,7 @@ Library
233233 blaze-markup >= 0.5.1 && < 0.7,
234234 attoparsec >= 0.10 && < 0.12,
235235 yaml >= 0.8.8.2 && < 0.9,
236+ scientific >= 0.2 && < 0.3,
236237 vector >= 0.10 && < 0.11,
237238 hslua >= 0.3 && < 0.4,
238239 binary >= 0.5 && < 0.8
src/Text/Pandoc/Readers/Markdown.hs+6−1
@@ -33,6 +33,7 @@ module Text.Pandoc.Readers.Markdown ( readMarkdown,
3333
3434import Data.List ( transpose, sortBy, findIndex, intersperse, intercalate )
3535import qualified Data.Map as M
36+import Data.Scientific (coefficient, base10Exponent)
3637import Data.Ord ( comparing )
3738import Data.Char ( isAlphaNum, toLower )
3839import Data.Maybe
@@ -285,7 +286,11 @@ toMetaValue opts x =
285286
286287yamlToMeta :: ReaderOptions -> Yaml.Value -> MetaValue
287288yamlToMeta 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
289294yamlToMeta _ (Yaml.Bool b) = MetaBool b
290295yamlToMeta opts (Yaml.Array xs) = B.toMetaValue $ map (yamlToMeta opts)
291296 $ V.toList xs