@@ -614,20 +614,22 @@ directive' = do
614 return mempty
614 return mempty
617−-- - Silently ignores illegal fields
618-- - Only supports :format: fields with a single format for :raw: roles,
617-- - Only supports :format: fields with a single format for :raw: roles,
619-- change Text.Pandoc.Definition.Format to fix
618-- change Text.Pandoc.Definition.Format to fix
620addNewRole :: String -> [(String, String)] -> RSTParser Blocks
619addNewRole :: String -> [(String, String)] -> RSTParser Blocks
621addNewRole roleString fields = do
620addNewRole roleString fields = do
622 (role, parentRole) <- parseFromString inheritedRole roleString
621 (role, parentRole) <- parseFromString inheritedRole roleString
623 customRoles <- stateRstCustomRoles <$> getState
622 customRoles <- stateRstCustomRoles <$> getState
623+ let getBaseRole (r, f, a) roles =
624+ case M.lookup r roles of
625+ Just (r', f', a') -> getBaseRole (r', f', a') roles
626+ Nothing -> (r, f, a)
624− let (baseRole, baseFmt, baseAttr) =
627+ (baseRole, baseFmt, baseAttr) =
625− maybe (parentRole, Nothing, nullAttr) id $
628+ getBaseRole (parentRole, Nothing, nullAttr) customRoles
626− M.lookup parentRole customRoles
627 fmt = if parentRole == "raw" then lookup "format" fields else baseFmt
629 fmt = if parentRole == "raw" then lookup "format" fields else baseFmt
628 annotate :: [String] -> [String]
630 annotate :: [String] -> [String]
629 annotate = maybe id (:) $
631 annotate = maybe id (:) $
630− if parentRole == "code"
632+ if baseRole == "code"
631 then lookup "language" fields
633 then lookup "language" fields
632 else Nothing
634 else Nothing
633 attr = let (ident, classes, keyValues) = baseAttr
635 attr = let (ident, classes, keyValues) = baseAttr
@@ -636,12 +638,12 @@ addNewRole roleString fields = do
637 -- warn about syntax we ignore
639 -- warn about syntax we ignore
638 flip mapM_ fields $ \(key, _) -> case key of
640 flip mapM_ fields $ \(key, _) -> case key of
639− "language" -> when (parentRole /= "code") $ addWarning Nothing $
641+ "language" -> when (baseRole /= "code") $ addWarning Nothing $
640 "ignoring :language: field because the parent of role :" ++
642 "ignoring :language: field because the parent of role :" ++
641− role ++ ": is :" ++ parentRole ++ ": not :code:"
643+ role ++ ": is :" ++ baseRole ++ ": not :code:"
642− "format" -> when (parentRole /= "raw") $ addWarning Nothing $
644+ "format" -> when (baseRole /= "raw") $ addWarning Nothing $
643 "ignoring :format: field because the parent of role :" ++
645 "ignoring :format: field because the parent of role :" ++
644− role ++ ": is :" ++ parentRole ++ ": not :raw:"
646+ role ++ ": is :" ++ baseRole ++ ": not :raw:"
645 _ -> addWarning Nothing $ "ignoring unknown field :" ++ key ++
647 _ -> addWarning Nothing $ "ignoring unknown field :" ++ key ++
646 ": in definition of role :" ++ role ++ ": in"
648 ": in definition of role :" ++ role ++ ": in"
647 when (parentRole == "raw" && countKeys "format" > 1) $
649 when (parentRole == "raw" && countKeys "format" > 1) $