From 56c4a11f97ce61085f1435e806437fbdb2638bd0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 19 Oct 2018 15:16:05 -0700 Subject: Man reader: minor improvements. use `trimInlines` for Para content to avoid leading and trailing spaces. Fix handling of \" in middle of line. Add more tests for escapes. --- src/Text/Pandoc/Readers/Man.hs | 6 +++--- test/Tests/Readers/Man.hs | 10 ++++++++-- test/man-reader.native | 10 +++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Text/Pandoc/Readers/Man.hs b/src/Text/Pandoc/Readers/Man.hs index d248a0714..02cdd83d2 100644 --- a/src/Text/Pandoc/Readers/Man.hs +++ b/src/Text/Pandoc/Readers/Man.hs @@ -216,8 +216,8 @@ escapeLexer = do escSingle = do c <- anyChar case c of - '"' -> mempty <$ manyTill anyChar newline -- line comment - '#' -> mempty <$ (manyTill anyChar newline >> optional newline) + '"' -> mempty <$ skipMany (satisfy (/='\n')) -- line comment + '#' -> mempty <$ manyTill anyChar newline '%' -> return mempty '{' -> return mempty '}' -> return mempty @@ -478,7 +478,7 @@ strToInlines (s, fonts) = inner $ S.toList fonts where inner (Regular:fs) = inner fs parsePara :: PandocMonad m => ManParser m Blocks -parsePara = para <$> parseInlines +parsePara = para . trimInlines <$> parseInlines parseInlines :: PandocMonad m => ManParser m Inlines parseInlines = do diff --git a/test/Tests/Readers/Man.hs b/test/Tests/Readers/Man.hs index f784596f3..e531404f5 100644 --- a/test/Tests/Readers/Man.hs +++ b/test/Tests/Readers/Man.hs @@ -42,7 +42,7 @@ tests = [ =?> (para $ strong $ text "single arg with \"Q\"") , "comment" =: ".\\\"bla\naaa" - =?> (para $ space <> str "aaa") + =?> (para $ str "aaa") , "link" =: ".BR aa (1)" =?> (para $ link "../1/aa.1" "aa" (strong $ str "aa") <> (strong $ str " (1)")) @@ -59,7 +59,13 @@ tests = [ =?> (para $ text "- \\“”—–“”") , "replace2" =: "\\t\\e\\`\\^\\|\\'" - =?> (para $ text "\t\\` `") + =?> (para $ text "\\` `") + , "comment with \\\"" =: + "Foo \\\" bar\n" + =?> (para $ text "Foo") + , "comment with \\#" =: + "Foo\\#\nbar\n" + =?> (para $ text "Foobar") ], testGroup "Lists" [ "bullet" =: diff --git a/test/man-reader.native b/test/man-reader.native index c79e6d4d0..042bd2386 100644 --- a/test/man-reader.native +++ b/test/man-reader.native @@ -1,17 +1,17 @@ Pandoc (Meta {unMeta = fromList [("title",MetaString "Pandoc Man tests")]}) [Header 1 ("",[],[]) [Str "Pandoc",Space,Str "Man",Space,Str "tests"] ,Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "set",Space,Str "of",Space,Str "tests",Space,Str "for",Space,Str "pandoc."] -,Para [Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] +,Para [Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] ,Header 2 ("",[],[]) [Str "Headers"] ,Header 2 ("",[],[]) [Str "Level",Space,Str "1"] ,Header 3 ("",[],[]) [Str "Level",Space,Str "2"] -,Para [Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] +,Para [Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] ,Header 2 ("",[],[]) [Str "Paragraphs"] ,Para [Str "Here's",Space,Str "a",Space,Str "regular",Space,Str "paragraph."] ,Para [Str "Another",Space,Str "paragraph",Space,Str "In",Space,Str "Markdown",Space,Str "1.0.0",Space,Str "and",Space,Str "earlier.",Space,Str "Version",Space,Str "8.",Space,Str "This",Space,Str "line",Space,Str "turns",Space,Str "into",Space,Str "a",Space,Str "list",Space,Str "item.",Space,Str "Because",Space,Str "a",Space,Str "hard-wrapped",Space,Str "line",Space,Str "in",Space,Str "the",Space,Str "middle",Space,Str "of",Space,Str "a",Space,Str "paragraph",Space,Str "looked",Space,Str "like",Space,Str "a",Space,Str "list",Space,Str "item."] ,Para [Str "There",Space,Str "should",Space,Str "be",Space,Str "a",Space,Str "hard",Space,Str "line",Space,Str "break"] ,Para [Str "here."] -,Para [Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] +,Para [Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] ,Header 2 ("",[],[]) [Str "Block",Space,Str "Quotes"] ,Para [Str "Code",Space,Str "in",Space,Str "a",Space,Str "block",Space,Str "quote:"] ,CodeBlock ("",[],[]) "\nsub status {\n print \"working\";\n}" @@ -24,7 +24,7 @@ Pandoc (Meta {unMeta = fromList [("title",MetaString "Pandoc Man tests")]}) ,CodeBlock ("",[],[]) "\n---- (should be four hyphens)\n\nsub status {\n print \"working\";\n}\n" ,Para [Str "And:"] ,CodeBlock ("",[],[]) "\n\tthis code line is indented by one tab" -,Para [Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] +,Para [Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] ,Header 2 ("",[],[]) [Str "Lists"] ,Header 3 ("",[],[]) [Str "Unordered"] ,Para [Str "Asterisks:"] @@ -71,7 +71,7 @@ Pandoc (Meta {unMeta = fromList [("title",MetaString "Pandoc Man tests")]}) [[Plain [Str "Decimal",Space,Str "start",Space,Str "with",Space,Str "6"] ,OrderedList (3,LowerAlpha,OneParen) [[Plain [Str "Lower",Space,Str "alpha",Space,Str "with",Space,Str "paren"]]]]]]]]] -,Para [Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] +,Para [Str "*",Space,Str "*",Space,Str "*",Space,Str "*",Space,Str "*"] ,Header 2 ("",[],[]) [Str "Special",Space,Str "Characters"] ,Para [Str "AT&T",Space,Str "has",Space,Str "an",Space,Str "ampersand",Space,Str "in",Space,Str "their",Space,Str "name."] ,Para [Str "4",Space,Str "<",Space,Str "5."] -- cgit v1.2.3