git.iko.soy/typeable/pandoc
on master help sign in
Roff readers: better parsing of groups.

We now allow groups where the closing `\\}` isn't at the beginning of a line. Closes #5410.

commite4cca4cf67af31ce574ef2871d08f0719d4a50a5 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 4 Sep 2019, 09:24 (7 years ago) parent0a3cc0b
3 files changed+13−10
src/Text/Pandoc/Readers/Roff.hs+5−9 test/Tests/Readers/Man.hs+1−1 test/command/5410.md+7
src/Text/Pandoc/Readers/Roff.hs+5−9
@@ -33,7 +33,7 @@ import Control.Monad.Except (throwError)
3333import Text.Pandoc.Class
3434 (getResourcePath, readFileFromDirs, PandocMonad(..), report)
3535import Data.Char (isLower, toLower, toUpper, chr,
36− isAscii, isAlphaNum, isSpace)
36+ isAscii, isAlphaNum)
3737import Data.Default (Default)
3838import qualified Data.Map as M
3939import Data.List (intercalate)
@@ -130,7 +130,7 @@ type RoffLexer m = ParserT [Char] RoffState m
130130--
131131
132132eofline :: Stream s m Char => ParsecT s u m ()
133−eofline = void newline <|> eof
133+eofline = void newline <|> eof <|> () <$ lookAhead (string "\\}")
134134
135135spacetab :: Stream s m Char => ParsecT s u m Char
136136spacetab = char ' ' <|> char '\t'
@@ -144,7 +144,7 @@ combiningAccentsMap =
144144 M.fromList $ map (\(x,y) -> (y,x)) combiningAccents
145145
146146escape :: PandocMonad m => RoffLexer m [LinePart]
147−escape = do
147+escape = try $ do
148148 backslash
149149 escapeGlyph <|> escapeNormal
150150
@@ -193,7 +193,7 @@ readUnicodeChar _ = Nothing
193193
194194escapeNormal :: PandocMonad m => RoffLexer m [LinePart]
195195escapeNormal = do
196− c <- anyChar
196+ c <- noneOf "{}"
197197 optional expandString
198198 case c of
199199 ' ' -> return [RoffStr " "]
@@ -256,9 +256,7 @@ escapeNormal = do
256256 'w' -> escIgnore 'w' [quoteArg]
257257 'x' -> escIgnore 'x' [quoteArg]
258258 'z' -> escIgnore 'z' [count 1 anyChar]
259− '{' -> return mempty
260259 '|' -> return [RoffStr "\x2006"] --1/6 em space
261− '}' -> return mempty
262260 '~' -> return [RoffStr "\160"] -- nonbreaking space
263261 '\\' -> do
264262 mode <- roffMode <$> getState
@@ -350,7 +348,7 @@ lexMacro = do
350348 guard $ sourceColumn pos == 1 || afterConditional st
351349 char '.' <|> char '\''
352350 skipMany spacetab
353− macroName <- many (satisfy (not . isSpace))
351+ macroName <- many (satisfy isAlphaNum)
354352 case macroName of
355353 "nop" -> return mempty
356354 "ie" -> lexConditional "ie"
@@ -361,8 +359,6 @@ lexMacro = do
361359 args <- lexArgs
362360 case macroName of
363361 "" -> return mempty
364− "\\\"" -> return mempty
365− "\\#" -> return mempty
366362 "TS" -> lexTable pos
367363 "de" -> lexMacroDef args
368364 "de1" -> lexMacroDef args
test/Tests/Readers/Man.hs+1−1
@@ -74,7 +74,7 @@ tests = [
7474 =?> para (text "hi " <> emph (text "there " <> strong (text "bold")) <>
7575 text " ok")
7676 , "skip" =:
77− "a\\%\\{\\}\\\n\\:b\\0"
77+ "a\\%\\\n\\:b\\0"
7878 =?> (para $ str "ab\8199")
7979 , "replace" =:
8080 "\\-\\ \\\\\\[lq]\\[rq]\\[em]\\[en]\\*(lq\\*(rq"
test/command/5410.mdnew file+7
@@ -0,0 +1,7 @@
1+```
2+% pandoc -f man -t native
3+.ie n \{\
4+'br\}
5+^D
6+[Para [LineBreak]]
7+```