@@ -614,20 +614,22 @@ directive' = do
614614 return mempty
615615
616616-- TODO:
617−-- - Silently ignores illegal fields
618617-- - Only supports :format: fields with a single format for :raw: roles,
619618-- change Text.Pandoc.Definition.Format to fix
620619addNewRole :: String -> [(String, String)] -> RSTParser Blocks
621620addNewRole roleString fields = do
622621 (role, parentRole) <- parseFromString inheritedRole roleString
623622 customRoles <- stateRstCustomRoles <$> getState
624− let (baseRole, baseFmt, baseAttr) =
625− maybe (parentRole, Nothing, nullAttr) id $
626− M.lookup parentRole customRoles
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)
627+ (baseRole, baseFmt, baseAttr) =
628+ getBaseRole (parentRole, Nothing, nullAttr) customRoles
627629 fmt = if parentRole == "raw" then lookup "format" fields else baseFmt
628630 annotate :: [String] -> [String]
629631 annotate = maybe id (:) $
630− if parentRole == "code"
632+ if baseRole == "code"
631633 then lookup "language" fields
632634 else Nothing
633635 attr = let (ident, classes, keyValues) = baseAttr
@@ -636,12 +638,12 @@ addNewRole roleString fields = do
636638
637639 -- warn about syntax we ignore
638640 flip mapM_ fields $ \(key, _) -> case key of
639− "language" -> when (parentRole /= "code") $ addWarning Nothing $
641+ "language" -> when (baseRole /= "code") $ addWarning Nothing $
640642 "ignoring :language: field because the parent of role :" ++
641− role ++ ": is :" ++ parentRole ++ ": not :code:"
642− "format" -> when (parentRole /= "raw") $ addWarning Nothing $
643+ role ++ ": is :" ++ baseRole ++ ": not :code:"
644+ "format" -> when (baseRole /= "raw") $ addWarning Nothing $
643645 "ignoring :format: field because the parent of role :" ++
644− role ++ ": is :" ++ parentRole ++ ": not :raw:"
646+ role ++ ": is :" ++ baseRole ++ ": not :raw:"
645647 _ -> addWarning Nothing $ "ignoring unknown field :" ++ key ++
646648 ": in definition of role :" ++ role ++ ": in"
647649 when (parentRole == "raw" && countKeys "format" > 1) $