diff options
author | Frerich Raabe <raabe@froglogic.com> | 2015-09-23 22:53:50 +0200 |
---|---|---|
committer | Frerich Raabe <raabe@froglogic.com> | 2015-09-24 18:26:55 +0200 |
commit | 35f12b5095799e41b563f47a7923a1d01015c71c (patch) | |
tree | 11c156045a0811fee4512366e387034ea1991e1f /src/Text/Pandoc | |
parent | f6538144f0763ae17b60c78810ed52ab96df308d (diff) | |
download | pandoc-35f12b5095799e41b563f47a7923a1d01015c71c.tar.gz |
Added proper support for DocBook 'xref' elements
'xref' is used to create cross references to other parts of the
document. It is an empty element - the cross reference text depends on
various attributes. Quoting 'DocBook: The Definitive Guide':
1. If the endterm attribute is specified on xref, the content of the
element pointed to by endterm will be used as the text of the
cross-reference.
2. Otherwise, if the object pointed to has a specified XRefLabel, the
content of that attribute will be used as the cross-reference text.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/DocBook.hs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index 83e2f3900..164b44b62 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -18,6 +18,7 @@ import Text.TeXMath (readMathML, writeTeX) import Text.Pandoc.Error (PandocError) import Text.Pandoc.Compat.Except import Data.Default +import Data.Foldable (asum) {- @@ -498,7 +499,7 @@ List of all DocBook tags, with [x] indicating implemented, [x] warning - An admonition set off from the text [x] wordasword - A word meant specifically as a word and not representing anything else -[ ] xref - A cross reference to another part of the document +[x] xref - A cross reference to another part of the document [ ] year - The year of publication of a document [x] ?asciidoc-br? - line break from asciidoc docbook output -} @@ -952,7 +953,13 @@ parseInline (Elem e) = "keycombo" -> keycombo <$> (mapM parseInline $ elContent e) "menuchoice" -> menuchoice <$> (mapM parseInline $ filter isGuiMenu $ elContent e) - "xref" -> return $ str "?" -- so at least you know something is there + "xref" -> do + content <- dbContent <$> get + let linkend = attrValue "linkend" e + let title = case attrValue "endterm" e of + "" -> maybe "???" xrefTitleByElem (findElementById linkend content) + endterm -> maybe "???" strContent (findElementById endterm content) + return $ link ('#' : linkend) "" (singleton (Str title)) "email" -> return $ link ("mailto:" ++ strContent e) "" $ str $ strContent e "uri" -> return $ link (strContent e) "" $ str $ strContent e @@ -1013,3 +1020,12 @@ parseInline (Elem e) = isGuiMenu (Elem x) = named "guimenu" x || named "guisubmenu" x || named "guimenuitem" x isGuiMenu _ = False + + findElementById idString content + = asum [filterElement (\x -> attrValue "id" x == idString) el | Elem el <- content] + + xrefTitleByElem el + | null xrefLabel = "???" + | otherwise = xrefLabel + where + xrefLabel = attrValue "xreflabel" el |