git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1354 from jkr/literalTab
0d8e0e5John MacFarlane
src/Text/Pandoc/Readers/Docx.hs+16−1
@@ -134,10 +134,12 @@ codeDivs = ["SourceCode"]
134runElemToInlines :: RunElem -> [Inline]
134runElemToInlines :: RunElem -> [Inline]
135runElemToInlines (TextRun s) = strToInlines s
135runElemToInlines (TextRun s) = strToInlines s
136runElemToInlines (LnBrk) = [LineBreak]
136runElemToInlines (LnBrk) = [LineBreak]
137+runElemToInlines (Tab) = [Space]
137
138
138runElemToString :: RunElem -> String
139runElemToString :: RunElem -> String
139runElemToString (TextRun s) = s
140runElemToString (TextRun s) = s
140runElemToString (LnBrk) = ['\n']
141runElemToString (LnBrk) = ['\n']
142+runElemToString (Tab) = ['\t']
141
143
142runElemsToString :: [RunElem] -> String
144runElemsToString :: [RunElem] -> String
143runElemsToString = concatMap runElemToString
145runElemsToString = concatMap runElemToString
@@ -148,6 +150,19 @@ strNormalize (Str "" : ils) = strNormalize ils
148strNormalize ((Str s) : (Str s') : l) = strNormalize ((Str (s++s')) : l)
150strNormalize ((Str s) : (Str s') : l) = strNormalize ((Str (s++s')) : l)
149strNormalize (il:ils) = il : (strNormalize ils)
151strNormalize (il:ils) = il : (strNormalize ils)
150
152
153+blockNormalize :: Block -> Block
154+blockNormalize (Plain (Space : ils)) = blockNormalize (Plain ils)
155+blockNormalize (Plain ils) = Plain $ strNormalize ils
156+blockNormalize (Para (Space : ils)) = blockNormalize (Para ils)
157+blockNormalize (Para ils) = Para $ strNormalize ils
158+blockNormalize (Header n attr (Space : ils)) =
159+ blockNormalize $ Header n attr ils
160+blockNormalize (Table (Space : ils) align width hdr cells) =
161+ blockNormalize $ Table ils align width hdr cells
162+blockNormalize (Table ils align width hdr cells) =
163+ Table (strNormalize ils) align width hdr cells
164+blockNormalize blk = blk
165+
151runToInlines :: ReaderOptions -> Docx -> Run -> [Inline]
166runToInlines :: ReaderOptions -> Docx -> Run -> [Inline]
152runToInlines _ _ (Run rs runElems)
167runToInlines _ _ (Run rs runElems)
153 | isJust (rStyle rs) && (fromJust (rStyle rs)) `elem` codeSpans =
168 | isJust (rStyle rs) && (fromJust (rStyle rs)) `elem` codeSpans =
@@ -294,7 +309,7 @@ makeImagesSelfContained _ inline = inline
294bodyToBlocks :: ReaderOptions -> Docx -> Body -> [Block]
309bodyToBlocks :: ReaderOptions -> Docx -> Body -> [Block]
295bodyToBlocks opts docx (Body bps) =
310bodyToBlocks opts docx (Body bps) =
296 bottomUp removeEmptyPars $
311 bottomUp removeEmptyPars $
297− bottomUp strNormalize $
312+ bottomUp blockNormalize $
298 bottomUp spanRemove $
313 bottomUp spanRemove $
299 bottomUp divRemove $
314 bottomUp divRemove $
300 map (makeHeaderAnchors) $
315 map (makeHeaderAnchors) $
src/Text/Pandoc/Readers/Docx/Parse.hs+4−1
@@ -466,7 +466,7 @@ data Run = Run RunStyle [RunElem]
466 | Endnote String
466 | Endnote String
467 deriving Show
467 deriving Show
468
468
469−data RunElem = TextRun String | LnBrk
469+data RunElem = TextRun String | LnBrk | Tab
470 deriving Show
470 deriving Show
471
471
472data RunStyle = RunStyle { isBold :: Bool
472data RunStyle = RunStyle { isBold :: Bool
@@ -545,6 +545,9 @@ elemToRunElem ns element
545 | qName (elName element) == "br" &&
545 | qName (elName element) == "br" &&
546 qURI (elName element) == (lookup "w" ns) =
546 qURI (elName element) == (lookup "w" ns) =
547 Just $ LnBrk
547 Just $ LnBrk
548+ | qName (elName element) == "tab" &&
549+ qURI (elName element) == (lookup "w" ns) =
550+ Just $ Tab
548 | otherwise = Nothing
551 | otherwise = Nothing
549
552
550
553
tests/Tests/Readers/Docx.hs+6−1
@@ -44,7 +44,12 @@ tests = [ testGroup "inlines"
44 , testCompare
44 , testCompare
45 "handling unicode input"
45 "handling unicode input"
46 "docx.unicode.docx"
46 "docx.unicode.docx"
47− "docx.unicode.native"]
47+ "docx.unicode.native"
48+ , testCompare
49+ "literal tabs"
50+ "docx.tabs.docx"
51+ "docx.tabs.native"
52+ ]
48 , testGroup "blocks"
53 , testGroup "blocks"
49 [ testCompare
54 [ testCompare
50 "headers"
55 "headers"
tests/docx.notes.native+1−1
@@ -1,2 +1,2 @@
1[Header 2 ("",[],[]) [Str "A",Space,Str "footnote"]
1[Header 2 ("",[],[]) [Str "A",Space,Str "footnote"]
2−,Para [Str "Test",Space,Str "footnote.",Note [Para [Space,Str "My",Space,Str "note."]],Space,Str "Test",Space,Str "endnote.",Note [Para [Space,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."]]]]
2+,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.tabs.docxnew file

Binary file not shown.

tests/docx.tabs.nativenew file+2
@@ -0,0 +1,2 @@
1+[Para [Str "Some",Space,Str "text",Space,Str "separated",Space,Str "by",Space,Str "a",Space,Str "tab."]
2+,Para [Str "Tab-indented",Space,Str "text."]]