From 08738954162e992b21ffa83baae7f82b10e1041f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 4 Aug 2023 20:43:39 -0700 Subject: OpenDocument writer: implement syntax highlighting. Still unimplemented: global background colors, line numbers. Closes #6710, obsoletes #6717. --- data/odt/styles.xml | 6 ++++-- src/Text/Pandoc/Writers/OpenDocument.hs | 24 ++++++++++++++---------- test/command/6792.md | 24 +++++++++++------------- test/command/8256.md | 24 +++++++++++------------- test/writer.opendocument | 24 +++++++++++------------- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/data/odt/styles.xml b/data/odt/styles.xml index ce98b73a1..d544a6750 100644 --- a/data/odt/styles.xml +++ b/data/odt/styles.xml @@ -250,14 +250,16 @@ xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.3"> fo:font-size="10pt" style:font-name-asian="Courier New" style:font-size-asian="10pt" style:font-name-complex="Courier New" - style:font-size-complex="10pt" /> + style:font-size-complex="10pt" + fo:language="zxx" /> + style:font-size-complex="10pt" + fo:language="zxx" /> flush . vcat <$> mapM inPreformattedTags h + Right h -> return $ flush . vcat $ map (inTags True "text:p" + [("text:style-name", + "Preformatted_20_Text")] . hcat) h Left msg -> do unless (T.null msg) $ report $ CouldNotHighlight msg unhighlighted s @@ -642,7 +644,8 @@ inlineToOpenDocument o ils Note l -> mkNote l where unhighlighted s = inlinedCode $ preformatted s - inlinedCode s = return $ inTags False "text:span" [("text:style-name", "Source_Text")] s + inlinedCode s = return $ inTags False "text:span" + [("text:style-name", "Source_Text")] s mkImg (_, _, kvs) s _ = do id' <- gets stImageId modify (\st -> st{ stImageId = id' + 1 }) @@ -922,21 +925,22 @@ withLangFromAttr (_,_,kvs) action = action styleToOpenDocument :: Style -> Doc Text -styleToOpenDocument style = vcat (parStyle : map toStyle alltoktypes) +styleToOpenDocument style = vcat (map toStyle alltoktypes) where alltoktypes = enumFromTo KeywordTok NormalTok toStyle toktype = inTags True "style:style" [("style:name", tshow toktype), ("style:family", "text")] $ selfClosingTag "style:text-properties" - (tokColor toktype ++ tokBgColor toktype) + (tokColor toktype ++ tokBgColor toktype ++ + [("fo:font-style", "italic") | + tokFeature tokenItalic toktype ] ++ + [("fo:font-weight", "bold") | + tokFeature tokenBold toktype ] ++ + [("style:text-underline-style", "solid") | + tokFeature tokenUnderline toktype ]) tokStyles = tokenStyles style - tokFeatures f toktype = maybe False f $ M.lookup toktype tokStyles + tokFeature f toktype = maybe False f $ M.lookup toktype tokStyles tokColor toktype = maybe [] (\c -> [("fo:color", T.pack (fromColor c))]) $ (tokenColor =<< M.lookup toktype tokStyles) `mplus` defaultColor style tokBgColor toktype = maybe [] (\c -> [("fo:background-color", T.pack (fromColor c))]) $ (tokenBackground =<< M.lookup toktype tokStyles) - `mplus` backgroundColor style - parStyle = inTags True "w:style" [("style:name", "SourceCode"), - ("style:family", "paragraph"), - ("style:class", "text")] mempty - diff --git a/test/command/6792.md b/test/command/6792.md index e7394c69e..ad7d5591e 100644 --- a/test/command/6792.md +++ b/test/command/6792.md @@ -22,10 +22,8 @@ - - - + @@ -58,19 +56,19 @@ - + - + - + - + - + @@ -82,7 +80,7 @@ - + @@ -103,16 +101,16 @@ - + - + - + - + diff --git a/test/command/8256.md b/test/command/8256.md index 4712acedd..5ba6b39cc 100644 --- a/test/command/8256.md +++ b/test/command/8256.md @@ -16,10 +16,8 @@ Testing. - - - + @@ -52,19 +50,19 @@ Testing. - + - + - + - + - + @@ -76,7 +74,7 @@ Testing. - + @@ -97,16 +95,16 @@ Testing. - + - + - + - + diff --git a/test/writer.opendocument b/test/writer.opendocument index b693bca2b..75faee891 100644 --- a/test/writer.opendocument +++ b/test/writer.opendocument @@ -4,10 +4,8 @@ - - - + @@ -40,19 +38,19 @@ - + - + - + - + - + @@ -64,7 +62,7 @@ - + @@ -85,16 +83,16 @@ - + - + - + - + -- cgit v1.2.3