@@ -26,9 +26,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2626 Portability : portable
2727
2828Conversion from Textile to 'Pandoc' document, based on the spec
29−available at http://redcloth.org/hobix.com/textile/
29+available at ahttp://redcloth.org/hobix.com/textile/
3030
31−Implemented :
31+Implemented and parsed :
3232 - Paragraphs
3333 - Code blocks
3434 - Lists
@@ -36,8 +36,8 @@ Implemented :
3636 - Inlines : strong, emph, cite, code, deleted, superscript,
3737 subscript, links
3838
39−Not implemented :
40− - HTML-specific and CSS-specific inlines
39+Implemented but discarded :
40+ - HTML-specific and CSS-specific attributes
4141-}
4242
4343
@@ -83,8 +83,8 @@ blockParsers = [ codeBlock
8383 , header
8484 , blockQuote
8585 , anyList
86− , table
87− , para
86+ , maybeExplicitBlock "table" table
87+ , maybeExplicitBlock "p" para
8888 , nullBlock ]
8989
9090-- | Any block in the order of definition of blockParsers
@@ -103,6 +103,7 @@ header :: GenParser Char ParserState Block
103103header = try $ do
104104 char 'h'
105105 level <- oneOf "123456" >>= return . digitToInt
106+ optional attributes
106107 char '.'
107108 whitespace
108109 name <- manyTill inline blockBreak
@@ -111,7 +112,9 @@ header = try $ do
111112-- | Blockquote of the form "bq. content"
112113blockQuote :: GenParser Char ParserState Block
113114blockQuote = try $ do
114− string "bq."
115+ string "bq"
116+ optional attributes
117+ char '.'
115118 whitespace
116119 para >>= return . BlockQuote . (:[])
117120
@@ -143,6 +146,7 @@ bulletListAtDepth depth = try $ do
143146bulletListItemAtDepth :: Int -> GenParser Char ParserState [Block]
144147bulletListItemAtDepth depth = try $ do
145148 count depth (char '*')
149+ optional attributes
146150 whitespace
147151 p <- inlines >>= return . Plain
148152 sublist <- option [] (anyListAtDepth (depth + 1) >>= return . (:[]))
@@ -160,6 +164,7 @@ orderedListAtDepth depth = try $ do
160164orderedListItemAtDepth :: Int -> GenParser Char ParserState [Block]
161165orderedListItemAtDepth depth = try $ do
162166 count depth (char '#')
167+ optional attributes
163168 whitespace
164169 p <- inlines >>= return . Plain
165170 sublist <- option [] (anyListAtDepth (depth + 1) >>= return . (:[]))
@@ -169,6 +174,7 @@ orderedListItemAtDepth depth = try $ do
169174blockBreak :: GenParser Char ParserState ()
170175blockBreak = try $ newline >> blanklines >> return ()
171176
177+
172178-- | In textile, paragraphs are separated by blank lines.
173179para :: GenParser Char ParserState Block
174180para = try $ do
@@ -223,6 +229,17 @@ table = try $ do
223229 rows
224230
225231
232+-- | Blocks like 'p' and 'table' do not need explicit block tag.
233+-- However, they can be used to set HTML/CSS attributes when needed.
234+maybeExplicitBlock :: String -- ^ block tag name
235+ -> GenParser Char ParserState Block -- ^ implicit block
236+ -> GenParser Char ParserState Block
237+maybeExplicitBlock name blk = try $ do
238+ optional $ string name >> optional attributes >> char '.' >>
239+ ((try whitespace) <|> endline)
240+ blk
241+
242+
226243
227244----------
228245-- Inlines
@@ -305,6 +322,13 @@ code :: GenParser Char ParserState Inline
305322code = surrounded (char '@') anyChar >>=
306323 return . Code
307324
325+
326+-- | Html / CSS attributes
327+attributes :: GenParser Char ParserState String
328+attributes = choice [ enclosed (char '(') (char ')') anyChar,
329+ enclosed (char '{') (char '}') anyChar,
330+ enclosed (char '[') (char ']') anyChar]
331+
308332-- | Parses material surrounded by a parser.
309333surrounded :: GenParser Char st t -- ^ surrounding parser
310334 -> GenParser Char st a -- ^ content parser (to be used repeatedly)
@@ -315,8 +339,9 @@ surrounded border = enclosed border border
315339simpleInline :: GenParser Char ParserState t -- ^ surrounding parser
316340 -> ([Inline] -> Inline) -- ^ Inline constructor
317341 -> GenParser Char ParserState Inline -- ^ content parser (to be used repeatedly)
318−simpleInline border construct = surrounded border inline >>=
342+simpleInline border construct = surrounded border (inlineWithAttribute) >>=
319343 return . construct . normalizeSpaces
344+ where inlineWithAttribute = (try $ optional attributes) >> inline
320345
321346
322347-- TODO
@@ -324,3 +349,4 @@ simpleInline border construct = surrounded border inline >>=
324349-- - Pandoc Meta Information (title, author, date)
325350-- - footnotes
326351-- - should autolink be shared through Parsing.hs ?
352+-- - embeded HTML, both inlines and blocks