aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorHubert Plociniczak <hubert.plociniczak@gmail.com>2016-10-26 15:53:33 +0200
committerJesse Rosenthal <jrosenthal@jhu.edu>2016-11-08 09:29:46 -0500
commit13bc573e7f9e0602404dd37fec2c7cd14b5c56ee (patch)
treea00a7be544b104df4544ddfcd5301300476b78cc /src/Text
parenteced02d70e0a4e8d7dfa4c373a6c4d8a4cc08407 (diff)
downloadpandoc-13bc573e7f9e0602404dd37fec2c7cd14b5c56ee.tar.gz
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.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Odt/ContentReader.hs26
-rw-r--r--src/Text/Pandoc/Writers/OpenDocument.hs3
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 )