git.iko.soy/typeable/pandoc
on master help sign in
Fixed bug in RST reader: previously, code blocks had to be
ad96032fiddlosopher
debian/changelog+4
@@ -27,6 +27,10 @@ pandoc (0.45) unstable; urgency=low
27 * Markdown reader: Require space before title in links and references.
27 * Markdown reader: Require space before title in links and references.
28 This fixes a bug in parsing URLs like http://silly/url(withparen).
28 This fixes a bug in parsing URLs like http://silly/url(withparen).
29
29
30+ * RST reader: Fixed bug in parsing of code blocks. Previously a
31+ full tab indent was required, but RST allows code to be indented
32+ any amount. Resolves Issue #27.
33+
30 * HTML writer: Don't produce HTML for table of contents if there are
34 * HTML writer: Don't produce HTML for table of contents if there are
31 no headers. (This would be an empty list, which is invalid XHTML.)
35 no headers. (This would be an empty list, which is invalid XHTML.)
32
36
src/Text/Pandoc/Readers/RST.hs+8−13
@@ -281,15 +281,11 @@ indentedLine indents = try $ do
281 return $ result ++ "\n"
281 return $ result ++ "\n"
282
282
283-- two or more indented lines, possibly separated by blank lines.
283-- two or more indented lines, possibly separated by blank lines.
284−-- if variable = True, then any indent will work, but it must be
284+-- any amount of indentation will work.
285−-- consistent through the block.
286−-- if variable = False, indent should be one tab or equivalent in spaces.
287−indentedBlock variable = try $ do
285+indentedBlock = try $ do
288 state <- getState
286 state <- getState
289 let tabStop = stateTabStop state
287 let tabStop = stateTabStop state
290− indents <- if variable
291− then many1 (oneOf " \t")
288+ indents <- many1 (oneOf " \t")
292− else oneOfStrings ["\t", (replicate tabStop ' ')]
293 firstline <- manyTill anyChar newline
289 firstline <- manyTill anyChar newline
294 rest <- many (choice [ indentedLine indents,
290 rest <- many (choice [ indentedLine indents,
295 try (do b <- blanklines
291 try (do b <- blanklines
@@ -300,8 +296,7 @@ indentedBlock variable = try $ do
300
296
301codeBlock = try $ do
297codeBlock = try $ do
302 codeBlockStart
298 codeBlockStart
303− result <- indentedBlock False
299+ result <- indentedBlock
304− -- the False means we want one tab stop indent on each line
305 return $ CodeBlock $ stripTrailingNewlines result
300 return $ CodeBlock $ stripTrailingNewlines result
306
301
307--
302--
@@ -309,7 +304,7 @@ codeBlock = try $ do
309--
304--
310
305
311rawHtmlBlock = try $ string ".. raw:: html" >> blanklines >>
306rawHtmlBlock = try $ string ".. raw:: html" >> blanklines >>
312− indentedBlock True >>= return . RawHtml
307+ indentedBlock >>= return . RawHtml
313
308
314--
309--
315-- raw latex
310-- raw latex
@@ -318,7 +313,7 @@ rawHtmlBlock = try $ string ".. raw:: html" >> blanklines >>
318rawLaTeXBlock = try $ do
313rawLaTeXBlock = try $ do
319 string ".. raw:: latex"
314 string ".. raw:: latex"
320 blanklines
315 blanklines
321− result <- indentedBlock True
316+ result <- indentedBlock
322 return $ Para [(TeX result)]
317 return $ Para [(TeX result)]
323
318
324--
319--
@@ -326,7 +321,7 @@ rawLaTeXBlock = try $ do
326--
321--
327
322
328blockQuote = do
323blockQuote = do
329− raw <- indentedBlock True
324+ raw <- indentedBlock
330 -- parse the extracted block, which may contain various block elements:
325 -- parse the extracted block, which may contain various block elements:
331 contents <- parseFromString parseBlocks $ raw ++ "\n\n"
326 contents <- parseFromString parseBlocks $ raw ++ "\n\n"
332 return $ BlockQuote contents
327 return $ BlockQuote contents
@@ -339,7 +334,7 @@ list = choice [ bulletList, orderedList, definitionList ] <?> "list"
339
334
340definitionListItem = try $ do
335definitionListItem = try $ do
341 term <- many1Till inline endline
336 term <- many1Till inline endline
342− raw <- indentedBlock True
337+ raw <- indentedBlock
343 -- parse the extracted block, which may contain various block elements:
338 -- parse the extracted block, which may contain various block elements:
344 contents <- parseFromString parseBlocks $ raw ++ "\n\n"
339 contents <- parseFromString parseBlocks $ raw ++ "\n\n"
345 return (normalizeSpaces term, contents)
340 return (normalizeSpaces term, contents)
tests/rst-reader.native+1−1
@@ -41,7 +41,7 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":",Space,Str
41, CodeBlock "---- (should be four hyphens)\n\nsub status {\n print \"working\";\n}"
41, CodeBlock "---- (should be four hyphens)\n\nsub status {\n print \"working\";\n}"
42, CodeBlock "this code block is indented by one tab"
42, CodeBlock "this code block is indented by one tab"
43, Para [Str "And",Str ":"]
43, Para [Str "And",Str ":"]
44−, CodeBlock " this block is indented by two tabs\n\n These should not be escaped: \\$ \\\\ \\> \\[ \\{"
44+, CodeBlock "this block is indented by two tabs\n\nThese should not be escaped: \\$ \\\\ \\> \\[ \\{"
45, Header 1 [Str "Lists"]
45, Header 1 [Str "Lists"]
46, Header 2 [Str "Unordered"]
46, Header 2 [Str "Unordered"]
47, Para [Str "Asterisks",Space,Str "tight",Str ":"]
47, Para [Str "Asterisks",Space,Str "tight",Str ":"]