Display an outline as a nested table: Difference between revisions
Display an outline as a nested table (view source)
Revision as of 22:20, 5 September 2021
, 2 years ago→{{header|Haskell}}
(→{{header|Haskell}}: Added a draft in Haskell) |
|||
Line 512:
import Data.List (find, intercalate)
import Data.Tree (Tree (..), foldTree, levels)
---------------- NESTED TABLE FROM OUTLINE ---------------
Line 524 ⟶ 523:
. (paddedTree [] =<< treeDepth)
. treeFromOutline
--------------------------- TEST -------------------------
Line 550 ⟶ 548:
\ either as a wiki table,\n\
\ or as HTML."
------------- TREE STRUCTURE FROM NESTED TEXT ------------
treeFromOutline :: String -> Tree String
treeFromOutline
head
. forestFromLineIndents
. indentLevelsFromLines
forestFromLineIndents :: [(Int, String)] -> [Tree String]
Line 574 ⟶ 571:
indentUnit = maybe 1 fst (find ((0 <) . fst) pairs)
in first (`div` indentUnit) <$> pairs
---------------- TREE PADDED TO EVEN DEPTH ---------------
Line 597 ⟶ 593:
go _ [] = 1
go _ xs = (succ . maximum) xs
----------------- SUBTREE WIDTHS MEASURED ----------------
Line 609 ⟶ 604:
(x, foldr ((+) . snd . rootLabel) 0 xs)
xs
------------------- COLOR SWATCH APPLIED -----------------
Line 623 ⟶ 617:
(subForest tree)
)
-------------------- WIKITABLE RENDERED ------------------
Line 632 ⟶ 625:
cellText (color, (txt, width))
| null txt = "| |"
| otherwise =
"| "
<> cw color width
<> "| "
<> txt
cw color width =
let go w
Line 645 ⟶ 642:
<> "style=\"text-align: center;\"\n|-\n"
<> intercalate "|-\n" (wikiRow <$> rows)
<> "|}"</lang>
{{Out}}
{| class="wikitable" style="text-align: center;"
|