DocBook reader: Support language attribute on inline code.

This commit is contained in:
John MacFarlane 2012-05-10 10:24:07 -07:00
parent 79e83749bf
commit 15ef1a1a48

View file

@ -581,7 +581,7 @@ parseBlock (Text (CData CDataRaw _ _)) = return mempty -- DOCTYPE
parseBlock (Text (CData _ s _)) = if all isSpace s parseBlock (Text (CData _ s _)) = if all isSpace s
then return mempty then return mempty
else return $ plain $ trimInlines $ text s else return $ plain $ trimInlines $ text s
parseBlock (CRef _) = return mempty -- TODO need something better here parseBlock (CRef x) = return $ plain $ str $ map toUpper x
parseBlock (Elem e) = parseBlock (Elem e) =
case qName (elName e) of case qName (elName e) of
"para" -> para <$> getInlines e "para" -> para <$> getInlines e
@ -637,7 +637,7 @@ parseBlock (Elem e) =
Just x@(_:_) | all isDigit x -> read x Just x@(_:_) | all isDigit x -> read x
_ -> 1 _ -> 1
orderedListWith (start,listStyle,DefaultDelim) orderedListWith (start,listStyle,DefaultDelim)
<$> listitems -- TODO list attributes <$> listitems
"variablelist" -> definitionList <$> deflistitems "variablelist" -> definitionList <$> deflistitems
"mediaobject" -> para <$> (getImage e) "mediaobject" -> para <$> (getImage e)
"caption" -> return mempty "caption" -> return mempty
@ -786,24 +786,24 @@ parseInline (Elem e) =
return $ if qt == SingleQuote return $ if qt == SingleQuote
then singleQuoted contents then singleQuoted contents
else doubleQuoted contents else doubleQuoted contents
"code" -> return $ code $ strContent e -- TODO attrs "code" -> codeWithLang []
"filename" -> return $ codeWith ("",["filename"],[]) $ strContent e -- TODO attrs "filename" -> codeWithLang ["filename"]
"literal" -> return $ code $ strContent e -- TODO attrs "literal" -> codeWithLang []
"prompt" -> return $ codeWith ("",["prompt"],[]) $ strContent e -- TODO attrs "prompt" -> codeWithLang ["prompt"]
"parameter" -> return $ codeWith ("",["parameter"],[]) $ strContent e -- TODO attrs "parameter" -> codeWithLang ["parameter"]
"option" -> return $ codeWith ("",["option"],[]) $ strContent e -- TODO attrs "option" -> codeWithLang ["option"]
"optional" -> do x <- getInlines e "optional" -> do x <- getInlines e
return $ str "[" <> x <> str "]" return $ str "[" <> x <> str "]"
"markup" -> return $ code $ strContent e -- TODO attrs "markup" -> codeWithLang []
"wordasword" -> emph <$> innerInlines "wordasword" -> emph <$> innerInlines
"command" -> return $ codeWith ("",["command"],[]) $ strContent e "command" -> codeWithLang ["command"]
"varname" -> return $ codeWith ("",["varname"],[]) $ strContent e "varname" -> codeWithLang ["varname"]
"function" -> return $ codeWith ("",["function"],[]) $ strContent e "function" -> codeWithLang ["function"]
"type" -> return $ codeWith ("",["type"],[]) $ strContent e "type" -> codeWithLang ["type"]
"symbol" -> return $ codeWith ("",["symbol"],[]) $ strContent e "symbol" -> codeWithLang ["symbol"]
"constant" -> return $ codeWith ("",["constant"],[]) $ strContent e "constant" -> codeWithLang ["constant"]
"userinput" -> return $ codeWith ("",["userinput"],[]) $ strContent e "userinput" -> codeWithLang ["userinput"]
"varargs" -> return $ str "(…)" "varargs" -> return $ code "(...)"
"email" -> return $ link ("mailto:" ++ strContent e) "" "email" -> return $ link ("mailto:" ++ strContent e) ""
$ code $ strContent e $ code $ strContent e
"ulink" -> link (attrValue "url" e) "" <$> innerInlines "ulink" -> link (attrValue "url" e) "" <$> innerInlines
@ -820,3 +820,9 @@ parseInline (Elem e) =
_ -> innerInlines _ -> innerInlines
where innerInlines = (trimInlines . mconcat) <$> where innerInlines = (trimInlines . mconcat) <$>
(mapM parseInline $ elContent e) (mapM parseInline $ elContent e)
codeWithLang classes = do
let classes' = case attrValue "language" e of
"" -> classes
l -> l:classes
return $ codeWith (attrValue "id" e,classes',[]) $ strContent e