Skip to content

Commit 1b1f598

Browse files
authored
Merge pull request #593 from icefoxen/mtable-plugin
Added MTable plugin.
2 parents d0031cf + 202648b commit 1b1f598

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

plugins/MTable.hs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

0 commit comments

Comments
 (0)