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 000000000..320375cc9 Binary files /dev/null and b/tests/odt/odt/inlinedCode.odt differ 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.