@@ -625,25 +625,27 @@ addNewRole :: String -> [(String, String)] -> RSTParser Blocks
625addNewRole roleString fields = do
625addNewRole roleString fields = do
626 (role, parentRole) <- parseFromString inheritedRole roleString
626 (role, parentRole) <- parseFromString inheritedRole roleString
627 customRoles <- stateRstCustomRoles <$> getState
627 customRoles <- stateRstCustomRoles <$> getState
628+ let (baseRole, baseFmt, baseAttr) =
629+ maybe (parentRole, Nothing, nullAttr) id $
628− baseRole <- case M.lookup parentRole customRoles of
630+ M.lookup parentRole customRoles
629− Just (base, _, _) -> return base
631+
630− Nothing -> return parentRole
632− let fmt = if baseRole == "raw" then lookup "format" fields else Nothing
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]
633− annotate = maybe (addClass role) (addLanguage role) $
635+ annotate = maybe id (:) $
634 if baseRole == "code"
636 if baseRole == "code"
635 then lookup "language" fields
637 then lookup "language" fields
636 else Nothing
638 else Nothing
639+ attr = let (ident, classes, keyValues) = baseAttr
640+ in (ident, nub . (role :) . annotate $ classes, keyValues)
638 updateState $ \s -> s {
642 updateState $ \s -> s {
639 stateRstCustomRoles =
643 stateRstCustomRoles =
640− M.insert role (baseRole, fmt, (,) parentRole . annotate) customRoles
644+ M.insert role (baseRole, fmt, attr) customRoles
643 return $ B.singleton Null
647 return $ B.singleton Null
645− addLanguage role lang (ident, classes, keyValues) =
646− (ident, nub ("sourceCode" : lang : role : classes), keyValues)
647 inheritedRole =
649 inheritedRole =
648 (,) <$> roleName <*> ((char '(' *> roleName <* char ')') <|> pure "span")
650 (,) <$> roleName <*> ((char '(' *> roleName <* char ')') <|> pure "span")
@@ -1014,12 +1016,10 @@ renderRole contents fmt role attr = case role of
1014 "span" -> return $ B.spanWith attr $ B.str contents
1016 "span" -> return $ B.spanWith attr $ B.str contents
1015 "raw" -> return $ B.rawInline (fromMaybe "" fmt) contents
1017 "raw" -> return $ B.rawInline (fromMaybe "" fmt) contents
1016 custom -> do
1018 custom -> do
1017− customRole <- stateRstCustomRoles <$> getState
1019+ customRoles <- stateRstCustomRoles <$> getState
1018− case M.lookup custom customRole of
1020+ case M.lookup custom customRoles of
1019− Just (_, newFmt, inherit) -> let
1021+ Just (newRole, newFmt, newAttr) ->
1020− fmtStr = fmt `mplus` newFmt
1021− (newRole, newAttr) = inherit attr
1022− in renderRole contents fmtStr newRole newAttr
1022+ renderRole contents newFmt newRole newAttr
1023 Nothing -> do
1023 Nothing -> do
1024 pos <- getPosition
1024 pos <- getPosition
1025 addWarning (Just pos) $ "ignoring unknown role :" ++ custom ++ ": in "
1025 addWarning (Just pos) $ "ignoring unknown role :" ++ custom ++ ": in "