diff options
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 30 | ||||
-rw-r--r-- | test/Tests/Readers/LaTeX.hs | 23 |
2 files changed, 52 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 3292550b2..ac471bdb1 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -44,7 +44,7 @@ import Control.Applicative (many, optional, (<|>)) import Control.Monad import Control.Monad.Except (throwError) import Control.Monad.Trans (lift) -import Data.Char (chr, isAlphaNum, isLetter, ord, isDigit) +import Data.Char (chr, isAlphaNum, isLetter, ord, isDigit, toLower) import Data.Default import Data.Text (Text) import qualified Data.Text as T @@ -1445,8 +1445,36 @@ inlineCommands = M.fromList $ , ("toggletrue", braced >>= setToggle True) , ("togglefalse", braced >>= setToggle False) , ("iftoggle", try $ ifToggle >> inline) + -- biblatex misc + , ("RN", romanNumeralUpper) + , ("Rn", romanNumeralLower) ] +romanNumeralUpper :: (PandocMonad m) => LP m Inlines +romanNumeralUpper = + str . toRomanNumeral <$> romanNumeralArg + +romanNumeralLower :: (PandocMonad m) => LP m Inlines +romanNumeralLower = + str . map toLower . toRomanNumeral <$> romanNumeralArg + +romanNumeralArg :: (PandocMonad m) => LP m Int +romanNumeralArg = spaces *> (parser <|> inBraces) + where + inBraces = do + symbol '{' + spaces + res <- parser + spaces + symbol '}' + return res + parser = do + Tok _ Word s <- satisfyTok isWordTok + let (digits, rest) = T.span isDigit s + unless (T.null rest) $ + fail "Non-digits in argument to \\Rn or \\RN" + safeRead $ T.unpack digits + newToggle :: (Monoid a, PandocMonad m) => [Tok] -> LP m a newToggle name = do updateState $ \st -> diff --git a/test/Tests/Readers/LaTeX.hs b/test/Tests/Readers/LaTeX.hs index b07eb875a..4effe26e8 100644 --- a/test/Tests/Readers/LaTeX.hs +++ b/test/Tests/Readers/LaTeX.hs @@ -143,6 +143,29 @@ tests = [ testGroup "basic" "hello\\pfbreak*{}goodbye" =?> para (str "hello") <> horizontalRule <> para (str "goodbye") ] + , testGroup "biblatex roman numerals" + [ "upper" =: + "number \\RN{12}" =?> + para (str "number" <> space <> str "XII") + , "lower" =: + "number \\Rn{29}" =?> + para (str "number" <> space <> str "xxix") + , "leading zero" =: + "\\Rn{014}" =?> + para (str "xiv") + , "surrounding spaces" =: + "number \\Rn{ 41 }" =?> + para (str "number" <> space <> str "xli") + , "zero" =: + "\\RN{0}" =?> + para (str "") + , "space then unbraced argument" =: + "\\RN 7 ok" =?> + para (str "VII" <> space <> str "ok") + , "space before braced argument" =: + "\\Rn {13}ok" =?> + para (str "xiiiok") + ] ] baseCitation :: Citation |