File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -50,4 +50,14 @@ showTable header types rows =
5050 border = T. intercalate " ---" [T. replicate width (T. singleton ' -' ) | width <- widths]
5151 separator = T. intercalate " -|-" [T. replicate width (T. singleton ' -' ) | width <- widths]
5252 fillCols fill cols = T. intercalate " | " [fill c width col | (c, width, col) <- zip3 cs widths cols]
53- in T. unlines $ border : fillCols colTitleFill header : separator : fillCols colTitleFill types : separator : map (fillCols colValueFill) rows
53+ in T. unlines $ border : fillCols colTitleFill header : separator : fillCols colTitleFill types : separator : map (fillCols colValueFill) rows
54+
55+ showTableProperMarkdown :: [T. Text ] -> [T. Text ] -> [[T. Text ]] -> T. Text
56+ showTableProperMarkdown header types rows =
57+ let headerWithTypes = zipWith (\ h t -> h <> " <br>" <> t) header types
58+ cs = map (\ h -> ColDesc center h left) headerWithTypes
59+ widths = [maximum $ map T. length col | col <- transpose $ headerWithTypes : rows]
60+ border = T. intercalate " ---" [T. replicate width (T. singleton ' -' ) | width <- widths]
61+ separator = T. intercalate " -|-" [T. replicate width (T. singleton ' -' ) | width <- widths]
62+ fillCols fill cols = T. intercalate " | " [fill c width col | (c, width, col) <- zip3 cs widths cols]
63+ in T. unlines $ border : fillCols colTitleFill headerWithTypes : separator : map (fillCols colValueFill) rows
Original file line number Diff line number Diff line change @@ -39,10 +39,10 @@ instance Eq DataFrame where
3939
4040instance Show DataFrame where
4141 show :: DataFrame -> String
42- show d = T. unpack (asText d)
42+ show d = T. unpack (asText d False )
4343
44- asText :: DataFrame -> T. Text
45- asText d =
44+ asText :: DataFrame -> Bool -> T. Text
45+ asText d properMarkdown =
4646 let header = " index" : map fst (sortBy (compare `on` snd ) $ M. toList (columnIndices d))
4747 types = V. toList $ V. filter (/= " " ) $ V. map getType (columns d)
4848 getType Nothing = " "
@@ -68,7 +68,7 @@ asText d =
6868 rows =
6969 transpose $
7070 zipWith (curry (V. toList . getTextColumnFromFrame d)) [0 .. ] header
71- in showTable header (" Int" : types) rows
71+ in ( if properMarkdown then showTableProperMarkdown else showTable) header (" Int" : types) rows
7272
7373-- | O(1) Creates an empty dataframe
7474empty :: DataFrame
You can’t perform that action at this time.
0 commit comments