@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2828Conversion from Textile to 'Pandoc' document, based on the spec
2929available at ahttp://redcloth.org/hobix.com/textile/
3030
31−Implemented and parsed :
31+Implemented and parsed:
3232 - Paragraphs
3333 - Code blocks
3434 - Lists
@@ -36,8 +36,14 @@ Implemented and parsed :
3636 - Inlines : strong, emph, cite, code, deleted, superscript,
3737 subscript, links
3838
39−Implemented but discarded :
39+Implemented but discarded:
4040 - HTML-specific and CSS-specific attributes
41+
42+Left to be implemented:
43+ - Pandoc Meta Information (title, author, date)
44+ - footnotes
45+ - should autolink be shared through Parsing.hs ?
46+
4147-}
4248
4349
@@ -47,7 +53,8 @@ module Text.Pandoc.Readers.Textile (
4753import Text.Pandoc.Definition
4854import Text.Pandoc.Shared
4955import 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 )
5158import Text.ParserCombinators.Parsec
5259import Data.Char ( digitToInt )
5360
@@ -83,6 +90,7 @@ blockParsers = [ codeBlock
8390 , header
8491 , blockQuote
8592 , anyList
93+ , rawHtmlBlock'
8694 , maybeExplicitBlock "table" table
8795 , maybeExplicitBlock "p" para
8896 , nullBlock ]
@@ -170,17 +178,26 @@ orderedListItemAtDepth depth = try $ do
170178 sublist <- option [] (anyListAtDepth (depth + 1) >>= return . (:[]))
171179 return (p:sublist)
172180
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.
174183blockBreak :: GenParser Char ParserState ()
175−blockBreak = try $ newline >> blanklines >> return ()
184+blockBreak = try $ choice
185+ [newline >> blanklines >> return (),
186+ lookAhead rawHtmlBlock' >> return ()]
176187
188+-- | A raw Html Block, optionally followed by blanklines
189+rawHtmlBlock' :: GenParser Char ParserState Block
190+rawHtmlBlock' = try $ do
191+ b <- rawHtmlBlock
192+ optional blanklines
193+ return b
177194
178195-- | In textile, paragraphs are separated by blank lines.
179196para :: GenParser Char ParserState Block
180197para = try $ do
181198 content <- manyTill inline blockBreak
182199 return $ Para $ normalizeSpaces content
183−
200+
184201
185202-- Tables
186203
@@ -260,6 +277,7 @@ inlineParsers = [ autoLink
260277 , str
261278 , whitespace
262279 , endline
280+ , rawHtmlInline
263281 , code
264282 , simpleInline (string "??") (Cite [])
265283 , simpleInline (string "**") Strong
@@ -313,7 +331,7 @@ image = try $ do
313331
314332-- | Any special symbol defined in specialChars
315333symbol :: GenParser Char ParserState Inline
316−symbol = do
334+symbol = do
317335 result <- oneOf specialChars
318336 return $ Str [result]
319337
@@ -322,7 +340,6 @@ code :: GenParser Char ParserState Inline
322340code = surrounded (char '@') anyChar >>=
323341 return . Code
324342
325−
326343-- | Html / CSS attributes
327344attributes :: GenParser Char ParserState String
328345attributes = choice [ enclosed (char '(') (char ')') anyChar,
@@ -341,12 +358,4 @@ simpleInline :: GenParser Char ParserState t -- ^ surrounding parser
341358 -> GenParser Char ParserState Inline -- ^ content parser (to be used repeatedly)
342359simpleInline border construct = surrounded border (inlineWithAttribute) >>=
343360 return . construct . normalizeSpaces
344− where inlineWithAttribute = (try $ optional attributes) >> inline
345−
346−
347−-- TODO
348−--
349−-- - Pandoc Meta Information (title, author, date)
350−-- - footnotes
351−-- - should autolink be shared through Parsing.hs ?
352−-- - embeded HTML, both inlines and blocks
361+ where inlineWithAttribute = (try $ optional attributes) >> inline