@@ -188,18 +188,36 @@ blockToDocbook opts (Div (id',"section":_,_) (Header lvl _ ils : xs)) = do
188 title' <- inlinesToDocbook opts ils
188 title' <- inlinesToDocbook opts ils
189 contents <- blocksToDocbook opts bs
189 contents <- blocksToDocbook opts bs
190 return $ inTags True tag attribs $ inTagsSimple "title" title' $$ contents
190 return $ inTags True tag attribs $ inTagsSimple "title" title' $$ contents
191−blockToDocbook opts (Div (ident,_,_) [Para lst]) =
191+blockToDocbook opts (Div (ident,classes,_) bs) =
192− let attribs = [("id", ident) | not (T.null ident)] in
192+ let identAttribs = [("id", ident) | not (T.null ident)]
193+ admonitions = ["attention","caution","danger","error","hint",
194+ "important","note","tip","warning"]
196+ (l:_) | l `elem` admonitions -> do
197+ let (mTitleBs, bodyBs) =
199+ -- Matches AST produced by the Docbook reader.
200+ (Div (_,["title"],_) ts : rest) -> (Just (blocksToDocbook opts ts), rest)
202+ admonitionTitle <- case mTitleBs of
203+ Nothing -> return mempty
204+ -- id will be attached to the admonition so let’s pass empty identAttrs.
205+ Just titleBs -> inTags False "title" [] <$> titleBs
206+ admonitionBody <- handleDivBody [] bodyBs
207+ return (inTags True l identAttribs (admonitionTitle $$ admonitionBody))
208+ _ -> handleDivBody identAttribs bs
210+ handleDivBody identAttribs [Para lst] =
193− if hasLineBreaks lst
211+ if hasLineBreaks lst
194− then flush . nowrap . inTags False "literallayout" attribs
212+ then flush . nowrap . inTags False "literallayout" identAttribs
195− <$> inlinesToDocbook opts lst
213+ <$> inlinesToDocbook opts lst
196− else inTags True "para" attribs <$> inlinesToDocbook opts lst
214+ else inTags True "para" identAttribs <$> inlinesToDocbook opts lst
197−blockToDocbook opts (Div (ident,_,_) bs) = do
215+ handleDivBody identAttribs bodyBs = do
198− contents <- blocksToDocbook opts (map plainToPara bs)
216+ contents <- blocksToDocbook opts (map plainToPara bodyBs)
199− return $
217+ return $
200− (if T.null ident
218+ (if null identAttribs
201− then mempty
219+ then mempty
202− else selfClosingTag "anchor" [("id", ident)]) $$ contents
220+ else selfClosingTag "anchor" identAttribs) $$ contents
203blockToDocbook _ h@Header{} = do
221blockToDocbook _ h@Header{} = do
204 -- should be handled by Div section above, except inside lists/blockquotes
222 -- should be handled by Div section above, except inside lists/blockquotes
205 report $ BlockNotRendered h
223 report $ BlockNotRendered h