diff options
| -rw-r--r-- | data/templates/default.opendocument | 3 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/OpenDocument.hs | 25 | ||||
| -rw-r--r-- | test/command/6792.md | 97 | ||||
| -rw-r--r-- | test/command/8256.md | 97 | ||||
| -rw-r--r-- | test/writer.opendocument | 97 |
5 files changed, 318 insertions, 1 deletions
diff --git a/data/templates/default.opendocument b/data/templates/default.opendocument index fceab3501..de96c9021 100644 --- a/data/templates/default.opendocument +++ b/data/templates/default.opendocument @@ -3,6 +3,9 @@ <office:font-face-decls> <style:font-face style:name="Courier New" style:font-family-generic="modern" style:font-pitch="fixed" svg:font-family="'Courier New'" /> </office:font-face-decls> + <office:styles> + $highlighting-styles$ + </office:styles> <office:automatic-styles> $automatic-styles$ </office:automatic-styles> diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index 8b1090e9e..bad61a747 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -15,7 +15,7 @@ Conversion of 'Pandoc' documents to OpenDocument XML. -} module Text.Pandoc.Writers.OpenDocument ( writeOpenDocument ) where import Control.Arrow ((***), (>>>)) -import Control.Monad (unless, liftM) +import Control.Monad (unless, liftM, MonadPlus(mplus)) import Control.Monad.State.Strict ( StateT(..), modify, gets, lift ) import Data.Char (chr) import Data.Foldable (find) @@ -45,6 +45,7 @@ import Text.Pandoc.XML import Text.Printf (printf) import Text.Pandoc.Highlighting (highlight) import Skylighting +import qualified Data.Map as M -- | Auxiliary function to convert Plain block to Para. plainToPara :: Block -> Block @@ -267,9 +268,11 @@ writeOpenDocument opts (Pandoc meta blocks) = do [("style:name", "L" <> tshow n)] (vcat l) let listStyles = map listStyle (stListStyles s) let automaticStyles = vcat $ reverse $ styles ++ listStyles + let highlightingStyles = maybe mempty styleToOpenDocument (writerHighlightStyle opts) let context = defField "body" body . defField "toc" (writerTableOfContents opts) . defField "toc-depth" (tshow $ writerTOCDepth opts) + . defField "highlighting-styles" highlightingStyles . defField "automatic-styles" automaticStyles $ metadata return $ render colwidth $ @@ -917,3 +920,23 @@ withLangFromAttr (_,_,kvs) action = Left _ -> do report $ InvalidLang l action + +styleToOpenDocument :: Style -> Doc Text +styleToOpenDocument style = vcat (parStyle : 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) + tokStyles = tokenStyles style + tokFeatures 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 d0d284f5d..e7394c69e 100644 --- a/test/command/6792.md +++ b/test/command/6792.md @@ -21,6 +21,103 @@ <office:font-face-decls> <style:font-face style:name="Courier New" style:font-family-generic="modern" style:font-pitch="fixed" svg:font-family="'Courier New'" /> </office:font-face-decls> + <office:styles> + <w:style style:name="SourceCode" style:family="paragraph" style:class="text"> + </w:style> + <style:style style:name="KeywordTok" style:family="text"> + <style:text-properties fo:color="#007020" /> + </style:style> + <style:style style:name="DataTypeTok" style:family="text"> + <style:text-properties fo:color="#902000" /> + </style:style> + <style:style style:name="DecValTok" style:family="text"> + <style:text-properties fo:color="#40a070" /> + </style:style> + <style:style style:name="BaseNTok" style:family="text"> + <style:text-properties fo:color="#40a070" /> + </style:style> + <style:style style:name="FloatTok" style:family="text"> + <style:text-properties fo:color="#40a070" /> + </style:style> + <style:style style:name="ConstantTok" style:family="text"> + <style:text-properties fo:color="#880000" /> + </style:style> + <style:style style:name="CharTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="SpecialCharTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="StringTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="VerbatimStringTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="SpecialStringTok" style:family="text"> + <style:text-properties fo:color="#bb6688" /> + </style:style> + <style:style style:name="ImportTok" style:family="text"> + <style:text-properties fo:color="#008000" /> + </style:style> + <style:style style:name="CommentTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="DocumentationTok" style:family="text"> + <style:text-properties fo:color="#ba2121" /> + </style:style> + <style:style style:name="AnnotationTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="CommentVarTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="OtherTok" style:family="text"> + <style:text-properties fo:color="#007020" /> + </style:style> + <style:style style:name="FunctionTok" style:family="text"> + <style:text-properties fo:color="#06287e" /> + </style:style> + <style:style style:name="VariableTok" style:family="text"> + <style:text-properties fo:color="#19177c" /> + </style:style> + <style:style style:name="ControlFlowTok" style:family="text"> + <style:text-properties fo:color="#007020" /> + </style:style> + <style:style style:name="OperatorTok" style:family="text"> + <style:text-properties fo:color="#666666" /> + </style:style> + <style:style style:name="BuiltInTok" style:family="text"> + <style:text-properties fo:color="#008000" /> + </style:style> + <style:style style:name="ExtensionTok" style:family="text"> + <style:text-properties /> + </style:style> + <style:style style:name="PreprocessorTok" style:family="text"> + <style:text-properties fo:color="#bc7a00" /> + </style:style> + <style:style style:name="AttributeTok" style:family="text"> + <style:text-properties fo:color="#7d9029" /> + </style:style> + <style:style style:name="RegionMarkerTok" style:family="text"> + <style:text-properties /> + </style:style> + <style:style style:name="InformationTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="WarningTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="AlertTok" style:family="text"> + <style:text-properties fo:color="#ff0000" /> + </style:style> + <style:style style:name="ErrorTok" style:family="text"> + <style:text-properties fo:color="#ff0000" /> + </style:style> + <style:style style:name="NormalTok" style:family="text"> + <style:text-properties /> + </style:style> + </office:styles> <office:automatic-styles> <style:style style:name="fr2" style:family="graphic" style:parent-style-name="Formula"><style:graphic-properties style:vertical-pos="middle" style:vertical-rel="text" style:horizontal-pos="center" style:horizontal-rel="paragraph-content" style:wrap="none" /></style:style> <style:style style:name="fr1" style:family="graphic" style:parent-style-name="Formula"><style:graphic-properties style:vertical-pos="middle" style:vertical-rel="text" /></style:style> diff --git a/test/command/8256.md b/test/command/8256.md index 76398f607..4712acedd 100644 --- a/test/command/8256.md +++ b/test/command/8256.md @@ -15,6 +15,103 @@ Testing. <office:font-face-decls> <style:font-face style:name="Courier New" style:font-family-generic="modern" style:font-pitch="fixed" svg:font-family="'Courier New'" /> </office:font-face-decls> + <office:styles> + <w:style style:name="SourceCode" style:family="paragraph" style:class="text"> + </w:style> + <style:style style:name="KeywordTok" style:family="text"> + <style:text-properties fo:color="#007020" /> + </style:style> + <style:style style:name="DataTypeTok" style:family="text"> + <style:text-properties fo:color="#902000" /> + </style:style> + <style:style style:name="DecValTok" style:family="text"> + <style:text-properties fo:color="#40a070" /> + </style:style> + <style:style style:name="BaseNTok" style:family="text"> + <style:text-properties fo:color="#40a070" /> + </style:style> + <style:style style:name="FloatTok" style:family="text"> + <style:text-properties fo:color="#40a070" /> + </style:style> + <style:style style:name="ConstantTok" style:family="text"> + <style:text-properties fo:color="#880000" /> + </style:style> + <style:style style:name="CharTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="SpecialCharTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="StringTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="VerbatimStringTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="SpecialStringTok" style:family="text"> + <style:text-properties fo:color="#bb6688" /> + </style:style> + <style:style style:name="ImportTok" style:family="text"> + <style:text-properties fo:color="#008000" /> + </style:style> + <style:style style:name="CommentTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="DocumentationTok" style:family="text"> + <style:text-properties fo:color="#ba2121" /> + </style:style> + <style:style style:name="AnnotationTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="CommentVarTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="OtherTok" style:family="text"> + <style:text-properties fo:color="#007020" /> + </style:style> + <style:style style:name="FunctionTok" style:family="text"> + <style:text-properties fo:color="#06287e" /> + </style:style> + <style:style style:name="VariableTok" style:family="text"> + <style:text-properties fo:color="#19177c" /> + </style:style> + <style:style style:name="ControlFlowTok" style:family="text"> + <style:text-properties fo:color="#007020" /> + </style:style> + <style:style style:name="OperatorTok" style:family="text"> + <style:text-properties fo:color="#666666" /> + </style:style> + <style:style style:name="BuiltInTok" style:family="text"> + <style:text-properties fo:color="#008000" /> + </style:style> + <style:style style:name="ExtensionTok" style:family="text"> + <style:text-properties /> + </style:style> + <style:style style:name="PreprocessorTok" style:family="text"> + <style:text-properties fo:color="#bc7a00" /> + </style:style> + <style:style style:name="AttributeTok" style:family="text"> + <style:text-properties fo:color="#7d9029" /> + </style:style> + <style:style style:name="RegionMarkerTok" style:family="text"> + <style:text-properties /> + </style:style> + <style:style style:name="InformationTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="WarningTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="AlertTok" style:family="text"> + <style:text-properties fo:color="#ff0000" /> + </style:style> + <style:style style:name="ErrorTok" style:family="text"> + <style:text-properties fo:color="#ff0000" /> + </style:style> + <style:style style:name="NormalTok" style:family="text"> + <style:text-properties /> + </style:style> + </office:styles> <office:automatic-styles> <style:style style:name="T1" style:family="text"><style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic" /></style:style> <style:style style:name="fr2" style:family="graphic" style:parent-style-name="Formula"><style:graphic-properties style:vertical-pos="middle" style:vertical-rel="text" style:horizontal-pos="center" style:horizontal-rel="paragraph-content" style:wrap="none" /></style:style> diff --git a/test/writer.opendocument b/test/writer.opendocument index f10f3be2a..b693bca2b 100644 --- a/test/writer.opendocument +++ b/test/writer.opendocument @@ -3,6 +3,103 @@ <office:font-face-decls> <style:font-face style:name="Courier New" style:font-family-generic="modern" style:font-pitch="fixed" svg:font-family="'Courier New'" /> </office:font-face-decls> + <office:styles> + <w:style style:name="SourceCode" style:family="paragraph" style:class="text"> + </w:style> + <style:style style:name="KeywordTok" style:family="text"> + <style:text-properties fo:color="#007020" /> + </style:style> + <style:style style:name="DataTypeTok" style:family="text"> + <style:text-properties fo:color="#902000" /> + </style:style> + <style:style style:name="DecValTok" style:family="text"> + <style:text-properties fo:color="#40a070" /> + </style:style> + <style:style style:name="BaseNTok" style:family="text"> + <style:text-properties fo:color="#40a070" /> + </style:style> + <style:style style:name="FloatTok" style:family="text"> + <style:text-properties fo:color="#40a070" /> + </style:style> + <style:style style:name="ConstantTok" style:family="text"> + <style:text-properties fo:color="#880000" /> + </style:style> + <style:style style:name="CharTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="SpecialCharTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="StringTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="VerbatimStringTok" style:family="text"> + <style:text-properties fo:color="#4070a0" /> + </style:style> + <style:style style:name="SpecialStringTok" style:family="text"> + <style:text-properties fo:color="#bb6688" /> + </style:style> + <style:style style:name="ImportTok" style:family="text"> + <style:text-properties fo:color="#008000" /> + </style:style> + <style:style style:name="CommentTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="DocumentationTok" style:family="text"> + <style:text-properties fo:color="#ba2121" /> + </style:style> + <style:style style:name="AnnotationTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="CommentVarTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="OtherTok" style:family="text"> + <style:text-properties fo:color="#007020" /> + </style:style> + <style:style style:name="FunctionTok" style:family="text"> + <style:text-properties fo:color="#06287e" /> + </style:style> + <style:style style:name="VariableTok" style:family="text"> + <style:text-properties fo:color="#19177c" /> + </style:style> + <style:style style:name="ControlFlowTok" style:family="text"> + <style:text-properties fo:color="#007020" /> + </style:style> + <style:style style:name="OperatorTok" style:family="text"> + <style:text-properties fo:color="#666666" /> + </style:style> + <style:style style:name="BuiltInTok" style:family="text"> + <style:text-properties fo:color="#008000" /> + </style:style> + <style:style style:name="ExtensionTok" style:family="text"> + <style:text-properties /> + </style:style> + <style:style style:name="PreprocessorTok" style:family="text"> + <style:text-properties fo:color="#bc7a00" /> + </style:style> + <style:style style:name="AttributeTok" style:family="text"> + <style:text-properties fo:color="#7d9029" /> + </style:style> + <style:style style:name="RegionMarkerTok" style:family="text"> + <style:text-properties /> + </style:style> + <style:style style:name="InformationTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="WarningTok" style:family="text"> + <style:text-properties fo:color="#60a0b0" /> + </style:style> + <style:style style:name="AlertTok" style:family="text"> + <style:text-properties fo:color="#ff0000" /> + </style:style> + <style:style style:name="ErrorTok" style:family="text"> + <style:text-properties fo:color="#ff0000" /> + </style:style> + <style:style style:name="NormalTok" style:family="text"> + <style:text-properties /> + </style:style> + </office:styles> <office:automatic-styles> <text:list-style style:name="L1"> <text:list-level-style-number text:level="1" text:style-name="Numbering_20_Symbols" style:num-format="1" text:start-value="1" style:num-suffix="."> |
