Merge pull request #1379 from jkr/more_auto_id

Docx Reader: Extend auto id behavior to all headers
This commit is contained in:
John MacFarlane 2014-06-28 15:00:25 -07:00
commit ce69021e42
8 changed files with 19 additions and 10 deletions

View file

@ -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

View file

@ -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."]]

View file

@ -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."]]

View file

@ -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","")]]

View file

@ -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."]

View file

@ -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"]

View file

@ -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."]]]]

View file

@ -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"]]