File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ module MTable (plugin ) where
2
+
3
+ -- This plugin ideally parses a less irritating table syntax
4
+ -- for gitit.
5
+ --
6
+ -- ~~~ {.mtable}
7
+ -- | foo | bar | bop |
8
+ -- | and | so | on |
9
+ -- ~~~
10
+ --
11
+ -- Unfortuantely it still can't do colspan
12
+ --
13
+ -- Simon Heath <[email protected] > 2013
14
+
15
+ import Data.Default
16
+ import Data.List.Split
17
+ import Text.Pandoc (readMarkdown )
18
+ import Network.Gitit.Interface
19
+ import System.IO.Unsafe
20
+
21
+ plugin :: Plugin
22
+ plugin = mkPageTransformM parseTableBlock
23
+
24
+ parseTableBlock :: Block -> PluginM Block
25
+ parseTableBlock (CodeBlock (_, classes, namevals) contents) | " mtable" `elem` classes = do
26
+ let lineses = lines contents
27
+ splittedLines = map (splitOn " |" ) lineses
28
+ splittedLinesWithEmptiesRemoved = map (filter ((/=) " " )) splittedLines
29
+ parseCell x =
30
+ let res = readMarkdown def x in
31
+ case res of
32
+ Left _ -> [Para $ [Str " Error parsing markdown in cell?" ]]
33
+ Right (Pandoc _ blk) -> blk
34
+ cellify line = map (\ cell -> parseCell cell) line
35
+ cells = map cellify splittedLinesWithEmptiesRemoved
36
+ alignments = replicate (length (head cells)) AlignDefault
37
+ return $ Table [] alignments [] [] cells -- (head cells) (tail cells)
38
+
39
+ parseTableBlock x = return x
You can’t perform that action at this time.
0 commit comments