aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-07-22 15:32:50 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2016-07-22 15:32:50 -0700
commit5f758970a5277de492728a3277bd7aae41978a1c (patch)
tree58df1944160c8c20ff9feaa935e517a95c60b62d
parent69e7249ab18bf12e3416896a0ef531fb5038c055 (diff)
downloadpandoc-5f758970a5277de492728a3277bd7aae41978a1c.tar.gz
Textile reader: support `bc..` extended code blocks.
Also, remove trailing newline in code blocks (consistently with Markdown reader).
m---------data/templates16
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs30
-rw-r--r--tests/textile-reader.native2
3 files changed, 33 insertions, 15 deletions
diff --git a/data/templates b/data/templates
-Subproject 6b2a1db0b9a8d5d7daca2c4542ad1a011b64d56
+Subproject 8bed1acf2271c84ae564d6f0b9adcdc4d5c71d2
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs
index 13fe29ca2..25d687c1f 100644
--- a/src/Text/Pandoc/Readers/Textile.hs
+++ b/src/Text/Pandoc/Readers/Textile.hs
@@ -161,9 +161,22 @@ codeBlock = codeBlockBc <|> codeBlockPre
codeBlockBc :: Parser [Char] ParserState Blocks
codeBlockBc = try $ do
- string "bc. "
- contents <- manyTill anyLine blanklines
- return $ B.codeBlock (unlines contents)
+ string "bc."
+ extended <- option False (True <$ char '.')
+ char ' '
+ let starts = ["p", "table", "bq", "bc", "h1", "h2", "h3",
+ "h4", "h5", "h6", "pre", "###", "notextile"]
+ let ender = choice $ map explicitBlockStart starts
+ contents <- if extended
+ then do
+ f <- anyLine
+ rest <- many (notFollowedBy ender *> anyLine)
+ return (f:rest)
+ else manyTill anyLine blanklines
+ return $ B.codeBlock (trimTrailingNewlines (unlines contents))
+
+trimTrailingNewlines :: String -> String
+trimTrailingNewlines = reverse . dropWhile (=='\n') . reverse
-- | Code Blocks in Textile are between <pre> and </pre>
codeBlockPre :: Parser [Char] ParserState Blocks
@@ -408,14 +421,21 @@ ignorableRow = try $ do
_ <- anyLine
return ()
+explicitBlockStart :: String -> Parser [Char] ParserState ()
+explicitBlockStart name = try $ do
+ string name
+ attributes
+ char '.'
+ optional whitespace
+ optional endline
+
-- | Blocks like 'p' and 'table' do not need explicit block tag.
-- However, they can be used to set HTML/CSS attributes when needed.
maybeExplicitBlock :: String -- ^ block tag name
-> Parser [Char] ParserState Blocks -- ^ implicit block
-> Parser [Char] ParserState Blocks
maybeExplicitBlock name blk = try $ do
- optional $ try $ string name >> attributes >> char '.' >>
- optional whitespace >> optional endline
+ optional $ explicitBlockStart name
blk
diff --git a/tests/textile-reader.native b/tests/textile-reader.native
index 2e8a6d01c..0b4b3bb22 100644
--- a/tests/textile-reader.native
+++ b/tests/textile-reader.native
@@ -25,7 +25,7 @@ Pandoc (Meta {unMeta = fromList []})
,CodeBlock ("",[],[]) " ---- (should be four hyphens)\n\n sub status {\n print \"working\";\n }\n\n this code block is indented by one tab"
,Para [Str "And:"]
,CodeBlock ("",[],[]) " this code block is indented by two tabs\n\n These should not be escaped: \\$ \\\\ \\> \\[ \\{"
-,CodeBlock ("",[],[]) "Code block with .bc\n continued\n @</\\\n"
+,CodeBlock ("",[],[]) "Code block with .bc\n continued\n @</\\"
,Para [Str "Inline",Space,Str "code:",Space,Code ("",[],[]) "<tt>",Str ",",Space,Code ("",[],[]) "@",Str "."]
,Header 1 ("notextile",[],[]) [Str "Notextile"]
,Para [Str "A",Space,Str "block",Space,Str "of",Space,Str "text",Space,Str "can",Space,Str "be",Space,Str "protected",Space,Str "with",Space,Str "notextile",Space,Str ":"]