git.iko.soy/typeable/pandoc
on master help sign in
preliminary material toward table support
commitd917db5e42353c2878e429fd29bf7ef6d576ad62 authorpaul.rivier <paul.r.ml@gmail.com> dateFri 17 Sep 2010, 18:20 (16 years ago) parent75fa22c
2 files changed+68−2
src/Text/Pandoc/Definition.hs+4−1 src/Text/Pandoc/Readers/Textile.hs+64−1
src/Text/Pandoc/Definition.hs+4−1
@@ -47,6 +47,9 @@ data Alignment = AlignLeft
4747 | AlignCenter
4848 | AlignDefault deriving (Eq, Ord, Show, Read, Typeable, Data)
4949
50+-- | Table cells are list of Blocks
51+type TableCell = [Block]
52+
5053-- | List attributes.
5154type ListAttributes = (Int, ListNumberStyle, ListNumberDelim)
5255
@@ -85,7 +88,7 @@ data Block
8588 -- definitions (each a list of blocks)
8689 | Header Int [Inline] -- ^ Header - level (integer) and text (inlines)
8790 | HorizontalRule -- ^ Horizontal rule
88− | Table [Inline] [Alignment] [Double] [[Block]] [[[Block]]] -- ^ Table,
91+ | Table [Inline] [Alignment] [Double] [TableCell] [[TableCell]] -- ^ Table,
8992 -- with caption, column alignments,
9093 -- relative column widths (0 = default),
9194 -- column headers (each a list of blocks), and
src/Text/Pandoc/Readers/Textile.hs+64−1
@@ -63,7 +63,7 @@ readTextile state s = (readWith parseTextile) state (s ++ "\n\n")
6363
6464-- | Special chars border strings parsing
6565specialChars :: [Char]
66−specialChars = "\\[]*#_@~<>!?-+^&'\";:"
66+specialChars = "\\[]*#_@~<>!?-+^&'\";:|"
6767
6868-- | Generate a Pandoc ADT from a textile document
6969parseTextile :: GenParser Char ParserState Pandoc
@@ -82,6 +82,7 @@ blockParsers = [ codeBlock
8282 , header
8383 , blockQuote
8484 , anyList
85+ , table
8586 , para
8687 , nullBlock ]
8788
@@ -173,6 +174,68 @@ para = try $ do
173174 content <- manyTill inline blockBreak
174175 return $ Para $ normalizeSpaces content
175176
177+
178+-- Tables
179+
180+-- TODO : DOC and factorizing cellInlines
181+
182+tableCell :: GenParser Char ParserState TableCell
183+tableCell = many1 cellInline >>= return . (:[]) . Plain . normalizeSpaces
184+ where cellInline = choice [ str
185+ , whitespace
186+ , code
187+ , simpleInline (string "??") (Cite [])
188+ , simpleInline (char '*') Strong
189+ , simpleInline (char '_') Emph
190+ , simpleInline (string "**") Strong
191+ , simpleInline (string "__") Emph
192+ , simpleInline (char '-') Strikeout
193+ , simpleInline (char '+') Inserted
194+ , simpleInline (char '^') Superscript
195+ , simpleInline (char '~') Subscript
196+ -- , link
197+ -- , image
198+ -- , math
199+ -- , autoLink
200+ ]
201+
202+tableRow :: GenParser Char ParserState [TableCell]
203+tableRow = try $ do
204+ char '|'
205+ cells <- endBy1 tableCell (char '|')
206+ newline
207+ return cells
208+
209+tableRows :: GenParser Char ParserState [[TableCell]]
210+tableRows = many1 tableRow
211+
212+tableHeaders :: GenParser Char ParserState [TableCell]
213+tableHeaders = try $ do
214+ let separator = (try $ string "|_.")
215+ separator
216+ headers <- sepBy1 tableCell separator
217+ char '|'
218+ newline
219+ return headers
220+
221+table :: GenParser Char ParserState Block
222+table = try $ do
223+ headers <- option [] tableHeaders
224+ rows <- tableRows
225+ return $ Table []
226+ (replicate (length headers) AlignDefault)
227+ (replicate (length headers) 0.0)
228+ headers
229+ rows
230+
231+
232+----------
233+-- Inlines
234+----------
235+
236+
237+
238+
176239-- | Any inline element
177240inline :: GenParser Char ParserState Inline
178241inline = choice inlineParsers <?> "inline"