git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2432 from hftf/hyphens

Docx Reader: Parse soft and non-breaking hyphen elements

commit869e800bbbe4008beeb3e3420e689aafd6e67aa7 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 4 Oct 2015, 21:56 (11 years ago) parente32ab44dfd0646
5 files changed+13−1
src/Text/Pandoc/Readers/Docx.hs+4 src/Text/Pandoc/Readers/Docx/Parse.hs+3−1 tests/Tests/Readers/Docx.hs+4 tests/docx/special_punctuation.docx tests/docx/special_punctuation.native+2
src/Text/Pandoc/Readers/Docx.hs+4
@@ -206,11 +206,15 @@ runElemToInlines :: RunElem -> Inlines
206206runElemToInlines (TextRun s) = text s
207207runElemToInlines (LnBrk) = linebreak
208208runElemToInlines (Tab) = space
209+runElemToInlines (SoftHyphen) = text "\xad"
210+runElemToInlines (NoBreakHyphen) = text "\x2011"
209211
210212runElemToString :: RunElem -> String
211213runElemToString (TextRun s) = s
212214runElemToString (LnBrk) = ['\n']
213215runElemToString (Tab) = ['\t']
216+runElemToString (SoftHyphen) = ['\xad']
217+runElemToString (NoBreakHyphen) = ['\x2011']
214218
215219runToString :: Run -> String
216220runToString (Run _ runElems) = concatMap runElemToString runElems
src/Text/Pandoc/Readers/Docx/Parse.hs+3−1
@@ -208,7 +208,7 @@ data Run = Run RunStyle [RunElem]
208208 | InlineDrawing FilePath B.ByteString
209209 deriving Show
210210
211−data RunElem = TextRun String | LnBrk | Tab
211+data RunElem = TextRun String | LnBrk | Tab | SoftHyphen | NoBreakHyphen
212212 deriving Show
213213
214214data VertAlign = BaseLn | SupScrpt | SubScrpt
@@ -877,6 +877,8 @@ elemToRunElem ns element
877877 map (\x -> fromMaybe x . getUnicode f . lowerFromPrivate $ x) str
878878 | isElem ns "w" "br" element = return LnBrk
879879 | isElem ns "w" "tab" element = return Tab
880+ | isElem ns "w" "softHyphen" element = return SoftHyphen
881+ | isElem ns "w" "noBreakHyphen" element = return NoBreakHyphen
880882 | isElem ns "w" "sym" element = return (getSymChar ns element)
881883 | otherwise = throwError WrongElem
882884 where
tests/Tests/Readers/Docx.hs+4
@@ -130,6 +130,10 @@ tests = [ testGroup "inlines"
130130 "literal tabs"
131131 "docx/tabs.docx"
132132 "docx/tabs.native"
133+ , testCompare
134+ "special punctuation"
135+ "docx/special_punctuation.docx"
136+ "docx/special_punctuation.native"
133137 , testCompare
134138 "normalizing inlines"
135139 "docx/normalize.docx"
tests/docx/special_punctuation.docxnew file

Binary file not shown.

tests/docx/special_punctuation.nativenew file+2
@@ -0,0 +1,2 @@
1+[Para [Str "Soft",Space,Str "hyphen:",Space,Str "[\173]"]
2+,Para [Str "Non-breaking",Space,Str "hyphen:",Space,Str "[\8209]"]]