git.iko.soy/typeable/pandoc
on master help sign in
Add \colorbox support
181c56dMarc Schreiber
src/Text/Pandoc/Readers/LaTeX.hs+12−10
@@ -393,8 +393,9 @@ blockCommands = M.fromList $
393 , ("graphicspath", graphicsPath)
393 , ("graphicspath", graphicsPath)
394 -- hyperlink
394 -- hyperlink
395 , ("hypertarget", braced >> grouped block)
395 , ("hypertarget", braced >> grouped block)
396+ -- LaTeX colors
396− -- textcolor
397+ , ("textcolor", coloredBlock "color")
397− , ("textcolor", blockTextcolor)
398+ , ("colorbox", coloredBlock "background-color")
398 ] ++ map ignoreBlocks
399 ] ++ map ignoreBlocks
399 -- these commands will be ignored unless --parse-raw is specified,
400 -- these commands will be ignored unless --parse-raw is specified,
400 -- in which case they will appear as raw latex blocks
401 -- in which case they will appear as raw latex blocks
@@ -416,11 +417,11 @@ blockCommands = M.fromList $
416 , "pagebreak"
417 , "pagebreak"
417 ]
418 ]
418
419
419−blockTextcolor :: PandocMonad m => LP m Blocks
420+coloredBlock :: PandocMonad m => String -> LP m Blocks
420−blockTextcolor = do
421+coloredBlock stylename = do
421 skipopts
422 skipopts
422 color <- braced
423 color <- braced
423− let constructor = divWith ("",[],[("style","color: " ++ color)])
424+ let constructor = divWith ("",[],[("style",stylename ++ ": " ++ color)])
424 inlineContents <|> constructor <$> blockContents
425 inlineContents <|> constructor <$> blockContents
425 where inlineContents = do
426 where inlineContents = do
426 ils <- grouped inline
427 ils <- grouped inline
@@ -694,8 +695,9 @@ inlineCommands = M.fromList $
694 , ("nohyphens", tok)
695 , ("nohyphens", tok)
695 , ("textnhtt", ttfamily)
696 , ("textnhtt", ttfamily)
696 , ("nhttfamily", ttfamily)
697 , ("nhttfamily", ttfamily)
698+ -- LaTeX colors
697− -- textcolor
699+ , ("textcolor", coloredInline "color")
698− , ("textcolor", inlineTextcolor)
700+ , ("colorbox", coloredInline "background-color")
699 ] ++ map ignoreInlines
701 ] ++ map ignoreInlines
700 -- these commands will be ignored unless --parse-raw is specified,
702 -- these commands will be ignored unless --parse-raw is specified,
701 -- in which case they will appear as raw latex blocks:
703 -- in which case they will appear as raw latex blocks:
@@ -707,11 +709,11 @@ inlineCommands = M.fromList $
707 , "pagebreak"
709 , "pagebreak"
708 ]
710 ]
709
711
710−inlineTextcolor :: PandocMonad m => LP m Inlines
712+coloredInline :: PandocMonad m => String -> LP m Inlines
711−inlineTextcolor = do
713+coloredInline stylename = do
712 skipopts
714 skipopts
713 color <- braced
715 color <- braced
714− spanWith ("",[],[("style","color: " ++ color)]) <$> tok
716+ spanWith ("",[],[("style",stylename ++ ": " ++ color)]) <$> tok
715
717
716ttfamily :: PandocMonad m => LP m Inlines
718ttfamily :: PandocMonad m => LP m Inlines
717ttfamily = (code . stringify . toList) <$> tok
719ttfamily = (code . stringify . toList) <$> tok
test/command/latex-color.mdnew file+127
@@ -0,0 +1,127 @@
1+# `\textcolor{}{}`
2+
3+```
4+% pandoc -f latex -t native
5+Hello \textcolor{red}{World}
6+^D
7+[Para [Str "Hello",Space,Span ("",[],[("style","color: red")]) [Str "World"]]]
8+```
9+
10+```
11+% pandoc -f latex -t native
12+\textcolor{red}{Hello} World
13+^D
14+[Para [Span ("",[],[("style","color: red")]) [Str "Hello"],Space,Str "World"]]
15+```
16+
17+```
18+% pandoc -f latex -t native
19+Hello \textcolor{blue}{\textbf{World}}
20+^D
21+[Para [Str "Hello",Space,Span ("",[],[("style","color: blue")]) [Strong [Str "World"]]]]
22+```
23+
24+
25+```
26+% pandoc -f latex -t native
27+Hello \textcolor{blue}{\textbf{World}}.
28+^D
29+[Para [Str "Hello",Space,Span ("",[],[("style","color: blue")]) [Strong [Str "World"]],Str "."]]
30+```
31+
32+```
33+% pandoc -f latex -t native
34+\textcolor{orange}{
35+\begin{itemize}
36+ \item Item 1
37+ \item Item 2
38+\end{itemize}
39+}
40+^D
41+[Div ("",[],[("style","color: orange")])
42+ [BulletList
43+ [[Para [Str "Item",Space,Str "1"]]
44+ ,[Para [Str "Item",Space,Str "2"]]]]]
45+```
46+
47+```
48+% pandoc -f latex -t native
49+\textcolor{blue}{
50+\begin{itemize}
51+ \item Item 1
52+ \item Item 2
53+\end{itemize}
54+} some more text
55+^D
56+[Div ("",[],[("style","color: blue")])
57+ [BulletList
58+ [[Para [Str "Item",Space,Str "1"]]
59+ ,[Para [Str "Item",Space,Str "2"]]]]
60+,Para [Str "some",Space,Str "more",Space,Str "text"]]
61+```
62+
63+# `\colorbox{}{}`
64+
65+
66+```
67+% pandoc -f latex -t native
68+Hello \colorbox{red}{World}
69+^D
70+[Para [Str "Hello",Space,Span ("",[],[("style","background-color: red")]) [Str "World"]]]
71+```
72+
73+```
74+% pandoc -f latex -t native
75+\colorbox{red}{Hello} World
76+^D
77+[Para [Span ("",[],[("style","background-color: red")]) [Str "Hello"],Space,Str "World"]]
78+```
79+
80+```
81+% pandoc -f latex -t native
82+Hello \colorbox{blue}{\textbf{World}}
83+^D
84+[Para [Str "Hello",Space,Span ("",[],[("style","background-color: blue")]) [Strong [Str "World"]]]]
85+```
86+
87+```
88+% pandoc -f latex -t native
89+Hello \colorbox{blue}{\textbf{World}}.
90+^D
91+[Para [Str "Hello",Space,Span ("",[],[("style","background-color: blue")]) [Strong [Str "World"]],Str "."]]
92+```
93+
94+```
95+% pandoc -f latex -t native
96+\colorbox{orange}{
97+\begin{minipage}{\textwidth}
98+\begin{itemize}
99+ \item Item 1
100+ \item Item 2
101+\end{itemize}
102+\end{minipage}
103+}
104+^D
105+[Div ("",[],[("style","background-color: orange")])
106+ [BulletList
107+ [[Para [Str "Item",Space,Str "1"]]
108+ ,[Para [Str "Item",Space,Str "2"]]]]]
109+```
110+
111+```
112+% pandoc -f latex -t native
113+\colorbox{blue}{
114+\begin{minipage}{\textwidth}
115+\begin{itemize}
116+ \item Item 1
117+ \item Item 2
118+\end{itemize}
119+\end{minipage}
120+} some more text
121+^D
122+[Div ("",[],[("style","background-color: blue")])
123+ [BulletList
124+ [[Para [Str "Item",Space,Str "1"]]
125+ ,[Para [Str "Item",Space,Str "2"]]]]
126+,Para [Str "some",Space,Str "more",Space,Str "text"]]
127+```
test/command/textcolor.mddeleted−60
@@ -1,60 +0,0 @@
1−```
2−% pandoc -f latex -t native
3−Hello \textcolor{red}{World}
4−^D
5−[Para [Str "Hello",Space,Span ("",[],[("style","color: red")]) [Str "World"]]]
6−```
7−
8−```
9−% pandoc -f latex -t native
10−\textcolor{red}{Hello} World
11−^D
12−[Para [Span ("",[],[("style","color: red")]) [Str "Hello"],Space,Str "World"]]
13−```
14−
15−```
16−% pandoc -f latex -t native
17−Hello \textcolor{blue}{\textbf{World}}
18−^D
19−[Para [Str "Hello",Space,Span ("",[],[("style","color: blue")]) [Strong [Str "World"]]]]
20−```
21−
22−
23−```
24−% pandoc -f latex -t native
25−Hello \textcolor{blue}{\textbf{World}}.
26−^D
27−[Para [Str "Hello",Space,Span ("",[],[("style","color: blue")]) [Strong [Str "World"]],Str "."]]
28−```
29−
30−```
31−% pandoc -f latex -t native
32−\textcolor{orange}{
33−\begin{itemize}
34− \item Item 1
35− \item Item 2
36−\end{itemize}
37−}
38−^D
39−[Div ("",[],[("style","color: orange")])
40− [BulletList
41− [[Para [Str "Item",Space,Str "1"]]
42− ,[Para [Str "Item",Space,Str "2"]]]]]
43−```
44−
45−```
46−% pandoc -f latex -t native
47−\textcolor{blue}{
48−\begin{itemize}
49− \item Item 1
50− \item Item 2
51−\end{itemize}
52−} some more text
53−^D
54−[Div ("",[],[("style","color: blue")])
55− [BulletList
56− [[Para [Str "Item",Space,Str "1"]]
57− ,[Para [Str "Item",Space,Str "2"]]]]
58−,Para [Str "some",Space,Str "more",Space,Str "text"]]
59−```
60−