git.iko.soy/typeable/pandoc
on master help sign in
Moved more from LaTeX reader to LaTeX.Parsing.
commit7faa9d90644b4ae151571e80734365bd96e857dc authorJohn MacFarlane <jgm@berkeley.edu> dateWed 22 Jul 2020, 12:05 (6 years ago) parent1e84178
2 files changed+67−63
src/Text/Pandoc/Readers/LaTeX.hs−63 src/Text/Pandoc/Readers/LaTeX/Parsing.hs+67
src/Text/Pandoc/Readers/LaTeX.hs−63
@@ -757,36 +757,6 @@ opt = bracketed inline <|> (str <$> rawopt)
757757paropt :: PandocMonad m => LP m Inlines
758758paropt = parenWrapped inline
759759
760−rawopt :: PandocMonad m => LP m Text
761−rawopt = try $ do
762− sp
763− inner <- untokenize <$> bracketedToks
764− sp
765− return $ "[" <> inner <> "]"
766−
767−skipopts :: PandocMonad m => LP m ()
768−skipopts = skipMany (void overlaySpecification <|> void rawopt)
769−
770−-- opts in angle brackets are used in beamer
771−overlaySpecification :: PandocMonad m => LP m Text
772−overlaySpecification = try $ do
773− symbol '<'
774− t <- untokenize <$> manyTill overlayTok (symbol '>')
775− -- see issue #3368
776− guard $ not (T.all isLetter t) ||
777− t `elem` ["beamer","presentation", "trans",
778− "handout","article", "second"]
779− return $ "<" <> t <> ">"
780−
781−overlayTok :: PandocMonad m => LP m Tok
782−overlayTok =
783− satisfyTok (\t ->
784− case t of
785− Tok _ Word _ -> True
786− Tok _ Spaces _ -> True
787− Tok _ Symbol c -> c `elem` ["-","+","@","|",":",","]
788− _ -> False)
789−
790760inBrackets :: Inlines -> Inlines
791761inBrackets x = str "[" <> x <> str "]"
792762
@@ -1309,39 +1279,6 @@ processHBox = walk convert
13091279 convert LineBreak = Str ""
13101280 convert x = x
13111281
1312−getRawCommand :: PandocMonad m => Text -> Text -> LP m Text
1313−getRawCommand name txt = do
1314− (_, rawargs) <- withRaw $
1315− case name of
1316− "write" -> do
1317− void $ satisfyTok isWordTok -- digits
1318− void braced
1319− "titleformat" -> do
1320− void braced
1321− skipopts
1322− void $ count 4 braced
1323− "def" ->
1324− void $ manyTill anyTok braced
1325− _ | isFontSizeCommand name -> return ()
1326− | otherwise -> do
1327− skipopts
1328− option "" (try dimenarg)
1329− void $ many braced
1330− return $ txt <> untokenize rawargs
1331−
1332−isFontSizeCommand :: Text -> Bool
1333−isFontSizeCommand "tiny" = True
1334−isFontSizeCommand "scriptsize" = True
1335−isFontSizeCommand "footnotesize" = True
1336−isFontSizeCommand "small" = True
1337−isFontSizeCommand "normalsize" = True
1338−isFontSizeCommand "large" = True
1339−isFontSizeCommand "Large" = True
1340−isFontSizeCommand "LARGE" = True
1341−isFontSizeCommand "huge" = True
1342−isFontSizeCommand "Huge" = True
1343−isFontSizeCommand _ = False
1344−
13451282isBlockCommand :: Text -> Bool
13461283isBlockCommand s =
13471284 s `M.member` (blockCommands :: M.Map Text (LP PandocPure Blocks))
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+67
@@ -71,6 +71,10 @@ module Text.Pandoc.Readers.LaTeX.Parsing
7171 , verbEnv
7272 , begin_
7373 , end_
74+ , getRawCommand
75+ , skipopts
76+ , rawopt
77+ , overlaySpecification
7478 ) where
7579
7680import Control.Applicative (many, (<|>))
@@ -759,3 +763,66 @@ end_ t = try (do
759763 txt <- untokenize <$> braced
760764 guard $ t == txt) <?> ("\\end{" ++ T.unpack t ++ "}")
761765
766+getRawCommand :: PandocMonad m => Text -> Text -> LP m Text
767+getRawCommand name txt = do
768+ (_, rawargs) <- withRaw $
769+ case name of
770+ "write" -> do
771+ void $ satisfyTok isWordTok -- digits
772+ void braced
773+ "titleformat" -> do
774+ void braced
775+ skipopts
776+ void $ count 4 braced
777+ "def" ->
778+ void $ manyTill anyTok braced
779+ _ | isFontSizeCommand name -> return ()
780+ | otherwise -> do
781+ skipopts
782+ option "" (try dimenarg)
783+ void $ many braced
784+ return $ txt <> untokenize rawargs
785+
786+skipopts :: PandocMonad m => LP m ()
787+skipopts = skipMany (void overlaySpecification <|> void rawopt)
788+
789+-- opts in angle brackets are used in beamer
790+overlaySpecification :: PandocMonad m => LP m Text
791+overlaySpecification = try $ do
792+ symbol '<'
793+ t <- untokenize <$> manyTill overlayTok (symbol '>')
794+ -- see issue #3368
795+ guard $ not (T.all isLetter t) ||
796+ t `elem` ["beamer","presentation", "trans",
797+ "handout","article", "second"]
798+ return $ "<" <> t <> ">"
799+
800+overlayTok :: PandocMonad m => LP m Tok
801+overlayTok =
802+ satisfyTok (\t ->
803+ case t of
804+ Tok _ Word _ -> True
805+ Tok _ Spaces _ -> True
806+ Tok _ Symbol c -> c `elem` ["-","+","@","|",":",","]
807+ _ -> False)
808+
809+rawopt :: PandocMonad m => LP m Text
810+rawopt = try $ do
811+ sp
812+ inner <- untokenize <$> bracketedToks
813+ sp
814+ return $ "[" <> inner <> "]"
815+
816+isFontSizeCommand :: Text -> Bool
817+isFontSizeCommand "tiny" = True
818+isFontSizeCommand "scriptsize" = True
819+isFontSizeCommand "footnotesize" = True
820+isFontSizeCommand "small" = True
821+isFontSizeCommand "normalsize" = True
822+isFontSizeCommand "large" = True
823+isFontSizeCommand "Large" = True
824+isFontSizeCommand "LARGE" = True
825+isFontSizeCommand "huge" = True
826+isFontSizeCommand "Huge" = True
827+isFontSizeCommand _ = False
828+