From 13bc573e7f9e0602404dd37fec2c7cd14b5c56ee Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Wed, 26 Oct 2016 15:53:33 +0200 Subject: [PATCH] Inline code when text has a special style When a piece of text has a text 'Source_Text' then we assume that this is a piece of the document that represents a code that needs to be inlined. Addapted an odt writer to also reflect that change; previously it was just writing a 'preformatted' text using a non-distinguishable font style. Code blocks are still not recognized by the ODT reader. That's a separate issue. --- data/odt/styles.xml | 8 ++ src/Text/Pandoc/Readers/Odt/ContentReader.hs | 26 ++++- src/Text/Pandoc/Writers/OpenDocument.hs | 3 +- tests/Tests/Readers/Odt.hs | 1 + tests/odt/native/inlinedCode.native | 1 + tests/odt/odt/inlinedCode.odt | Bin 0 -> 10141 bytes tests/writer.opendocument | 115 +++++++++---------- 7 files changed, 85 insertions(+), 69 deletions(-) create mode 100644 tests/odt/native/inlinedCode.native create mode 100644 tests/odt/odt/inlinedCode.odt diff --git a/data/odt/styles.xml b/data/odt/styles.xml index 32b918406..1f1e2c5c8 100644 --- a/data/odt/styles.xml +++ b/data/odt/styles.xml @@ -237,6 +237,13 @@ xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2"> style:font-name-complex="Courier New" style:font-size-complex="10pt" /> + + + style:font-name-asian="Courier New" style:font-name-complex="Courier New" /> + do -------------------------------------------------------------------------------- -- -readStyleByName :: OdtReader _x Style -readStyleByName = findAttr NsText "style-name" >>? getStyleByName +readStyleByName :: OdtReader _x (StyleName, Style) +readStyleByName = + findAttr NsText "style-name" >>? keepingTheValue getStyleByName >>^ liftE + where + liftE :: (StyleName, Fallible Style) -> Fallible (StyleName, Style) + liftE (name, Right v) = Right (name, v) + liftE (_, Left v) = Left v -- isStyleToTrace :: OdtReader Style Bool @@ -275,7 +280,10 @@ withNewStyle :: OdtReaderSafe x Inlines -> OdtReaderSafe x Inlines withNewStyle a = proc x -> do fStyle <- readStyleByName -< () case fStyle of - Right style -> do + Right (styleName, _) | isCodeStyle styleName -> do + inlines <- a -< x + arr inlineCode -<< inlines + Right (_, style) -> do mFamily <- arr styleFamily -< style fTextProps <- arr ( maybeToChoice . textProperties @@ -301,7 +309,13 @@ withNewStyle a = proc x -> do Left _ -> a -< x Left _ -> a -< x Left _ -> a -< x + where + isCodeStyle :: StyleName -> Bool + isCodeStyle "Source_Text" = True + isCodeStyle _ = False + inlineCode :: Inlines -> Inlines + inlineCode = code . intercalate "" . map stringify . toList type PropertyTriple = (ReaderState, TextProperties, Maybe StyleFamily) type InlineModifier = Inlines -> Inlines @@ -327,7 +341,7 @@ modifierFromStyleDiff propertyTriple = let getVPos = Just . verticalPosition in case lookupPreviousValueM getVPos triple of Nothing -> ignore - Just oldVPos -> getVPosModifier' (oldVPos,verticalPosition textProps) + Just oldVPos -> getVPosModifier' (oldVPos, verticalPosition textProps) getVPosModifier' (oldVPos , newVPos ) | oldVPos == newVPos = ignore getVPosModifier' ( _ , VPosSub ) = subscript @@ -401,7 +415,7 @@ constructPara reader = proc blocks -> do fStyle <- readStyleByName -< blocks case fStyle of Left _ -> reader -< blocks - Right style -> do + Right (_, style) -> do let modifier = getParaModifier style blocks' <- reader -< blocks arr modifier -<< blocks' diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index 583aa2e4a..42c151780 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -392,7 +392,7 @@ inlineToOpenDocument o ils Subscript l -> withTextStyle Sub $ inlinesToOpenDocument o l SmallCaps l -> withTextStyle SmallC $ inlinesToOpenDocument o l Quoted t l -> inQuotes t <$> inlinesToOpenDocument o l - Code _ s -> withTextStyle Pre $ inTextStyle $ preformatted s + Code _ s -> inlinedCode $ preformatted s Math t s -> inlinesToOpenDocument o (texMathToInlines t s) Cite _ l -> inlinesToOpenDocument o l RawInline f s -> if f == Format "opendocument" @@ -403,6 +403,7 @@ inlineToOpenDocument o ils Note l -> mkNote l where preformatted s = handleSpaces $ escapeStringForXML s + inlinedCode s = return $ inTags False "text:span" [("text:style-name", "Source_Text")] s mkLink s t = inTags False "text:a" [ ("xlink:type" , "simple") , ("xlink:href" , s ) , ("office:name", t ) diff --git a/tests/Tests/Readers/Odt.hs b/tests/Tests/Readers/Odt.hs index b0c5aefb1..d6ed48f8d 100644 --- a/tests/Tests/Readers/Odt.hs +++ b/tests/Tests/Readers/Odt.hs @@ -149,6 +149,7 @@ namesOfTestsComparingToNative = [ "blockquote" , "image" , "imageIndex" , "imageWithCaption" + , "inlinedCode" , "orderedListMixed" , "orderedListRoman" , "orderedListSimple" diff --git a/tests/odt/native/inlinedCode.native b/tests/odt/native/inlinedCode.native new file mode 100644 index 000000000..6e32ff7a9 --- /dev/null +++ b/tests/odt/native/inlinedCode.native @@ -0,0 +1 @@ +[Para [Str "Here",Space,Str "comes",Space,Code ("",[],[]) "inlined code",Space,Str "text",Space,Str "and",Space,Code ("",[],[]) "an another",Space,Str "one."]] diff --git a/tests/odt/odt/inlinedCode.odt b/tests/odt/odt/inlinedCode.odt new file mode 100644 index 0000000000000000000000000000000000000000..320375cc90bd2ea4e9b859b466f0070393d8a3f9 GIT binary patch literal 10141 zcmdUVbzD?k*Y*H{q<|nGB_-Y6B8@Z>f`Bv(Fw_hsDJ>leNJxVq9fNdt&nVp`-JKuY z&*P)_{p$05@1NhA-}%isXYY0GefC-F?7i2zROFHF-~&)mQ2})?bmaiQ2;I%OgsqJk z(A?3%5CXKd0duk$8XKEho8Da7IY{xGPDE#7vqB&Ln| zS`3ob#4rz~SjVZc+)qi({q8z&ydzwdrs!@7$0l?VTiY#%KzFe7Us(xrZ<1-zIg79y zjk;PZ#x+Y(75c-7nHRs_O?!^ofPHMM?<^V^Zznd}WhbIR)XTKHfIaGtcy2r{xU1X_dHAU{r7?QG27swl}|p%bIu zRKb#yl~lX=uK)lL0H`;5fac4N)td_=6$N!EXB$g9dx#g<-rh67(KF<=>luc|W4ZvaWuI8b>p2@x@*ihfZQ0L&+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Ito@m1fDYmZO ze5eQ59}hGgAO(>NPs46*U6#DBpS3$y&Nx60I``_#WRums9*bHnNj^W=6%2p=i2j3R zc#?+fABh3&Qb+(8w zDmiaaLyC5-)vgsex$Y7hhiE~3y{=< zK$#uyFs693H<{QxS|Es`BM+am-d13nKfr>oT91ny{RJQ)^2s)}zbD6F+_&4m5HT;i z96uVLElO#;fkM|1|9s!E+;L**>AG1|8 z4tIVKjy0%-ZAY^q+`5FSKE?xw{_)~?4(Sya? zd)Uq10y`-OzQDokZDM4~?Qll?jq@-QV3zO+$M|~ zD~h6llr1dXDqYRkFc>qDRU%Pj6nroN@vpuk;ggYGr7IN+)CSjVv>`=^Q~ISpKyhS8 zXy@)H+#|-*$uU5F_HplV??6kWUvq4fOao4AqKpmq=^>GBQbZTSlTT~W-ePu_?MBy` zDjB@qM)fa4g$3EqjA@vjR=bR<0P_N&U1&n@f_NouFQ`DdMkR+4WZlNG);bPRI{R%) zR6+QD*9f;k$50f^mnB#L!25T%8$AR>e8As{F+aF1x1qM zqIGlnPtczvnSXWdcPO_snV%ANbNWw||3RAhGuYp|)cqTucVtl0%RkcxKef{D z-Dv$gneapFM=yU30sXy~+c#RjW)1$S`Rh03HbnGOSZ`j~&w!DN{B4K{0KmQZ+1(^P J2&r$c{tp&tc?JLg literal 0 HcmV?d00001 diff --git a/tests/writer.opendocument b/tests/writer.opendocument index 5007c5635..6c84ae31b 100644 --- a/tests/writer.opendocument +++ b/tests/writer.opendocument @@ -668,47 +668,37 @@ - - - - - + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - + - - + + - + - - - - - - - - - - @@ -1358,22 +1348,22 @@ Markup So is this word. This is code: ->, -$, -\, -\$, -<html>. -This -is -strikeout. +>, +$, +\, +\$, +<html>. +This +is +strikeout. Superscripts: -abcd -ahello -ahello there. +abcd +ahello +ahello there. Subscripts: -H2O, -H23O, -Hmany of themO. +H2O, +H23O, +Hmany of themO. These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d. @@ -1387,7 +1377,7 @@ trees. So is ‘pine.’ ‘He said, “I want to go.”’ Were you alive in the 70’s? Here is some quoted -‘code’ and a +‘code’ and a “quoted link”. Some dashes: one—two — three—four — @@ -1405,16 +1395,16 @@ five. 2 + 2 = 4 - x ∈ y + x ∈ y - α ∧ ω + α ∧ ω 223 - p-Tree + p-Tree Here’s some display math: @@ -1422,18 +1412,18 @@ five. Here’s one that has a line break in it: - α + ω × x2. + α + ω × x2. These shouldn’t be math: To get the famous equation, write - $e = mc^2$. + $e = mc^2$. $22,000 is a - lot of money. So is $34,000. + lot of money. So is $34,000. (It worked if “lot” is emphasized.) @@ -1441,11 +1431,11 @@ five. Escaped - $: $73 - this - should - be - emphasized + $: $73 + this + should + be + emphasized 23$. @@ -1570,7 +1560,7 @@ link in pointy braces. Blockquoted: http://example.com/ Auto-links should not occur here: -<http://example.com/> +<http://example.com/> or here: <http://example.com/> Images @@ -1595,14 +1585,15 @@ indented to show that they belong to the footnote (as with list items).{ <code> }If you want, you can indent every line, but you can also be lazy and just indent the first line of each block. This -should not be a footnote +should not be a footnote reference, because it contains a space.[^my note] Here is an inline note.3This -is easier to type. Inline notes +is easier to type. Inline notes may contain links -and ] verbatim characters, as -well as [bracketed text]. +and ] verbatim +characters, as well as [bracketed +text]. Notes can go in quotes.4In quote.