@@ -37,7 +37,7 @@ import Text.Pandoc.Builder (setMeta, fromList)
37import Text.Pandoc.Shared
37import Text.Pandoc.Shared
38import Text.Pandoc.Parsing
38import Text.Pandoc.Parsing
39import Text.Pandoc.Options
39import Text.Pandoc.Options
40−import Control.Monad ( when, liftM, guard, mzero, mplus )
40+import Control.Monad ( when, liftM, guard, mzero )
41import Data.List ( findIndex, intersperse, intercalate,
41import Data.List ( findIndex, intersperse, intercalate,
42 transpose, sort, deleteFirstsBy, isSuffixOf , nub, union)
42 transpose, sort, deleteFirstsBy, isSuffixOf , nub, union)
43import Data.Maybe (fromMaybe)
43import Data.Maybe (fromMaybe)
@@ -628,17 +628,35 @@ addNewRole roleString fields = do
628 let (baseRole, baseFmt, baseAttr) =
628 let (baseRole, baseFmt, baseAttr) =
629 maybe (parentRole, Nothing, nullAttr) id $
629 maybe (parentRole, Nothing, nullAttr) id $
630 M.lookup parentRole customRoles
630 M.lookup parentRole customRoles
632− let fmt = if parentRole == "raw" then lookup "format" fields else baseFmt
631+ fmt = if parentRole == "raw" then lookup "format" fields else baseFmt
633− -- nub in case role name & language class are the same
634 annotate :: [String] -> [String]
632 annotate :: [String] -> [String]
635 annotate = maybe id (:) $
633 annotate = maybe id (:) $
636− if baseRole == "code"
634+ if parentRole == "code"
637 then lookup "language" fields
635 then lookup "language" fields
638 else Nothing
636 else Nothing
639 attr = let (ident, classes, keyValues) = baseAttr
637 attr = let (ident, classes, keyValues) = baseAttr
638+ -- nub in case role name & language class are the same
640 in (ident, nub . (role :) . annotate $ classes, keyValues)
639 in (ident, nub . (role :) . annotate $ classes, keyValues)
641+ -- warn about syntax we ignore
642+ flip mapM_ fields $ \(key, _) -> case key of
643+ "language" -> when (parentRole /= "code") $ addWarning Nothing $
644+ "ignoring :language: field because the parent of role :" ++
645+ role ++ ": is :" ++ parentRole ++ ": not :code:"
646+ "format" -> when (parentRole /= "raw") $ addWarning Nothing $
647+ "ignoring :format: field because the parent of role :" ++
648+ role ++ ": is :" ++ parentRole ++ ": not :raw:"
649+ _ -> addWarning Nothing $ "ignoring unknown field :" ++ key ++
650+ ": in definition of role :" ++ role ++ ": in"
651+ when (parentRole == "raw" && countKeys "format" > 1) $
652+ addWarning Nothing $
653+ "ignoring :format: fields after the first in the definition of role :"
655+ when (parentRole == "code" && countKeys "language" > 1) $
656+ addWarning Nothing $
657+ "ignoring :language: fields after the first in the definition of role :"
642 updateState $ \s -> s {
660 updateState $ \s -> s {
643 stateRstCustomRoles =
661 stateRstCustomRoles =
644 M.insert role (baseRole, fmt, attr) customRoles
662 M.insert role (baseRole, fmt, attr) customRoles
@@ -646,9 +664,11 @@ addNewRole roleString fields = do
647 return $ B.singleton Null
665 return $ B.singleton Null
667+ countKeys k = length . filter (== k) . map fst $ fields
649 inheritedRole =
668 inheritedRole =
650 (,) <$> roleName <*> ((char '(' *> roleName <* char ')') <|> pure "span")
669 (,) <$> roleName <*> ((char '(' *> roleName <* char ')') <|> pure "span")
652-- Can contain character codes as decimal numbers or
672-- Can contain character codes as decimal numbers or
653-- hexadecimal numbers, prefixed by 0x, x, \x, U+, u, or \u
673-- hexadecimal numbers, prefixed by 0x, x, \x, U+, u, or \u
654-- or as XML-style hexadecimal character entities, e.g. ᨫ
674-- or as XML-style hexadecimal character entities, e.g. ᨫ
@@ -1022,7 +1042,7 @@ renderRole contents fmt role attr = case role of
1022 renderRole contents newFmt newRole newAttr
1042 renderRole contents newFmt newRole newAttr
1023 Nothing -> do
1043 Nothing -> do
1024 pos <- getPosition
1044 pos <- getPosition
1025− addWarning (Just pos) $ "ignoring unknown role :" ++ custom ++ ": in "
1045+ addWarning (Just pos) $ "ignoring unknown role :" ++ custom ++ ": in"
1026 return $ B.str contents -- Undefined role
1046 return $ B.str contents -- Undefined role
1028 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
1048 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour