@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28Conversion from Textile to 'Pandoc' document, based on the spec
28Conversion from Textile to 'Pandoc' document, based on the spec
29available at ahttp://redcloth.org/hobix.com/textile/
29available at ahttp://redcloth.org/hobix.com/textile/
31−Implemented and parsed :
31+Implemented and parsed:
32 - Paragraphs
32 - Paragraphs
33 - Code blocks
33 - Code blocks
@@ -36,8 +36,14 @@ Implemented and parsed :
36 - Inlines : strong, emph, cite, code, deleted, superscript,
36 - Inlines : strong, emph, cite, code, deleted, superscript,
37 subscript, links
37 subscript, links
39−Implemented but discarded :
39+Implemented but discarded:
40 - HTML-specific and CSS-specific attributes
40 - HTML-specific and CSS-specific attributes
42+Left to be implemented:
43+ - Pandoc Meta Information (title, author, date)
45+ - should autolink be shared through Parsing.hs ?
@@ -47,7 +53,8 @@ module Text.Pandoc.Readers.Textile (
47import Text.Pandoc.Definition
53import Text.Pandoc.Definition
48import Text.Pandoc.Shared
54import Text.Pandoc.Shared
49import Text.Pandoc.Parsing
55import Text.Pandoc.Parsing
50−import Text.Pandoc.Readers.HTML ( htmlTag, htmlEndTag )
56+import Text.Pandoc.Readers.HTML ( htmlTag, htmlEndTag, -- find code blocks
57+ rawHtmlBlock, rawHtmlInline )
51import Text.ParserCombinators.Parsec
58import Text.ParserCombinators.Parsec
52import Data.Char ( digitToInt )
59import Data.Char ( digitToInt )
@@ -83,6 +90,7 @@ blockParsers = [ codeBlock
84 , blockQuote
91 , blockQuote
86 , maybeExplicitBlock "table" table
94 , maybeExplicitBlock "table" table
87 , maybeExplicitBlock "p" para
95 , maybeExplicitBlock "p" para
88 , nullBlock ]
96 , nullBlock ]
@@ -170,17 +178,26 @@ orderedListItemAtDepth depth = try $ do
170 sublist <- option [] (anyListAtDepth (depth + 1) >>= return . (:[]))
178 sublist <- option [] (anyListAtDepth (depth + 1) >>= return . (:[]))
171 return (p:sublist)
179 return (p:sublist)
173−-- | This terminates a block such as a paragraph.
181+-- | This terminates a block such as a paragraph. Because of raw html
182+-- blocks support, we have to lookAhead for a rawHtmlBlock.
174blockBreak :: GenParser Char ParserState ()
183blockBreak :: GenParser Char ParserState ()
184+blockBreak = try $ choice
175−blockBreak = try $ newline >> blanklines >> return ()
185+ [newline >> blanklines >> return (),
186+ lookAhead rawHtmlBlock' >> return ()]
188+-- | A raw Html Block, optionally followed by blanklines
189+rawHtmlBlock' :: GenParser Char ParserState Block
190+rawHtmlBlock' = try $ do
178-- | In textile, paragraphs are separated by blank lines.
195-- | In textile, paragraphs are separated by blank lines.
179para :: GenParser Char ParserState Block
196para :: GenParser Char ParserState Block
180para = try $ do
197para = try $ do
181 content <- manyTill inline blockBreak
198 content <- manyTill inline blockBreak
182 return $ Para $ normalizeSpaces content
199 return $ Para $ normalizeSpaces content
@@ -260,6 +277,7 @@ inlineParsers = [ autoLink
261 , whitespace
278 , whitespace
262 , endline
279 , endline
264 , simpleInline (string "??") (Cite [])
282 , simpleInline (string "??") (Cite [])
265 , simpleInline (string "**") Strong
283 , simpleInline (string "**") Strong
@@ -313,7 +331,7 @@ image = try $ do
314-- | Any special symbol defined in specialChars
332-- | Any special symbol defined in specialChars
315symbol :: GenParser Char ParserState Inline
333symbol :: GenParser Char ParserState Inline
316−symbol = do
334+symbol = do
317 result <- oneOf specialChars
335 result <- oneOf specialChars
318 return $ Str [result]
336 return $ Str [result]
@@ -322,7 +340,6 @@ code :: GenParser Char ParserState Inline
322code = surrounded (char '@') anyChar >>=
340code = surrounded (char '@') anyChar >>=
323 return . Code
341 return . Code
326-- | Html / CSS attributes
343-- | Html / CSS attributes
327attributes :: GenParser Char ParserState String
344attributes :: GenParser Char ParserState String
328attributes = choice [ enclosed (char '(') (char ')') anyChar,
345attributes = choice [ enclosed (char '(') (char ')') anyChar,
@@ -341,12 +358,4 @@ simpleInline :: GenParser Char ParserState t -- ^ surrounding parser
341 -> GenParser Char ParserState Inline -- ^ content parser (to be used repeatedly)
358 -> GenParser Char ParserState Inline -- ^ content parser (to be used repeatedly)
342simpleInline border construct = surrounded border (inlineWithAttribute) >>=
359simpleInline border construct = surrounded border (inlineWithAttribute) >>=
343 return . construct . normalizeSpaces
360 return . construct . normalizeSpaces
344− where inlineWithAttribute = (try $ optional attributes) >> inline
361+ where inlineWithAttribute = (try $ optional attributes) >> inline
349−-- - Pandoc Meta Information (title, author, date)
351−-- - should autolink be shared through Parsing.hs ?
352−-- - embeded HTML, both inlines and blocks