@@ -37,18 +37,14 @@ import Prelude
3737import Control.Monad
3838import Control.Monad.Except (throwError)
3939import Data.Char (isAlphaNum, isPunctuation, isSpace, toLower)
40−import qualified Data.HashMap.Strict as H
4140import Data.List (intercalate, sortBy, transpose, elemIndex)
4241import qualified Data.Map as M
4342import Data.Maybe
4443import Data.Ord (comparing)
45−import Data.Scientific (base10Exponent, coefficient)
4644import qualified Data.Set as Set
4745import Data.Text (Text)
4846import qualified Data.Text as T
49−import qualified Data.Vector as V
50−import Data.Yaml (ParseException (..), YamlException (..), YamlMark (..))
51−import qualified Data.Yaml as Yaml
47+import qualified Data.YAML as YAML
5248import System.FilePath (addExtension, takeExtension)
5349import Text.HTML.TagSoup
5450import Text.Pandoc.Builder (Blocks, Inlines)
@@ -246,47 +242,38 @@ yamlMetaBlock = try $ do
246242 -- by including --- and ..., we allow yaml blocks with just comments:
247243 let rawYaml = unlines ("---" : (rawYamlLines ++ ["..."]))
248244 optional blanklines
249− case Yaml.decodeEither' $ UTF8.fromString rawYaml of
250− Right (Yaml.Object hashmap) -> do
251− let alist = H.toList hashmap
252− mapM_ (\(k, v) ->
253− if ignorable k
254− then return ()
255− else do
256− v' <- yamlToMeta v
257− let k' = T.unpack k
258− updateState $ \st -> st{ stateMeta' =
259− do m <- stateMeta' st
260− -- if there's already a value, leave it unchanged
261− case lookupMeta k' m of
262− Just _ -> return m
263− Nothing -> do
264− v'' <- v'
265− return $ B.setMeta (T.unpack k) v'' m}
245+ case YAML.decodeStrict (UTF8.fromString rawYaml) of
246+ Right (YAML.Mapping _ hashmap : _) -> do
247+ let alist = M.toList hashmap
248+ mapM_ (\(k', v) ->
249+ case YAML.parseEither (YAML.parseYAML k') of
250+ Left e -> fail e
251+ Right k -> do
252+ if ignorable k
253+ then return ()
254+ else do
255+ v' <- yamlToMeta v
256+ let k' = T.unpack k
257+ updateState $ \st -> st{ stateMeta' =
258+ do m <- stateMeta' st
259+ -- if there's already a value, leave it unchanged
260+ case lookupMeta k' m of
261+ Just _ -> return m
262+ Nothing -> do
263+ v'' <- v'
264+ return $ B.setMeta (T.unpack k) v'' m}
266265 ) alist
267− Right Yaml.Null -> return ()
266+ Right [] -> return ()
267+ Right (YAML.Scalar YAML.SNull:_) -> return ()
268268 Right _ -> do
269− logMessage $
270− CouldNotParseYamlMetadata "not an object"
271− pos
272− return ()
269+ logMessage $
270+ CouldNotParseYamlMetadata "not an object"
271+ pos
272+ return ()
273273 Left err' -> do
274− case err' of
275− InvalidYaml (Just YamlParseException{
276− yamlProblem = problem
277− , yamlContext = _ctxt
278− , yamlProblemMark = Yaml.YamlMark {
279− yamlLine = yline
280− , yamlColumn = ycol
281− }}) ->
282− logMessage $ CouldNotParseYamlMetadata
283− problem (setSourceLine
284− (setSourceColumn pos
285− (sourceColumn pos + ycol))
286− (sourceLine pos + 1 + yline))
287− _ -> logMessage $ CouldNotParseYamlMetadata
288− (show err') pos
289− return ()
274+ logMessage $ CouldNotParseYamlMetadata
275+ err' pos
276+ return ()
290277 return mempty
291278
292279-- ignore fields ending with _
@@ -313,22 +300,25 @@ toMetaValue x =
313300 -- `|` or `>` will.
314301
315302yamlToMeta :: PandocMonad m
316− => Yaml.Value -> MarkdownParser m (F MetaValue)
317−yamlToMeta (Yaml.String t) = toMetaValue t
318−yamlToMeta (Yaml.Number n)
319− -- avoid decimal points for numbers that don't need them:
320− | base10Exponent n >= 0 = return $ return $ MetaString $ show
321− $ coefficient n * (10 ^ base10Exponent n)
322− | otherwise = return $ return $ MetaString $ show n
323−yamlToMeta (Yaml.Bool b) = return $ return $ MetaBool b
324−yamlToMeta (Yaml.Array xs) = do
325− xs' <- mapM yamlToMeta (V.toList xs)
303+ => YAML.Node -> MarkdownParser m (F MetaValue)
304+yamlToMeta (YAML.Scalar x) =
305+ case x of
306+ YAML.SStr t -> toMetaValue t
307+ YAML.SBool b -> return $ return $ MetaBool b
308+ YAML.SFloat d -> return $ return $ MetaString (show d)
309+ YAML.SInt i -> return $ return $ MetaString (show i)
310+ _ -> return $ return $ MetaString ""
311+yamlToMeta (YAML.Sequence _ xs) = do
312+ xs' <- mapM yamlToMeta xs
326313 return $ do
327314 xs'' <- sequence xs'
328315 return $ B.toMetaValue xs''
329−yamlToMeta (Yaml.Object o) = do
330− let alist = H.toList o
331− foldM (\m (k,v) ->
316+yamlToMeta (YAML.Mapping _ o) = do
317+ let alist = M.toList o
318+ foldM (\m (k',v) ->
319+ case YAML.parseEither (YAML.parseYAML k') of
320+ Left e -> fail e
321+ Right k -> do
332322 if ignorable k
333323 then return m
334324 else do