aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-06-28 15:00:25 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-06-28 15:00:25 -0700
commitce69021e42d7bf50deccba2a52ed4717f6ddac10 (patch)
treecec0417928f4a00d18b7a447948424f75eb90526
parent7fc7e61745085ec87c074c147f372474074c46e3 (diff)
parent7fb74d88fb3a55a91340c00b5f1e3c006314769d (diff)
downloadpandoc-ce69021e42d7bf50deccba2a52ed4717f6ddac10.tar.gz
Merge pull request #1379 from jkr/more_auto_id
Docx Reader: Extend auto id behavior to all headers
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs11
-rw-r--r--tests/docx.block_quotes_parse_indent.native2
-rw-r--r--tests/docx.headers.native6
-rw-r--r--tests/docx.image_no_embed.native2
-rw-r--r--tests/docx.links.native2
-rw-r--r--tests/docx.lists.native2
-rw-r--r--tests/docx.notes.native2
-rw-r--r--tests/docx.tables.native2
8 files changed, 19 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 0607aac7f..71baa5dde 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -103,7 +103,6 @@ readDocx opts bytes =
Just docx -> Pandoc nullMeta (docxToBlocks opts docx)
Nothing -> error $ "couldn't parse docx file"
-
data DState = DState { docxAnchorMap :: M.Map String String }
data DEnv = DEnv { docxOptions :: ReaderOptions
@@ -321,6 +320,8 @@ dummyAnchors :: [String]
dummyAnchors = ["_GoBack"]
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)
| (x : xs) <- filter isAnchorSpan ils
, (Span (ident, _, _) _) <- x
@@ -330,6 +331,14 @@ makeHeaderAnchor (Header n (_, classes, kvs) ils)
let newIdent = uniqueIdent ils (M.elems hdrIDMap)
put DState{docxAnchorMap = M.insert ident newIdent hdrIDMap}
return $ Header n (newIdent, classes, kvs) (ils \\ (x:xs))
+-- Otherwise we just give it a name, and register that name (associate
+-- it with itself.)
+makeHeaderAnchor (Header n (_, classes, kvs) ils) =
+ do
+ hdrIDMap <- gets docxAnchorMap
+ let newIdent = uniqueIdent ils (M.elems hdrIDMap)
+ put DState{docxAnchorMap = M.insert newIdent newIdent hdrIDMap}
+ return $ Header n (newIdent, classes, kvs) ils
makeHeaderAnchor blk = return blk
diff --git a/tests/docx.block_quotes_parse_indent.native b/tests/docx.block_quotes_parse_indent.native
index da1cef110..842b3606a 100644
--- a/tests/docx.block_quotes_parse_indent.native
+++ b/tests/docx.block_quotes_parse_indent.native
@@ -1,4 +1,4 @@
-[Header 2 ("",[],[]) [Str "Some",Space,Str "block",Space,Str "quotes,",Space,Str "in",Space,Str "different",Space,Str "ways"]
+[Header 2 ("some-block-quotes-in-different-ways",[],[]) [Str "Some",Space,Str "block",Space,Str "quotes,",Space,Str "in",Space,Str "different",Space,Str "ways"]
,Para [Str "This",Space,Str "is",Space,Str "the",Space,Str "proper",Space,Str "way,",Space,Str "with",Space,Str "a",Space,Str "style"]
,BlockQuote
[Para [Str "I",Space,Str "don\8217t",Space,Str "know",Space,Str "why",Space,Str "this",Space,Str "would",Space,Str "be",Space,Str "in",Space,Str "italics,",Space,Str "but",Space,Str "so",Space,Str "it",Space,Str "appears",Space,Str "to",Space,Str "be",Space,Str "on",Space,Str "my",Space,Str "screen."]]
diff --git a/tests/docx.headers.native b/tests/docx.headers.native
index e4d4a4781..03f967728 100644
--- a/tests/docx.headers.native
+++ b/tests/docx.headers.native
@@ -1,5 +1,5 @@
-[Header 1 ("",[],[]) [Str "A",Space,Str "Test",Space,Str "of",Space,Str "Headers"]
-,Header 2 ("",[],[]) [Str "Second",Space,Str "Level"]
+[Header 1 ("a-test-of-headers",[],[]) [Str "A",Space,Str "Test",Space,Str "of",Space,Str "Headers"]
+,Header 2 ("second-level",[],[]) [Str "Second",Space,Str "Level"]
,Para [Str "Some",Space,Str "plain",Space,Str "text."]
-,Header 3 ("",[],[]) [Str "Third",Space,Str "level"]
+,Header 3 ("third-level",[],[]) [Str "Third",Space,Str "level"]
,Para [Str "Some",Space,Str "more",Space,Str "plain",Space,Str "text."]]
diff --git a/tests/docx.image_no_embed.native b/tests/docx.image_no_embed.native
index 18debf135..063958bc7 100644
--- a/tests/docx.image_no_embed.native
+++ b/tests/docx.image_no_embed.native
@@ -1,2 +1,2 @@
-[Header 2 ("",[],[]) [Str "An",Space,Str "image"]
+[Header 2 ("an-image",[],[]) [Str "An",Space,Str "image"]
,Para [Image [] ("word/media/image1.jpeg","")]]
diff --git a/tests/docx.links.native b/tests/docx.links.native
index fb95863a4..c741fe875 100644
--- a/tests/docx.links.native
+++ b/tests/docx.links.native
@@ -1,4 +1,4 @@
-[Header 2 ("",[],[]) [Str "An",Space,Str "internal",Space,Str "link",Space,Str "and",Space,Str "an",Space,Str "external",Space,Str "link"]
+[Header 2 ("an-internal-link-and-an-external-link",[],[]) [Str "An",Space,Str "internal",Space,Str "link",Space,Str "and",Space,Str "an",Space,Str "external",Space,Str "link"]
,Para [Str "An",Space,Link [Str "external",Space,Str "link"] ("http://google.com",""),Space,Str "to",Space,Str "a",Space,Str "popular",Space,Str "website."]
,Para [Str "An",Space,Link [Str "internal",Space,Str "link"] ("#a-section-for-testing-link-targets",""),Space,Str "to",Space,Str "a",Space,Str "section",Space,Str "header."]
,Para [Str "An",Space,Link [Str "internal",Space,Str "link"] ("#my_bookmark",""),Space,Str "to",Space,Str "a",Space,Str "bookmark."]
diff --git a/tests/docx.lists.native b/tests/docx.lists.native
index e46bc140b..af922b335 100644
--- a/tests/docx.lists.native
+++ b/tests/docx.lists.native
@@ -1,4 +1,4 @@
-[Header 2 ("",[],[]) [Str "Some",Space,Str "nested",Space,Str "lists"]
+[Header 2 ("some-nested-lists",[],[]) [Str "Some",Space,Str "nested",Space,Str "lists"]
,OrderedList (1,Decimal,Period)
[[Para [Str "one"]]
,[Para [Str "two"]
diff --git a/tests/docx.notes.native b/tests/docx.notes.native
index 5a94b1999..ec1b414b6 100644
--- a/tests/docx.notes.native
+++ b/tests/docx.notes.native
@@ -1,2 +1,2 @@
-[Header 2 ("",[],[]) [Str "A",Space,Str "footnote"]
+[Header 2 ("a-footnote",[],[]) [Str "A",Space,Str "footnote"]
,Para [Str "Test",Space,Str "footnote.",Note [Para [Str "My",Space,Str "note."]],Space,Str "Test",Space,Str "endnote.",Note [Para [Str "This",Space,Str "is",Space,Str "an",Space,Str "endnote",Space,Str "at",Space,Str "the",Space,Str "end",Space,Str "of",Space,Str "the",Space,Str "document."]]]]
diff --git a/tests/docx.tables.native b/tests/docx.tables.native
index 8dbaabda7..2564afcec 100644
--- a/tests/docx.tables.native
+++ b/tests/docx.tables.native
@@ -1,4 +1,4 @@
-[Header 2 ("",[],[]) [Str "A",Space,Str "table,",Space,Str "with",Space,Str "and",Space,Str "without",Space,Str "a",Space,Str "header",Space,Str "row"]
+[Header 2 ("a-table-with-and-without-a-header-row",[],[]) [Str "A",Space,Str "table,",Space,Str "with",Space,Str "and",Space,Str "without",Space,Str "a",Space,Str "header",Space,Str "row"]
,Table [] [AlignDefault,AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0,0.0]
[[Para [Str "Name"]]
,[Para [Str "Game"]]