git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #4018 from swilde/creole-fixes

Creole Reader: fix lists with triling white space

commitfd7e3cb18f55e05795180b782a1b61dc602b6ac4 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 1 Nov 2017, 00:04 (9 years ago) parent0e57b8b534e625
2 files changed+21−6
src/Text/Pandoc/Readers/Creole.hs+7−5 test/Tests/Readers/Creole.hs+14−1
src/Text/Pandoc/Readers/Creole.hs+7−5
@@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2727 License : GNU GPL, version 2 or above
2828
2929 Maintainer : Sascha Wilde <wilde@sha-bang.de>
30− Stability : WIP
30+ Stability : alpha
3131 Portability : portable
3232
3333Conversion of creole text to 'Pandoc' document.
@@ -64,7 +64,7 @@ readCreole opts s = do
6464type CRLParser = ParserT [Char] ParserState
6565
6666--
67−-- Utility funcitons
67+-- Utility functions
6868--
6969
7070(<+>) :: (Monad m, Monoid a) => m a -> m a -> m a
@@ -111,7 +111,8 @@ block = do
111111 return res
112112
113113nowiki :: PandocMonad m => CRLParser m B.Blocks
114−nowiki = try $ fmap (B.codeBlock . mconcat) (nowikiStart >> manyTill content nowikiEnd)
114+nowiki = try $ fmap (B.codeBlock . mconcat) (nowikiStart
115+ >> manyTill content nowikiEnd)
115116 where
116117 content = brackets <|> line
117118 brackets = try $ option "" ((:[]) <$> newline)
@@ -154,7 +155,8 @@ listItem :: PandocMonad m => Char -> Int -> CRLParser m B.Blocks
154155listItem c n =
155156 fmap (B.plain . B.trimInlines .mconcat) (listStart >> many1Till inline itemEnd)
156157 where
157− listStart = try $ optional newline >> skipSpaces >> count n (char c)
158+ listStart = try $ skipSpaces >> optional newline >> skipSpaces
159+ >> count n (char c)
158160 >> lookAhead (noneOf [c]) >> skipSpaces
159161 itemEnd = endOfParaElement <|> nextItem n
160162 <|> if n < 3 then nextItem (n+1)
@@ -193,7 +195,7 @@ endOfParaElement = lookAhead $ endOfInput <|> endOfPara
193195 startOf :: PandocMonad m => CRLParser m a -> CRLParser m ()
194196 startOf p = try $ blankline >> p >> return mempty
195197 startOfList = startOf $ anyList 1
196− startOfTable =startOf table
198+ startOfTable = startOf table
197199 startOfHeader = startOf header
198200 startOfNowiki = startOf nowiki
199201 hr = startOf horizontalRule
test/Tests/Readers/Creole.hs+14−1
@@ -127,6 +127,11 @@ tests = [
127127 =?> bulletList [ plain "foo"
128128 <> bulletList [ plain "bar", plain "baz" ]
129129 , plain "blubb" ]
130+ , "nested unordered list, one separating space, trailing space" =:
131+ "* foo \n** bar \n** baz \n* blubb "
132+ =?> bulletList [ plain "foo"
133+ <> bulletList [ plain "bar", plain "baz" ]
134+ , plain "blubb" ]
130135 , "ordered list, two entries, one separating space" =:
131136 "# foo\n# bar"
132137 =?> orderedList [ plain "foo", plain "bar" ]
@@ -141,6 +146,11 @@ tests = [
141146 =?> orderedList [ plain "foo"
142147 <> orderedList [ plain "bar", plain "baz" ]
143148 , plain "blubb" ]
149+ , "nested ordered list, one separating space, trailing space" =:
150+ "# foo \n## bar \n## baz \n# blubb "
151+ =?> orderedList [ plain "foo"
152+ <> orderedList [ plain "bar", plain "baz" ]
153+ , plain "blubb" ]
144154 , "nested many ordered lists, one separating space" =:
145155 ("# foo\n## bar\n### third\n### third two\n## baz\n### third again\n"
146156 <> "#### fourth\n##### fith\n# blubb")
@@ -193,7 +203,10 @@ tests = [
193203 , "forced line breaks" =:
194204 "{{{no break!\\\\here}}} but a break\\\\here!"
195205 =?> para (code "no break!\\\\here" <> " but a break"
196− <> linebreak <> "here!")
206+ <> linebreak <> "here!"),
207+ "quoted block, after trailing white space" =:
208+ "this is a paragraph \n{{{\nfoo bar\n //baz//\n}}}"
209+ =?> para "this is a paragraph" <> codeBlock "foo bar\n //baz//"
197210 ]
198211 , testGroup "Images and Links" [
199212 "image simple" =: