Merge branch 'schrieveslaach-textcolor-support'
This commit is contained in:
commit
fe0ffd272e
2 changed files with 147 additions and 0 deletions
|
@ -1311,6 +1311,9 @@ inlineCommands = M.fromList $
|
||||||
, ("nohyphens", tok)
|
, ("nohyphens", tok)
|
||||||
, ("textnhtt", ttfamily)
|
, ("textnhtt", ttfamily)
|
||||||
, ("nhttfamily", ttfamily)
|
, ("nhttfamily", ttfamily)
|
||||||
|
-- LaTeX colors
|
||||||
|
, ("textcolor", coloredInline "color")
|
||||||
|
, ("colorbox", coloredInline "background-color")
|
||||||
-- fontawesome
|
-- fontawesome
|
||||||
, ("faCheck", lit "\10003")
|
, ("faCheck", lit "\10003")
|
||||||
, ("faClose", lit "\10007")
|
, ("faClose", lit "\10007")
|
||||||
|
@ -1331,6 +1334,12 @@ ifstrequal = do
|
||||||
else getInput >>= setInput . (ifnotequal ++)
|
else getInput >>= setInput . (ifnotequal ++)
|
||||||
return mempty
|
return mempty
|
||||||
|
|
||||||
|
coloredInline :: PandocMonad m => String -> LP m Inlines
|
||||||
|
coloredInline stylename = do
|
||||||
|
skipopts
|
||||||
|
color <- braced
|
||||||
|
spanWith ("",[],[("style",stylename ++ ": " ++ toksToString color)]) <$> tok
|
||||||
|
|
||||||
ttfamily :: PandocMonad m => LP m Inlines
|
ttfamily :: PandocMonad m => LP m Inlines
|
||||||
ttfamily = (code . stringify . toList) <$> tok
|
ttfamily = (code . stringify . toList) <$> tok
|
||||||
|
|
||||||
|
@ -1709,6 +1718,9 @@ blockCommands = M.fromList $
|
||||||
, ("graphicspath", graphicsPath)
|
, ("graphicspath", graphicsPath)
|
||||||
-- hyperlink
|
-- hyperlink
|
||||||
, ("hypertarget", try $ braced >> grouped block)
|
, ("hypertarget", try $ braced >> grouped block)
|
||||||
|
-- LaTeX colors
|
||||||
|
, ("textcolor", coloredBlock "color")
|
||||||
|
, ("colorbox", coloredBlock "background-color")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -1872,6 +1884,14 @@ addImageCaption = walkM go
|
||||||
Nothing -> Image attr alt (src,tit)
|
Nothing -> Image attr alt (src,tit)
|
||||||
go x = return x
|
go x = return x
|
||||||
|
|
||||||
|
coloredBlock :: PandocMonad m => String -> LP m Blocks
|
||||||
|
coloredBlock stylename = try $ do
|
||||||
|
skipopts
|
||||||
|
color <- braced
|
||||||
|
notFollowedBy (grouped inline)
|
||||||
|
let constructor = divWith ("",[],[("style",stylename ++ ": " ++ toksToString color)])
|
||||||
|
constructor <$> grouped block
|
||||||
|
|
||||||
graphicsPath :: PandocMonad m => LP m Blocks
|
graphicsPath :: PandocMonad m => LP m Blocks
|
||||||
graphicsPath = do
|
graphicsPath = do
|
||||||
ps <- map toksToString <$> (bgroup *> manyTill braced egroup)
|
ps <- map toksToString <$> (bgroup *> manyTill braced egroup)
|
||||||
|
|
127
test/command/latex-color.md
Normal file
127
test/command/latex-color.md
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
# `\textcolor{}{}`
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
Hello \textcolor{red}{World}
|
||||||
|
^D
|
||||||
|
[Para [Str "Hello",Space,Span ("",[],[("style","color: red")]) [Str "World"]]]
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% 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
|
||||||
|
Hello \textcolor{blue}{\textbf{World}}
|
||||||
|
^D
|
||||||
|
[Para [Str "Hello",Space,Span ("",[],[("style","color: blue")]) [Strong [Str "World"]]]]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
Hello \textcolor{blue}{\textbf{World}}.
|
||||||
|
^D
|
||||||
|
[Para [Str "Hello",Space,Span ("",[],[("style","color: blue")]) [Strong [Str "World"]],Str "."]]
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
\textcolor{orange}{
|
||||||
|
\begin{itemize}
|
||||||
|
\item Item 1
|
||||||
|
\item Item 2
|
||||||
|
\end{itemize}
|
||||||
|
}
|
||||||
|
^D
|
||||||
|
[Div ("",[],[("style","color: orange")])
|
||||||
|
[BulletList
|
||||||
|
[[Para [Str "Item",Space,Str "1"]]
|
||||||
|
,[Para [Str "Item",Space,Str "2"]]]]]
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
\textcolor{blue}{
|
||||||
|
\begin{itemize}
|
||||||
|
\item Item 1
|
||||||
|
\item Item 2
|
||||||
|
\end{itemize}
|
||||||
|
} some more text
|
||||||
|
^D
|
||||||
|
[Div ("",[],[("style","color: blue")])
|
||||||
|
[BulletList
|
||||||
|
[[Para [Str "Item",Space,Str "1"]]
|
||||||
|
,[Para [Str "Item",Space,Str "2"]]]]
|
||||||
|
,Para [Str "some",Space,Str "more",Space,Str "text"]]
|
||||||
|
```
|
||||||
|
|
||||||
|
# `\colorbox{}{}`
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
Hello \colorbox{red}{World}
|
||||||
|
^D
|
||||||
|
[Para [Str "Hello",Space,Span ("",[],[("style","background-color: red")]) [Str "World"]]]
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
\colorbox{red}{Hello} World
|
||||||
|
^D
|
||||||
|
[Para [Span ("",[],[("style","background-color: red")]) [Str "Hello"],Space,Str "World"]]
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
Hello \colorbox{blue}{\textbf{World}}
|
||||||
|
^D
|
||||||
|
[Para [Str "Hello",Space,Span ("",[],[("style","background-color: blue")]) [Strong [Str "World"]]]]
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
Hello \colorbox{blue}{\textbf{World}}.
|
||||||
|
^D
|
||||||
|
[Para [Str "Hello",Space,Span ("",[],[("style","background-color: blue")]) [Strong [Str "World"]],Str "."]]
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
\colorbox{orange}{
|
||||||
|
\begin{minipage}{\textwidth}
|
||||||
|
\begin{itemize}
|
||||||
|
\item Item 1
|
||||||
|
\item Item 2
|
||||||
|
\end{itemize}
|
||||||
|
\end{minipage}
|
||||||
|
}
|
||||||
|
^D
|
||||||
|
[Div ("",[],[("style","background-color: orange")])
|
||||||
|
[BulletList
|
||||||
|
[[Para [Str "Item",Space,Str "1"]]
|
||||||
|
,[Para [Str "Item",Space,Str "2"]]]]]
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
% pandoc -f latex -t native
|
||||||
|
\colorbox{blue}{
|
||||||
|
\begin{minipage}{\textwidth}
|
||||||
|
\begin{itemize}
|
||||||
|
\item Item 1
|
||||||
|
\item Item 2
|
||||||
|
\end{itemize}
|
||||||
|
\end{minipage}
|
||||||
|
} some more text
|
||||||
|
^D
|
||||||
|
[Div ("",[],[("style","background-color: blue")])
|
||||||
|
[BulletList
|
||||||
|
[[Para [Str "Item",Space,Str "1"]]
|
||||||
|
,[Para [Str "Item",Space,Str "2"]]]]
|
||||||
|
,Para [Str "some",Space,Str "more",Space,Str "text"]]
|
||||||
|
```
|
Loading…
Add table
Reference in a new issue