diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2020-02-08 21:03:48 +0100 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2020-02-08 21:07:57 +0100 |
commit | 689cb7128f09719955b801494e946b27da6e9adc (patch) | |
tree | 62772db1c15ec099921858b2e127536464bce1c6 /src/Text/Pandoc | |
parent | 5f0bd5222169129cc3474d0284a0f1ecb702a770 (diff) | |
download | pandoc-689cb7128f09719955b801494e946b27da6e9adc.tar.gz |
Org reader: simplify parsing of sub- and superscripts
Speeds up parsing of single-word, markup-less sub- and superscripts.
Fixes: #6127
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/Org/Inlines.hs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Inlines.hs b/src/Text/Pandoc/Readers/Org/Inlines.hs index d8204d38f..103dfc86a 100644 --- a/src/Text/Pandoc/Readers/Org/Inlines.hs +++ b/src/Text/Pandoc/Readers/Org/Inlines.hs @@ -40,7 +40,6 @@ import Data.List (intersperse) import qualified Data.Map as M import Data.Text (Text) import qualified Data.Text as T -import Data.Maybe (fromMaybe) -- -- Functions acting on the parser state @@ -761,7 +760,7 @@ afterEmphasisPreChar :: PandocMonad m => OrgParser m Bool afterEmphasisPreChar = do pos <- getPosition lastPrePos <- orgStateLastPreCharPos <$> getState - return . fromMaybe True $ (== pos) <$> lastPrePos + return $ maybe True (== pos) lastPrePos -- | Whether the parser is right after a forbidden border char notAfterForbiddenBorderChar :: PandocMonad m => OrgParser m Bool @@ -773,20 +772,21 @@ notAfterForbiddenBorderChar = do -- | Read a sub- or superscript expression subOrSuperExpr :: PandocMonad m => OrgParser m (F Inlines) subOrSuperExpr = try $ - choice [ charsInBalanced '{' '}' (noneOf "\n\r") - , enclosing ('(', ')') <$> charsInBalanced '(' ')' (noneOf "\n\r") - , simpleSubOrSuperText - ] >>= parseFromString (mconcat <$> many inline) + simpleSubOrSuperText <|> + (choice [ charsInBalanced '{' '}' (noneOf "\n\r") + , enclosing ('(', ')') <$> charsInBalanced '(' ')' (noneOf "\n\r") + ] >>= parseFromString (mconcat <$> many inline)) where enclosing (left, right) s = T.cons left $ T.snoc s right -simpleSubOrSuperText :: PandocMonad m => OrgParser m Text +simpleSubOrSuperText :: PandocMonad m => OrgParser m (F Inlines) simpleSubOrSuperText = try $ do state <- getState guard . exportSubSuperscripts . orgStateExportSettings $ state - choice [ textStr "*" - , mappend <$> option "" (T.singleton <$> oneOf "+-") - <*> many1Char alphaNum - ] + return . B.str <$> + choice [ textStr "*" + , mappend <$> option "" (T.singleton <$> oneOf "+-") + <*> many1Char alphaNum + ] inlineLaTeX :: PandocMonad m => OrgParser m (F Inlines) inlineLaTeX = try $ do |