git.iko.soy/typeable/pandoc
on master help sign in
Org reader: fix inline-LaTeX regression

The last fix for whitespace handling of inline LaTeX commands was incorrect, preventing correct recognition of inline LaTeX commands which contain spaces. This fix ensures that only trailing whitespace is cut off.

commit10a809f1260945b61cae6aa8912399ad83051552 authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 9 May 2016, 17:50 (10 years ago) parent21d1a3b
2 files changed+13−4
src/Text/Pandoc/Readers/Org.hs+9−4 tests/Tests/Readers/Org.hs+4
src/Text/Pandoc/Readers/Org.hs+9−4
@@ -1581,8 +1581,8 @@ inlineLaTeX = try $ do
15811581
15821582 parseAsMathMLSym :: String -> Maybe Inlines
15831583 parseAsMathMLSym cs = B.str <$> MathMLEntityMap.getUnicode (clean cs)
1584− -- dropWhileEnd would be nice here, but it's not available before base 4.5
1585− where clean = reverse . dropWhile (`elem` ("{}" :: String)) . reverse . drop 1
1584+ -- drop initial backslash and any trailing "{}"
1585+ where clean = dropWhileEnd (`elem` ("{}" :: String)) . drop 1
15861586
15871587 state :: ParserState
15881588 state = def{ stateOptions = def{ readerParseRaw = True }}
@@ -1598,13 +1598,18 @@ inlineLaTeXCommand = try $ do
15981598 rest <- getInput
15991599 case runParser rawLaTeXInline def "source" rest of
16001600 Right (RawInline _ cs) -> do
1601− -- drop any trailing whitespace, those should not be part of the command
1602− let cmdNoSpc = takeWhile (not . isSpace) $ cs
1601+ -- drop any trailing whitespace, those are not be part of the command as
1602+ -- far as org mode is concerned.
1603+ let cmdNoSpc = dropWhileEnd isSpace cs
16031604 let len = length cmdNoSpc
16041605 count len anyChar
16051606 return cmdNoSpc
16061607 _ -> mzero
16071608
1609+-- Taken from Data.OldList.
1610+dropWhileEnd :: (a -> Bool) -> [a] -> [a]
1611+dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) []
1612+
16081613smart :: OrgParser (F Inlines)
16091614smart = do
16101615 getOption readerSmart >>= guard
tests/Tests/Readers/Org.hs+4
@@ -308,6 +308,10 @@ tests =
308308 "\\textit{Emphasised}" =?>
309309 para (emph "Emphasised")
310310
311+ , "Inline LaTeX command with spaces" =:
312+ "\\emph{Emphasis mine}" =?>
313+ para (emph "Emphasis mine")
314+
311315 , "Inline LaTeX math symbol" =:
312316 "\\tau" =?>
313317 para (emph "τ")