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 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Text') 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 -- cgit v1.2.3 From d9439808f2fe226aad027c8c9d0a38217a1e8c34 Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Wed, 3 May 2017 12:00:30 +0200 Subject: Add block version of \textcolor --- src/Text/Pandoc/Readers/LaTeX.hs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 6252293d7..1c1aa4c62 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -393,6 +393,8 @@ blockCommands = M.fromList $ , ("graphicspath", graphicsPath) -- hyperlink , ("hypertarget", braced >> grouped block) + -- textcolor + , ("textcolor", blockTextcolor) ] ++ map ignoreBlocks -- these commands will be ignored unless --parse-raw is specified, -- in which case they will appear as raw latex blocks @@ -414,6 +416,12 @@ blockCommands = M.fromList $ , "pagebreak" ] +blockTextcolor :: PandocMonad m => LP m Blocks +blockTextcolor = do + skipopts + color <- braced + return <$> divWith ("",[],[("style","color: " ++ color)]) $ block + graphicsPath :: PandocMonad m => LP m Blocks graphicsPath = do ps <- bgroup *> (manyTill braced egroup) @@ -681,7 +689,7 @@ inlineCommands = M.fromList $ , ("textnhtt", ttfamily) , ("nhttfamily", ttfamily) -- textcolor - , ("textcolor", textcolor) + , ("textcolor", inlineTextcolor) ] ++ map ignoreInlines -- these commands will be ignored unless --parse-raw is specified, -- in which case they will appear as raw latex blocks: @@ -693,6 +701,12 @@ inlineCommands = M.fromList $ , "pagebreak" ] +inlineTextcolor :: PandocMonad m => LP m Inlines +inlineTextcolor = do + skipopts + color <- braced + spanWith ("",[],[("style","color: " ++ color)]) <$> tok + ttfamily :: PandocMonad m => LP m Inlines ttfamily = (code . stringify . toList) <$> tok @@ -758,12 +772,6 @@ 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 -- cgit v1.2.3 From 1728d4e60983e050be4bfb5b8c2e6065b4dd198a Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Wed, 3 May 2017 13:39:38 +0200 Subject: \textcolor works as inline and block command --- src/Text/Pandoc/Readers/LaTeX.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 1c1aa4c62..58ed97b04 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -420,7 +420,7 @@ blockTextcolor :: PandocMonad m => LP m Blocks blockTextcolor = do skipopts color <- braced - return <$> divWith ("",[],[("style","color: " ++ color)]) $ block + divWith ("",[],[("style","color: " ++ color)]) <$> grouped block graphicsPath :: PandocMonad m => LP m Blocks graphicsPath = do -- cgit v1.2.3 From 4ed6d9165672917cb9450578c8f7d84121ecfc24 Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Thu, 4 May 2017 16:48:27 +0200 Subject: \textcolor will be parse as span at the beginning of a paragraph --- src/Text/Pandoc/Readers/LaTeX.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 58ed97b04..a34be46e2 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -420,7 +420,7 @@ blockTextcolor :: PandocMonad m => LP m Blocks blockTextcolor = do skipopts color <- braced - divWith ("",[],[("style","color: " ++ color)]) <$> grouped block + divWith ("",[],[("style","color: " ++ color)]) <$> grouped block <* notFollowedBy inline graphicsPath :: PandocMonad m => LP m Blocks graphicsPath = do -- cgit v1.2.3 From 29a4bdc68131d3925a55e0428b35c6a4f75f86e0 Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Tue, 23 May 2017 17:31:42 -0300 Subject: Add suggestions of @jgm: parse bracketed stuff as inlines --- src/Text/Pandoc/Readers/LaTeX.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index a34be46e2..6b44df468 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -418,9 +418,15 @@ blockCommands = M.fromList $ blockTextcolor :: PandocMonad m => LP m Blocks blockTextcolor = do - skipopts - color <- braced - divWith ("",[],[("style","color: " ++ color)]) <$> grouped block <* notFollowedBy inline + skipopts + color <- braced + let constructor = divWith ("",[],[("style","color: " ++ color)]) + inlineContents <|> constructor <$> blockContents + where inlineContents = do + ils <- grouped inline + rest <- inlines + return (para (ils <> rest)) + blockContents = grouped block graphicsPath :: PandocMonad m => LP m Blocks graphicsPath = do -- cgit v1.2.3 From 181c56d4003aa83abed23b95a452c4890aa3797c Mon Sep 17 00:00:00 2001 From: Marc Schreiber Date: Thu, 1 Jun 2017 09:09:27 +0200 Subject: Add \colorbox support --- src/Text/Pandoc/Readers/LaTeX.hs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 6b44df468..1d13f7107 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -393,8 +393,9 @@ blockCommands = M.fromList $ , ("graphicspath", graphicsPath) -- hyperlink , ("hypertarget", braced >> grouped block) - -- textcolor - , ("textcolor", blockTextcolor) + -- LaTeX colors + , ("textcolor", coloredBlock "color") + , ("colorbox", coloredBlock "background-color") ] ++ map ignoreBlocks -- these commands will be ignored unless --parse-raw is specified, -- in which case they will appear as raw latex blocks @@ -416,11 +417,11 @@ blockCommands = M.fromList $ , "pagebreak" ] -blockTextcolor :: PandocMonad m => LP m Blocks -blockTextcolor = do +coloredBlock :: PandocMonad m => String -> LP m Blocks +coloredBlock stylename = do skipopts color <- braced - let constructor = divWith ("",[],[("style","color: " ++ color)]) + let constructor = divWith ("",[],[("style",stylename ++ ": " ++ color)]) inlineContents <|> constructor <$> blockContents where inlineContents = do ils <- grouped inline @@ -694,8 +695,9 @@ inlineCommands = M.fromList $ , ("nohyphens", tok) , ("textnhtt", ttfamily) , ("nhttfamily", ttfamily) - -- textcolor - , ("textcolor", inlineTextcolor) + -- LaTeX colors + , ("textcolor", coloredInline "color") + , ("colorbox", coloredInline "background-color") ] ++ map ignoreInlines -- these commands will be ignored unless --parse-raw is specified, -- in which case they will appear as raw latex blocks: @@ -707,11 +709,11 @@ inlineCommands = M.fromList $ , "pagebreak" ] -inlineTextcolor :: PandocMonad m => LP m Inlines -inlineTextcolor = do +coloredInline :: PandocMonad m => String -> LP m Inlines +coloredInline stylename = do skipopts color <- braced - spanWith ("",[],[("style","color: " ++ color)]) <$> tok + spanWith ("",[],[("style",stylename ++ ": " ++ color)]) <$> tok ttfamily :: PandocMonad m => LP m Inlines ttfamily = (code . stringify . toList) <$> tok -- cgit v1.2.3