summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Textile.hs
diff options
context:
space:
mode:
authorpaul.rivier <paul.r.ml@gmail.com>2010-09-17 18:20:03 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-03 23:10:51 -0800
commitd917db5e42353c2878e429fd29bf7ef6d576ad62 (patch)
tree52515b0332fd115b0e932e53788572a8f3aed3f5 /src/Text/Pandoc/Readers/Textile.hs
parent75fa22c30039d1b4b9db46b3fe02591fa4152806 (diff)
preliminary material toward table support
Diffstat (limited to 'src/Text/Pandoc/Readers/Textile.hs')
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs65
1 files changed, 64 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs
index 1bd3cc7ec..0bdb915b3 100644
--- a/src/Text/Pandoc/Readers/Textile.hs
+++ b/src/Text/Pandoc/Readers/Textile.hs
@@ -63,7 +63,7 @@ readTextile state s = (readWith parseTextile) state (s ++ "\n\n")
-- | Special chars border strings parsing
specialChars :: [Char]
-specialChars = "\\[]*#_@~<>!?-+^&'\";:"
+specialChars = "\\[]*#_@~<>!?-+^&'\";:|"
-- | Generate a Pandoc ADT from a textile document
parseTextile :: GenParser Char ParserState Pandoc
@@ -82,6 +82,7 @@ blockParsers = [ codeBlock
, header
, blockQuote
, anyList
+ , table
, para
, nullBlock ]
@@ -173,6 +174,68 @@ para = try $ do
content <- manyTill inline blockBreak
return $ Para $ normalizeSpaces content
+
+-- Tables
+
+-- TODO : DOC and factorizing cellInlines
+
+tableCell :: GenParser Char ParserState TableCell
+tableCell = many1 cellInline >>= return . (:[]) . Plain . normalizeSpaces
+ where cellInline = choice [ str
+ , whitespace
+ , code
+ , simpleInline (string "??") (Cite [])
+ , simpleInline (char '*') Strong
+ , simpleInline (char '_') Emph
+ , simpleInline (string "**") Strong
+ , simpleInline (string "__") Emph
+ , simpleInline (char '-') Strikeout
+ , simpleInline (char '+') Inserted
+ , simpleInline (char '^') Superscript
+ , simpleInline (char '~') Subscript
+ -- , link
+ -- , image
+ -- , math
+ -- , autoLink
+ ]
+
+tableRow :: GenParser Char ParserState [TableCell]
+tableRow = try $ do
+ char '|'
+ cells <- endBy1 tableCell (char '|')
+ newline
+ return cells
+
+tableRows :: GenParser Char ParserState [[TableCell]]
+tableRows = many1 tableRow
+
+tableHeaders :: GenParser Char ParserState [TableCell]
+tableHeaders = try $ do
+ let separator = (try $ string "|_.")
+ separator
+ headers <- sepBy1 tableCell separator
+ char '|'
+ newline
+ return headers
+
+table :: GenParser Char ParserState Block
+table = try $ do
+ headers <- option [] tableHeaders
+ rows <- tableRows
+ return $ Table []
+ (replicate (length headers) AlignDefault)
+ (replicate (length headers) 0.0)
+ headers
+ rows
+
+
+----------
+-- Inlines
+----------
+
+
+
+
-- | Any inline element
inline :: GenParser Char ParserState Inline
inline = choice inlineParsers <?> "inline"