diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-04-25 17:36:01 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-04-25 17:39:49 -0700 |
commit | a9344bf308afa4d2197582aff8045de56e24c7aa (patch) | |
tree | f4cf50bbde8abfa93c5bb3cd9b19cf7fb13b0f85 | |
parent | 16f36eee43c9401612aa647eff4f041c4270e969 (diff) | |
download | pandoc-a9344bf308afa4d2197582aff8045de56e24c7aa.tar.gz |
LaTeX reader: support `\MakeUppercase`, `\MakeLowercase'.
Also `\MakeTextUppercase`, `\MakeTextLowercase` from textcase
and `\uppercase`, `\lowercase`.
We don't mimic exactly the quirky semantic differences between
these commands, but just uppercase/lowercase regular strings within
them. We leave commands and code alone.
Closes #4595.
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index e1497dfb1..6254ce3f3 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -48,7 +48,7 @@ import Control.Applicative (many, optional, (<|>)) import Control.Monad import Control.Monad.Except (throwError) import Control.Monad.Trans (lift) -import Data.Char (chr, isAlphaNum, isDigit, isLetter, ord, toLower) +import Data.Char (chr, isAlphaNum, isDigit, isLetter, ord, toLower, toUpper) import Data.Default import Data.List (intercalate, isPrefixOf) import qualified Data.Map as M @@ -1315,6 +1315,12 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList , ("slshape", extractSpaces emph <$> inlines) , ("scshape", extractSpaces smallcaps <$> inlines) , ("bfseries", extractSpaces strong <$> inlines) + , ("MakeUppercase", makeUppercase <$> tok) + , ("MakeTextUppercase", makeUppercase <$> tok) -- textcase + , ("uppercase", makeUppercase <$> tok) + , ("MakeLowercase", makeLowercase <$> tok) + , ("MakeTextLowercase", makeLowercase <$> tok) + , ("lowercase", makeLowercase <$> tok) , ("/", pure mempty) -- italic correction , ("aa", lit "å") , ("AA", lit "Å") @@ -1515,6 +1521,16 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList , ("foreignlanguage", foreignlanguage) ] +makeUppercase :: Inlines -> Inlines +makeUppercase = fromList . walk (alterStr (map toUpper)) . toList + +makeLowercase :: Inlines -> Inlines +makeLowercase = fromList . walk (alterStr (map toLower)) . toList + +alterStr :: (String -> String) -> Inline -> Inline +alterStr f (Str xs) = Str (f xs) +alterStr _ x = x + foreignlanguage :: PandocMonad m => LP m Inlines foreignlanguage = do babelLang <- T.unpack . untokenize <$> braced |