From 10a809f1260945b61cae6aa8912399ad83051552 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 9 May 2016 17:50:27 +0200 Subject: 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. --- src/Text/Pandoc/Readers/Org.hs | 13 +++++++++---- tests/Tests/Readers/Org.hs | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs index db1e70ea0..5a50a8f34 100644 --- a/src/Text/Pandoc/Readers/Org.hs +++ b/src/Text/Pandoc/Readers/Org.hs @@ -1581,8 +1581,8 @@ inlineLaTeX = try $ do parseAsMathMLSym :: String -> Maybe Inlines parseAsMathMLSym cs = B.str <$> MathMLEntityMap.getUnicode (clean cs) - -- dropWhileEnd would be nice here, but it's not available before base 4.5 - where clean = reverse . dropWhile (`elem` ("{}" :: String)) . reverse . drop 1 + -- drop initial backslash and any trailing "{}" + where clean = dropWhileEnd (`elem` ("{}" :: String)) . drop 1 state :: ParserState state = def{ stateOptions = def{ readerParseRaw = True }} @@ -1598,13 +1598,18 @@ inlineLaTeXCommand = try $ do rest <- getInput case runParser rawLaTeXInline def "source" rest of Right (RawInline _ cs) -> do - -- drop any trailing whitespace, those should not be part of the command - let cmdNoSpc = takeWhile (not . isSpace) $ cs + -- drop any trailing whitespace, those are not be part of the command as + -- far as org mode is concerned. + let cmdNoSpc = dropWhileEnd isSpace cs let len = length cmdNoSpc count len anyChar return cmdNoSpc _ -> mzero +-- Taken from Data.OldList. +dropWhileEnd :: (a -> Bool) -> [a] -> [a] +dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) [] + smart :: OrgParser (F Inlines) smart = do getOption readerSmart >>= guard diff --git a/tests/Tests/Readers/Org.hs b/tests/Tests/Readers/Org.hs index 3fab92e53..17682fb32 100644 --- a/tests/Tests/Readers/Org.hs +++ b/tests/Tests/Readers/Org.hs @@ -308,6 +308,10 @@ tests = "\\textit{Emphasised}" =?> para (emph "Emphasised") + , "Inline LaTeX command with spaces" =: + "\\emph{Emphasis mine}" =?> + para (emph "Emphasis mine") + , "Inline LaTeX math symbol" =: "\\tau" =?> para (emph "τ") -- cgit v1.2.3 From d32878b84b08f2f8e007b9b06c393a41e2ebe5fe Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 9 May 2016 18:53:29 +0200 Subject: Org writer: print empty table rows Empty table rows should not be dropped from the output, so row-height is always set to be at least 1. --- src/Text/Pandoc/Writers/Org.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs index 20086ed19..e57a6fc11 100644 --- a/src/Text/Pandoc/Writers/Org.hs +++ b/src/Text/Pandoc/Writers/Org.hs @@ -170,7 +170,7 @@ blockToOrg (Table caption' _ _ headers rows) = do map ((+2) . numChars) $ transpose (headers' : rawRows) -- FIXME: Org doesn't allow blocks with height more than 1. let hpipeBlocks blocks = hcat [beg, middle, end] - where h = maximum (map height blocks) + where h = maximum (1 : map height blocks) sep' = lblock 3 $ vcat (map text $ replicate h " | ") beg = lblock 2 $ vcat (map text $ replicate h "| ") end = lblock 2 $ vcat (map text $ replicate h " |") -- cgit v1.2.3