summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2016-08-28 18:03:09 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2016-08-28 18:03:09 -0400
commit62882f976d2fb37c317dac7c35c6ce82b784b95b (patch)
treeeccc91c08974a1a05ff9d9e0aea3450d2b3252e4 /src
parentd29a6238968c963c8fba829d23a605d3e780118e (diff)
Docx reader: Handle anchor spans with content in headers.
Previously, we would only be able to figure out internal links to a header in a docx if the anchor span was empty. We change that to read the inlines out of the first anchor span in a header. This still leaves another problem: what to do if there are multiple anchor spans in a header. That will be addressed in a future commit.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 2bc17c069..f74b2b6d6 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -83,7 +83,7 @@ import Text.Pandoc.Readers.Docx.Lists
import Text.Pandoc.Readers.Docx.Combine
import Text.Pandoc.Shared
import Text.Pandoc.MediaBag (insertMedia, MediaBag)
-import Data.List (delete, (\\), intersect)
+import Data.List (delete, intersect)
import Text.TeXMath (writeTeX)
import Data.Default (Default)
import qualified Data.ByteString.Lazy as B
@@ -412,10 +412,9 @@ parPartToInlines (PlainOMath exps) = do
return $ math $ writeTeX exps
isAnchorSpan :: Inline -> Bool
-isAnchorSpan (Span (_, classes, kvs) ils) =
+isAnchorSpan (Span (_, classes, kvs) _) =
classes == ["anchor"] &&
- null kvs &&
- null ils
+ null kvs
isAnchorSpan _ = False
dummyAnchors :: [String]
@@ -433,12 +432,14 @@ makeHeaderAnchor' :: Block -> DocxContext Block
-- If there is an anchor already there (an anchor span in the header,
-- to be exact), we rename and associate the new id with the old one.
makeHeaderAnchor' (Header n (_, classes, kvs) ils)
- | (c:cs) <- filter isAnchorSpan ils
- , (Span (ident, ["anchor"], _) _) <- c = do
+ | (c:_) <- filter isAnchorSpan ils
+ , (Span (ident, ["anchor"], _) cIls) <- c = do
hdrIDMap <- gets docxAnchorMap
let newIdent = uniqueIdent ils (Set.fromList $ M.elems hdrIDMap)
+ newIls = concatMap f ils where f il | il == c = cIls
+ | otherwise = [il]
modify $ \s -> s {docxAnchorMap = M.insert ident newIdent hdrIDMap}
- return $ Header n (newIdent, classes, kvs) (ils \\ (c:cs))
+ return $ Header n (newIdent, classes, kvs) newIls
-- Otherwise we just give it a name, and register that name (associate
-- it with itself.)
makeHeaderAnchor' (Header n (_, classes, kvs) ils) =