git.iko.soy/typeable/pandoc
on master help sign in
preliminary material toward table support
d917db5paul.rivier
src/Text/Pandoc/Definition.hs+4−1
@@ -47,6 +47,9 @@ data Alignment = AlignLeft
47 | AlignCenter
47 | AlignCenter
48 | AlignDefault deriving (Eq, Ord, Show, Read, Typeable, Data)
48 | AlignDefault deriving (Eq, Ord, Show, Read, Typeable, Data)
49
49
50+-- | Table cells are list of Blocks
51+type TableCell = [Block]
52+
50-- | List attributes.
53-- | List attributes.
51type ListAttributes = (Int, ListNumberStyle, ListNumberDelim)
54type ListAttributes = (Int, ListNumberStyle, ListNumberDelim)
52
55
@@ -85,7 +88,7 @@ data Block
85 -- definitions (each a list of blocks)
88 -- definitions (each a list of blocks)
86 | Header Int [Inline] -- ^ Header - level (integer) and text (inlines)
89 | Header Int [Inline] -- ^ Header - level (integer) and text (inlines)
87 | HorizontalRule -- ^ Horizontal rule
90 | HorizontalRule -- ^ Horizontal rule
88− | Table [Inline] [Alignment] [Double] [[Block]] [[[Block]]] -- ^ Table,
91+ | Table [Inline] [Alignment] [Double] [TableCell] [[TableCell]] -- ^ Table,
89 -- with caption, column alignments,
92 -- with caption, column alignments,
90 -- relative column widths (0 = default),
93 -- relative column widths (0 = default),
91 -- column headers (each a list of blocks), and
94 -- 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")
63
63
64-- | Special chars border strings parsing
64-- | Special chars border strings parsing
65specialChars :: [Char]
65specialChars :: [Char]
66−specialChars = "\\[]*#_@~<>!?-+^&'\";:"
66+specialChars = "\\[]*#_@~<>!?-+^&'\";:|"
67
67
68-- | Generate a Pandoc ADT from a textile document
68-- | Generate a Pandoc ADT from a textile document
69parseTextile :: GenParser Char ParserState Pandoc
69parseTextile :: GenParser Char ParserState Pandoc
@@ -82,6 +82,7 @@ blockParsers = [ codeBlock
82 , header
82 , header
83 , blockQuote
83 , blockQuote
84 , anyList
84 , anyList
85+ , table
85 , para
86 , para
86 , nullBlock ]
87 , nullBlock ]
87
88
@@ -173,6 +174,68 @@ para = try $ do
173 content <- manyTill inline blockBreak
174 content <- manyTill inline blockBreak
174 return $ Para $ normalizeSpaces content
175 return $ Para $ normalizeSpaces content
175
176
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+
176-- | Any inline element
239-- | Any inline element
177inline :: GenParser Char ParserState Inline
240inline :: GenParser Char ParserState Inline
178inline = choice inlineParsers <?> "inline"
241inline = choice inlineParsers <?> "inline"