@@ -625,25 +625,27 @@ addNewRole :: String -> [(String, String)] -> RSTParser Blocks
625625addNewRole roleString fields = do
626626 (role, parentRole) <- parseFromString inheritedRole roleString
627627 customRoles <- stateRstCustomRoles <$> getState
628− baseRole <- case M.lookup parentRole customRoles of
629− Just (base, _, _) -> return base
630− Nothing -> return parentRole
631−
632− let fmt = if baseRole == "raw" then lookup "format" fields else Nothing
633− annotate = maybe (addClass role) (addLanguage role) $
628+ let (baseRole, baseFmt, baseAttr) =
629+ maybe (parentRole, Nothing, nullAttr) id $
630+ M.lookup parentRole customRoles
631+
632+ let 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]
635+ annotate = maybe id (:) $
634636 if baseRole == "code"
635637 then lookup "language" fields
636638 else Nothing
639+ attr = let (ident, classes, keyValues) = baseAttr
640+ in (ident, nub . (role :) . annotate $ classes, keyValues)
637641
638642 updateState $ \s -> s {
639643 stateRstCustomRoles =
640− M.insert role (baseRole, fmt, (,) parentRole . annotate) customRoles
644+ M.insert role (baseRole, fmt, attr) customRoles
641645 }
642646
643647 return $ B.singleton Null
644648 where
645− addLanguage role lang (ident, classes, keyValues) =
646− (ident, nub ("sourceCode" : lang : role : classes), keyValues)
647649 inheritedRole =
648650 (,) <$> roleName <*> ((char '(' *> roleName <* char ')') <|> pure "span")
649651
@@ -1014,12 +1016,10 @@ renderRole contents fmt role attr = case role of
10141016 "span" -> return $ B.spanWith attr $ B.str contents
10151017 "raw" -> return $ B.rawInline (fromMaybe "" fmt) contents
10161018 custom -> do
1017− customRole <- stateRstCustomRoles <$> getState
1018− case M.lookup custom customRole of
1019− Just (_, newFmt, inherit) -> let
1020− fmtStr = fmt `mplus` newFmt
1021− (newRole, newAttr) = inherit attr
1022− in renderRole contents fmtStr newRole newAttr
1019+ customRoles <- stateRstCustomRoles <$> getState
1020+ case M.lookup custom customRoles of
1021+ Just (newRole, newFmt, newAttr) ->
1022+ renderRole contents newFmt newRole newAttr
10231023 Nothing -> do
10241024 pos <- getPosition
10251025 addWarning (Just pos) $ "ignoring unknown role :" ++ custom ++ ": in "