From 49336ee6eeecc352e248d1262ea1b46070e00243 Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Tue, 2 May 2017 10:48:57 +0200 Subject: Add basic \textcolor support to LaTeX reader --- src/Text/Pandoc/Readers/LaTeX.hs | 8 ++++++++ test/command/textcolor.md | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/command/textcolor.md diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index a54238206..6252293d7 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -680,6 +680,8 @@ inlineCommands = M.fromList $ , ("nohyphens", tok) , ("textnhtt", ttfamily) , ("nhttfamily", ttfamily) + -- textcolor + , ("textcolor", textcolor) ] ++ map ignoreInlines -- these commands will be ignored unless --parse-raw is specified, -- in which case they will appear as raw latex blocks: @@ -756,6 +758,12 @@ dosiunitx = do emptyOr160 unit, unit] +textcolor :: PandocMonad m => LP m Inlines +textcolor = do + skipopts + color <- braced + spanWith ("",[],[("style","color: " ++ color)]) <$> tok + lit :: String -> LP m Inlines lit = pure . str diff --git a/test/command/textcolor.md b/test/command/textcolor.md new file mode 100644 index 000000000..7719a1c6b --- /dev/null +++ b/test/command/textcolor.md @@ -0,0 +1,13 @@ +``` +% pandoc -f latex -t native +\textcolor{red}{Hello World} +^D +[Para [Span ("",[],[("style","color: red")]) [Str "Hello",Space,Str "World"]]] +``` + +``` +% pandoc -f latex -t native +\textcolor{blue}{Hello \textbf{World}} +^D +[Para [Span ("",[],[("style","color: blue")]) [Str "Hello",Space,Strong [Str "World"]]]] +``` -- cgit v1.2.3