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.
This commit is contained in:
parent
e0688711fd
commit
d16775e1c7
2 changed files with 7 additions and 1 deletions
|
@ -233,6 +233,7 @@ Library
|
||||||
blaze-markup >= 0.5.1 && < 0.7,
|
blaze-markup >= 0.5.1 && < 0.7,
|
||||||
attoparsec >= 0.10 && < 0.12,
|
attoparsec >= 0.10 && < 0.12,
|
||||||
yaml >= 0.8.8.2 && < 0.9,
|
yaml >= 0.8.8.2 && < 0.9,
|
||||||
|
scientific >= 0.2 && < 0.3,
|
||||||
vector >= 0.10 && < 0.11,
|
vector >= 0.10 && < 0.11,
|
||||||
hslua >= 0.3 && < 0.4,
|
hslua >= 0.3 && < 0.4,
|
||||||
binary >= 0.5 && < 0.8
|
binary >= 0.5 && < 0.8
|
||||||
|
|
|
@ -33,6 +33,7 @@ module Text.Pandoc.Readers.Markdown ( readMarkdown,
|
||||||
|
|
||||||
import Data.List ( transpose, sortBy, findIndex, intersperse, intercalate )
|
import Data.List ( transpose, sortBy, findIndex, intersperse, intercalate )
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
import Data.Scientific (coefficient, base10Exponent)
|
||||||
import Data.Ord ( comparing )
|
import Data.Ord ( comparing )
|
||||||
import Data.Char ( isAlphaNum, toLower )
|
import Data.Char ( isAlphaNum, toLower )
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
@ -285,7 +286,11 @@ toMetaValue opts x =
|
||||||
|
|
||||||
yamlToMeta :: ReaderOptions -> Yaml.Value -> MetaValue
|
yamlToMeta :: ReaderOptions -> Yaml.Value -> MetaValue
|
||||||
yamlToMeta opts (Yaml.String t) = toMetaValue opts t
|
yamlToMeta opts (Yaml.String t) = toMetaValue opts t
|
||||||
yamlToMeta _ (Yaml.Number n) = MetaString $ show n
|
yamlToMeta _ (Yaml.Number n)
|
||||||
|
-- avoid decimal points for numbers that don't need them:
|
||||||
|
| base10Exponent n >= 0 = MetaString $ show
|
||||||
|
$ coefficient n * (10 ^ base10Exponent n)
|
||||||
|
| otherwise = MetaString $ show n
|
||||||
yamlToMeta _ (Yaml.Bool b) = MetaBool b
|
yamlToMeta _ (Yaml.Bool b) = MetaBool b
|
||||||
yamlToMeta opts (Yaml.Array xs) = B.toMetaValue $ map (yamlToMeta opts)
|
yamlToMeta opts (Yaml.Array xs) = B.toMetaValue $ map (yamlToMeta opts)
|
||||||
$ V.toList xs
|
$ V.toList xs
|
||||||
|
|
Loading…
Add table
Reference in a new issue