From ad9603231f5fec1ccfb8111c3080d61f375189b9 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Thu, 11 Oct 2007 05:50:28 +0000 Subject: Fixed bug in RST reader: previously, code blocks had to be indented a full tabstop, but RST allows any amount of indentation. Resolves Issue #27. + removed 'variable' parameter from indentedBlock function in RST reader, as it is no longer needed + updated test suite + updated changelog git-svn-id: https://pandoc.googlecode.com/svn/trunk@1046 788f1e2b-df1e-0410-8736-df70ead52e1b --- debian/changelog | 4 ++++ src/Text/Pandoc/Readers/RST.hs | 21 ++++++++------------- tests/rst-reader.native | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1ce453691..1a73a93c5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -27,6 +27,10 @@ pandoc (0.45) unstable; urgency=low * Markdown reader: Require space before title in links and references. This fixes a bug in parsing URLs like http://silly/url(withparen). + * RST reader: Fixed bug in parsing of code blocks. Previously a + full tab indent was required, but RST allows code to be indented + any amount. Resolves Issue #27. + * HTML writer: Don't produce HTML for table of contents if there are no headers. (This would be an empty list, which is invalid XHTML.) diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 0103087a5..1769b84d6 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -281,15 +281,11 @@ indentedLine indents = try $ do return $ result ++ "\n" -- two or more indented lines, possibly separated by blank lines. --- if variable = True, then any indent will work, but it must be --- consistent through the block. --- if variable = False, indent should be one tab or equivalent in spaces. -indentedBlock variable = try $ do +-- any amount of indentation will work. +indentedBlock = try $ do state <- getState let tabStop = stateTabStop state - indents <- if variable - then many1 (oneOf " \t") - else oneOfStrings ["\t", (replicate tabStop ' ')] + indents <- many1 (oneOf " \t") firstline <- manyTill anyChar newline rest <- many (choice [ indentedLine indents, try (do b <- blanklines @@ -300,8 +296,7 @@ indentedBlock variable = try $ do codeBlock = try $ do codeBlockStart - result <- indentedBlock False - -- the False means we want one tab stop indent on each line + result <- indentedBlock return $ CodeBlock $ stripTrailingNewlines result -- @@ -309,7 +304,7 @@ codeBlock = try $ do -- rawHtmlBlock = try $ string ".. raw:: html" >> blanklines >> - indentedBlock True >>= return . RawHtml + indentedBlock >>= return . RawHtml -- -- raw latex @@ -318,7 +313,7 @@ rawHtmlBlock = try $ string ".. raw:: html" >> blanklines >> rawLaTeXBlock = try $ do string ".. raw:: latex" blanklines - result <- indentedBlock True + result <- indentedBlock return $ Para [(TeX result)] -- @@ -326,7 +321,7 @@ rawLaTeXBlock = try $ do -- blockQuote = do - raw <- indentedBlock True + raw <- indentedBlock -- parse the extracted block, which may contain various block elements: contents <- parseFromString parseBlocks $ raw ++ "\n\n" return $ BlockQuote contents @@ -339,7 +334,7 @@ list = choice [ bulletList, orderedList, definitionList ] "list" definitionListItem = try $ do term <- many1Till inline endline - raw <- indentedBlock True + raw <- indentedBlock -- parse the extracted block, which may contain various block elements: contents <- parseFromString parseBlocks $ raw ++ "\n\n" return (normalizeSpaces term, contents) diff --git a/tests/rst-reader.native b/tests/rst-reader.native index 948c04be5..bbd139776 100644 --- a/tests/rst-reader.native +++ b/tests/rst-reader.native @@ -41,7 +41,7 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":",Space,Str , CodeBlock "---- (should be four hyphens)\n\nsub status {\n print \"working\";\n}" , CodeBlock "this code block is indented by one tab" , Para [Str "And",Str ":"] -, CodeBlock " this block is indented by two tabs\n\n These should not be escaped: \\$ \\\\ \\> \\[ \\{" +, CodeBlock "this block is indented by two tabs\n\nThese should not be escaped: \\$ \\\\ \\> \\[ \\{" , Header 1 [Str "Lists"] , Header 2 [Str "Unordered"] , Para [Str "Asterisks",Space,Str "tight",Str ":"] -- cgit v1.2.3