git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2907 from tarleb/org-fixes

Org fixes (reader and writer)

commitfd9ec835ec1447fb6040ee63a1fa8ee13b19d555 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 9 May 2016, 10:17 (10 years ago) parentc1b19b1d32878b
3 files changed+14−5
src/Text/Pandoc/Readers/Org.hs+9−4 src/Text/Pandoc/Writers/Org.hs+1−1 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
src/Text/Pandoc/Writers/Org.hs+1−1
@@ -170,7 +170,7 @@ blockToOrg (Table caption' _ _ headers rows) = do
170170 map ((+2) . numChars) $ transpose (headers' : rawRows)
171171 -- FIXME: Org doesn't allow blocks with height more than 1.
172172 let hpipeBlocks blocks = hcat [beg, middle, end]
173− where h = maximum (map height blocks)
173+ where h = maximum (1 : map height blocks)
174174 sep' = lblock 3 $ vcat (map text $ replicate h " | ")
175175 beg = lblock 2 $ vcat (map text $ replicate h "| ")
176176 end = lblock 2 $ vcat (map text $ replicate h " |")
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 "τ")