From 9dc96375831b21e845c0993c258314e69d6da774 Mon Sep 17 00:00:00 2001 From: Simon Lenz Date: Mon, 11 Jul 2022 17:49:23 +0200 Subject: [PATCH 1/4] Implement heading --- plugins/InfoBox.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/InfoBox.hs b/plugins/InfoBox.hs index 75488bf..430a864 100644 --- a/plugins/InfoBox.hs +++ b/plugins/InfoBox.hs @@ -76,6 +76,12 @@ serializeRowToHTML :: TableRowData -> String serializeRowToHTML (HeadingRowData label) = "" ++ label ++ "\n" serializeRowToHTML (FieldRowData label value) = "" ++ label ++ "" ++ value ++ "\n" +serializeToBlock :: InfoBoxData -> Block +serializeToBlock infoBoxData = + Div ("", ["info-box"], []) [ + Header 2 ("", [], []) [(Str . pack) (title infoBoxData)] + ] + plugin :: Plugin plugin = mkPageTransform transformBlock @@ -114,7 +120,7 @@ plugin = mkPageTransform transformBlock transformBlock :: Block -> Block transformBlock (CodeBlock (_, classes, namevals) contents) | "infobox" `elem` classes = traceShow parsed - serializeToHTML parsed + serializeToBlock parsed where parsed = (parse (unpack contents)) transformBlock x = x From d0d0b4a4514d63b58aef33dac26bf9c2b57101e6 Mon Sep 17 00:00:00 2001 From: Simon Lenz Date: Mon, 11 Jul 2022 17:52:17 +0200 Subject: [PATCH 2/4] Use nullAttr --- plugins/InfoBox.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/InfoBox.hs b/plugins/InfoBox.hs index 430a864..003f160 100644 --- a/plugins/InfoBox.hs +++ b/plugins/InfoBox.hs @@ -79,7 +79,7 @@ serializeRowToHTML (FieldRowData label value) = "" ++ label ++ " Block serializeToBlock infoBoxData = Div ("", ["info-box"], []) [ - Header 2 ("", [], []) [(Str . pack) (title infoBoxData)] + Header 2 nullAttr [(Str . pack) (title infoBoxData)] ] plugin :: Plugin From dd33cda475fba85c4b99a7d37253c5bd9fea0e6e Mon Sep 17 00:00:00 2001 From: Simon Lenz Date: Mon, 11 Jul 2022 19:01:29 +0200 Subject: [PATCH 3/4] Add image as simple figure --- plugins/InfoBox.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/InfoBox.hs b/plugins/InfoBox.hs index 003f160..a270c0a 100644 --- a/plugins/InfoBox.hs +++ b/plugins/InfoBox.hs @@ -79,7 +79,14 @@ serializeRowToHTML (FieldRowData label value) = "" ++ label ++ " Block serializeToBlock infoBoxData = Div ("", ["info-box"], []) [ - Header 2 nullAttr [(Str . pack) (title infoBoxData)] + Header 2 nullAttr [(Str . pack) (title infoBoxData)], + SimpleFigure + nullAttr + [Str (pack (maybe "" (\x -> x) (imageCaption infoBoxData)))] + ( + pack (maybe "" (\x -> x) (imageURL infoBoxData)), + "" + ) ] plugin :: Plugin From ec956b5f7d862920233ed9e39a68ab94c4267ea2 Mon Sep 17 00:00:00 2001 From: Simon Lenz Date: Mon, 11 Jul 2022 23:48:26 +0200 Subject: [PATCH 4/4] Add table rendering --- plugins/InfoBox.hs | 75 ++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/plugins/InfoBox.hs b/plugins/InfoBox.hs index a270c0a..b081673 100644 --- a/plugins/InfoBox.hs +++ b/plugins/InfoBox.hs @@ -76,6 +76,40 @@ serializeRowToHTML :: TableRowData -> String serializeRowToHTML (HeadingRowData label) = "" ++ label ++ "\n" serializeRowToHTML (FieldRowData label value) = "" ++ label ++ "" ++ value ++ "\n" +serializeRowsToTableBodies :: [TableRowData] -> [TableBody] +serializeRowsToTableBodies [] = [] +serializeRowsToTableBodies (x:xs) = serializeRowToTableBodies x (serializeRowsToTableBodies xs) + +serializeRowToTableBodies :: TableRowData -> [TableBody] -> [TableBody] +serializeRowToTableBodies (HeadingRowData label) result = result ++ [ + ( + TableBody + nullAttr + (RowHeadColumns 1) + [ + Row nullAttr [ + Cell nullAttr AlignCenter (RowSpan 1) (ColSpan 2) [Plain [((Str . pack) label)]] + ] + ] + [] + ) + ] +serializeRowToTableBodies (FieldRowData label value) result = (init result) ++ [ + ( + addBodyRow + (last result) + ( + Row nullAttr [ + Cell nullAttr AlignLeft (RowSpan 1) (ColSpan 1) [Plain [((Str . pack) label)]], + Cell nullAttr AlignLeft (RowSpan 1) (ColSpan 1) [Para [(Str (pack value))]] + ] + ) + ) + ] + +addBodyRow :: TableBody -> Row -> TableBody +addBodyRow (TableBody attr rhc headRows bodyRows) row = TableBody attr rhc headRows (bodyRows ++ [row]) + serializeToBlock :: InfoBoxData -> Block serializeToBlock infoBoxData = Div ("", ["info-box"], []) [ @@ -86,44 +120,19 @@ serializeToBlock infoBoxData = ( pack (maybe "" (\x -> x) (imageURL infoBoxData)), "" - ) + ), + Table + nullAttr + (Caption Nothing []) + [(AlignLeft,ColWidthDefault), (AlignLeft,ColWidthDefault)] + (TableHead nullAttr []) + (serializeRowsToTableBodies (reverse (tableRows infoBoxData))) + (TableFoot nullAttr []) ] plugin :: Plugin plugin = mkPageTransform transformBlock - -- return $ Table - -- ("ttable", [], []) - -- (Caption (Just [(Str "some caption")]) []) - -- [(AlignLeft,ColWidth 20), (AlignLeft,ColWidthDefault)] - -- (TableHead ("thead", [], []) [ - -- Row ("theadrow1", [], []) [ - -- Cell ("theadcell1", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "Header col 1")]] - -- ] - -- ]) - -- [TableBody ("tbody1", [], []) (RowHeadColumns 0) [ - -- Row ("trow1.1", [], []) [ - -- Cell ("tcell1.1a", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "content cell1.1a"), (Str "2nd content cell1.1")]] - -- ], - -- Row ("trow1.2", [], []) [ - -- Cell ("tcell1.2a", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "content cell1.2a")]], - -- Cell ("tcell1.2b", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "content cell1.2b")]] - -- ], - -- Row ("trow1.3", [], []) [ - -- Cell ("tcell1.3a", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "content cell1.3a")]], - -- Cell ("tcell1.3b", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "content cell1.3b")]] - -- ] - -- ] [ - -- Row ("trow2.1", [], []) [ - -- Cell ("tcell2.1a", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "content cell2.1a")]], - -- Cell ("tcell2.1b", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "content cell2.1b")]] - -- ], - -- Row ("trow2.2", [], []) [ - -- Cell ("tcell2.2a", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "content cell2.2a")]], - -- Cell ("tcell2.2b", [], []) AlignLeft (RowSpan 1) (ColSpan 1) [Plain [(Str "content cell2.2b")]] - -- ] - -- ]] - -- (TableFoot ("tfoot", [], []) []) transformBlock :: Block -> Block transformBlock (CodeBlock (_, classes, namevals) contents) | "infobox" `elem` classes = traceShow parsed