git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1379 from jkr/more_auto_id

Docx Reader: Extend auto id behavior to all headers

commitce69021e42d7bf50deccba2a52ed4717f6ddac10 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 28 Jun 2014, 15:00 (12 years ago) parent7fc7e617fb74d8
8 files changed+19−10
src/Text/Pandoc/Readers/Docx.hs+10−1 tests/docx.block_quotes_parse_indent.native+1−1 tests/docx.headers.native+3−3 tests/docx.image_no_embed.native+1−1 tests/docx.links.native+1−1 tests/docx.lists.native+1−1 tests/docx.notes.native+1−1 tests/docx.tables.native+1−1
src/Text/Pandoc/Readers/Docx.hs+10−1
@@ -103,7 +103,6 @@ readDocx opts bytes =
103103 Just docx -> Pandoc nullMeta (docxToBlocks opts docx)
104104 Nothing -> error $ "couldn't parse docx file"
105105
106−
107106data DState = DState { docxAnchorMap :: M.Map String String }
108107
109108data DEnv = DEnv { docxOptions :: ReaderOptions
@@ -321,6 +320,8 @@ dummyAnchors :: [String]
321320dummyAnchors = ["_GoBack"]
322321
323322makeHeaderAnchor :: Block -> DocxContext Block
323+-- If there is an anchor already there (an anchor span in the header,
324+-- to be exact), we rename and associate the new id with the old one.
324325makeHeaderAnchor (Header n (_, classes, kvs) ils)
325326 | (x : xs) <- filter isAnchorSpan ils
326327 , (Span (ident, _, _) _) <- x
@@ -330,6 +331,14 @@ makeHeaderAnchor (Header n (_, classes, kvs) ils)
330331 let newIdent = uniqueIdent ils (M.elems hdrIDMap)
331332 put DState{docxAnchorMap = M.insert ident newIdent hdrIDMap}
332333 return $ Header n (newIdent, classes, kvs) (ils \\ (x:xs))
334+-- Otherwise we just give it a name, and register that name (associate
335+-- it with itself.)
336+makeHeaderAnchor (Header n (_, classes, kvs) ils) =
337+ do
338+ hdrIDMap <- gets docxAnchorMap
339+ let newIdent = uniqueIdent ils (M.elems hdrIDMap)
340+ put DState{docxAnchorMap = M.insert newIdent newIdent hdrIDMap}
341+ return $ Header n (newIdent, classes, kvs) ils
333342makeHeaderAnchor blk = return blk
334343
335344
tests/docx.block_quotes_parse_indent.native+1−1
@@ -1,4 +1,4 @@
1−[Header 2 ("",[],[]) [Str "Some",Space,Str "block",Space,Str "quotes,",Space,Str "in",Space,Str "different",Space,Str "ways"]
1+[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"]
22,Para [Str "This",Space,Str "is",Space,Str "the",Space,Str "proper",Space,Str "way,",Space,Str "with",Space,Str "a",Space,Str "style"]
33,BlockQuote
44 [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."]]
tests/docx.headers.native+3−3
@@ -1,5 +1,5 @@
1−[Header 1 ("",[],[]) [Str "A",Space,Str "Test",Space,Str "of",Space,Str "Headers"]
2−,Header 2 ("",[],[]) [Str "Second",Space,Str "Level"]
1+[Header 1 ("a-test-of-headers",[],[]) [Str "A",Space,Str "Test",Space,Str "of",Space,Str "Headers"]
2+,Header 2 ("second-level",[],[]) [Str "Second",Space,Str "Level"]
33,Para [Str "Some",Space,Str "plain",Space,Str "text."]
4−,Header 3 ("",[],[]) [Str "Third",Space,Str "level"]
4+,Header 3 ("third-level",[],[]) [Str "Third",Space,Str "level"]
55,Para [Str "Some",Space,Str "more",Space,Str "plain",Space,Str "text."]]
tests/docx.image_no_embed.native+1−1
@@ -1,2 +1,2 @@
1−[Header 2 ("",[],[]) [Str "An",Space,Str "image"]
1+[Header 2 ("an-image",[],[]) [Str "An",Space,Str "image"]
22,Para [Image [] ("word/media/image1.jpeg","")]]
tests/docx.links.native+1−1
@@ -1,4 +1,4 @@
1−[Header 2 ("",[],[]) [Str "An",Space,Str "internal",Space,Str "link",Space,Str "and",Space,Str "an",Space,Str "external",Space,Str "link"]
1+[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"]
22,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."]
33,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."]
44,Para [Str "An",Space,Link [Str "internal",Space,Str "link"] ("#my_bookmark",""),Space,Str "to",Space,Str "a",Space,Str "bookmark."]
tests/docx.lists.native+1−1
@@ -1,4 +1,4 @@
1−[Header 2 ("",[],[]) [Str "Some",Space,Str "nested",Space,Str "lists"]
1+[Header 2 ("some-nested-lists",[],[]) [Str "Some",Space,Str "nested",Space,Str "lists"]
22,OrderedList (1,Decimal,Period)
33 [[Para [Str "one"]]
44 ,[Para [Str "two"]
tests/docx.notes.native+1−1
@@ -1,2 +1,2 @@
1−[Header 2 ("",[],[]) [Str "A",Space,Str "footnote"]
1+[Header 2 ("a-footnote",[],[]) [Str "A",Space,Str "footnote"]
22,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."]]]]
tests/docx.tables.native+1−1
@@ -1,4 +1,4 @@
1−[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"]
1+[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"]
22,Table [] [AlignDefault,AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0,0.0]
33 [[Para [Str "Name"]]
44 ,[Para [Str "Game"]]