diff options
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/Odt/ContentReader.hs | 26 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/OpenDocument.hs | 3 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/Odt/ContentReader.hs b/src/Text/Pandoc/Readers/Odt/ContentReader.hs index 8093cc779..3a6a99237 100644 --- a/src/Text/Pandoc/Readers/Odt/ContentReader.hs +++ b/src/Text/Pandoc/Readers/Odt/ContentReader.hs @@ -44,7 +44,7 @@ import Control.Applicative hiding ( liftA, liftA2, liftA3 ) import qualified Data.ByteString.Lazy as B import qualified Data.Map as M -import Data.List ( find ) +import Data.List ( find, intercalate ) import Data.Maybe import qualified Text.XML.Light as XML @@ -263,8 +263,13 @@ getHeaderAnchor = proc title -> 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 ) |