aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-05-14 10:37:46 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-05-14 10:37:46 -0700
commit2b89aaf04dd2d1bdafa0ee507abefd4f0d6df271 (patch)
tree855653c0624a174a0ebb97670841b64abe81165c /src/Text/Pandoc
parent933aa3ee8493f53f5ef1dfa7565530313dd75b98 (diff)
downloadpandoc-2b89aaf04dd2d1bdafa0ee507abefd4f0d6df271.tar.gz
Make internal links work in ODT/OpenDocument.
This adds proper bookmarks to the headers with non-null IDs. Closes #4358.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/OpenDocument.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs
index 514327e9a..21d709f98 100644
--- a/src/Text/Pandoc/Writers/OpenDocument.hs
+++ b/src/Text/Pandoc/Writers/OpenDocument.hs
@@ -193,10 +193,15 @@ formulaStyle mt = inTags False "style:style"
,("style:horizontal-rel", "paragraph-content")
,("style:wrap", "none")]
-inHeaderTags :: PandocMonad m => Int -> Doc -> OD m Doc
-inHeaderTags i d =
+inHeaderTags :: PandocMonad m => Int -> String -> Doc -> OD m Doc
+inHeaderTags i ident d =
return $ inTags False "text:h" [ ("text:style-name", "Heading_20_" ++ show i)
- , ("text:outline-level", show i)] d
+ , ("text:outline-level", show i)]
+ $ if null ident
+ then d
+ else selfClosingTag "text:bookmark-start" [ ("text:name", ident) ]
+ <> d <>
+ selfClosingTag "text:bookmark-end" [ ("text:name", ident) ]
inQuotes :: QuoteType -> Doc -> Doc
inQuotes SingleQuote s = char '\8216' <> s <> char '\8217'
@@ -349,8 +354,9 @@ blockToOpenDocument o bs
| LineBlock b <- bs = blockToOpenDocument o $ linesToPara b
| Div attr xs <- bs = withLangFromAttr attr
(blocksToOpenDocument o xs)
- | Header i _ b <- bs = setFirstPara >>
- (inHeaderTags i =<< inlinesToOpenDocument o b)
+ | Header i (ident,_,_) b
+ <- bs = setFirstPara >> (inHeaderTags i ident
+ =<< inlinesToOpenDocument o b)
| BlockQuote b <- bs = setFirstPara >> mkBlockQuote b
| DefinitionList b <- bs = setFirstPara >> defList b
| BulletList b <- bs = setFirstPara >> bulletListToOpenDocument o b