git.iko.soy/typeable/pandoc
on master help sign in
Merge branch 'schrieveslaach-textcolor-support'
commitfe0ffd272ea14b3f1a40c891403ef03f09f6294f authorJohn MacFarlane <jgm@berkeley.edu> dateTue 25 Jul 2017, 11:42 (9 years ago) parent862d92f2b039ac
2 files changed+147
src/Text/Pandoc/Readers/LaTeX.hs+20 test/command/latex-color.md+127
src/Text/Pandoc/Readers/LaTeX.hs+20
@@ -1311,6 +1311,9 @@ inlineCommands = M.fromList $
13111311 , ("nohyphens", tok)
13121312 , ("textnhtt", ttfamily)
13131313 , ("nhttfamily", ttfamily)
1314+ -- LaTeX colors
1315+ , ("textcolor", coloredInline "color")
1316+ , ("colorbox", coloredInline "background-color")
13141317 -- fontawesome
13151318 , ("faCheck", lit "\10003")
13161319 , ("faClose", lit "\10007")
@@ -1331,6 +1334,12 @@ ifstrequal = do
13311334 else getInput >>= setInput . (ifnotequal ++)
13321335 return mempty
13331336
1337+coloredInline :: PandocMonad m => String -> LP m Inlines
1338+coloredInline stylename = do
1339+ skipopts
1340+ color <- braced
1341+ spanWith ("",[],[("style",stylename ++ ": " ++ toksToString color)]) <$> tok
1342+
13341343ttfamily :: PandocMonad m => LP m Inlines
13351344ttfamily = (code . stringify . toList) <$> tok
13361345
@@ -1709,6 +1718,9 @@ blockCommands = M.fromList $
17091718 , ("graphicspath", graphicsPath)
17101719 -- hyperlink
17111720 , ("hypertarget", try $ braced >> grouped block)
1721+ -- LaTeX colors
1722+ , ("textcolor", coloredBlock "color")
1723+ , ("colorbox", coloredBlock "background-color")
17121724 ]
17131725
17141726
@@ -1872,6 +1884,14 @@ addImageCaption = walkM go
18721884 Nothing -> Image attr alt (src,tit)
18731885 go x = return x
18741886
1887+coloredBlock :: PandocMonad m => String -> LP m Blocks
1888+coloredBlock stylename = try $ do
1889+ skipopts
1890+ color <- braced
1891+ notFollowedBy (grouped inline)
1892+ let constructor = divWith ("",[],[("style",stylename ++ ": " ++ toksToString color)])
1893+ constructor <$> grouped block
1894+
18751895graphicsPath :: PandocMonad m => LP m Blocks
18761896graphicsPath = do
18771897 ps <- map toksToString <$> (bgroup *> manyTill braced egroup)
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+```