Display an outline as a nested table: Difference between revisions

Content added Content deleted
(→‎Python: Functional: Adjusted to allow for outlines with more than one root (forests, rather than trees))
(→‎{{header|Haskell}}: Updated to allow for writing several tables, where outline has several top-level roots)
Line 513: Line 513:
import Data.Tree (Tree (..), foldTree, levels)
import Data.Tree (Tree (..), foldTree, levels)


---------------- NESTED TABLE FROM OUTLINE ---------------
---------------- NESTED TABLES FROM OUTLINE --------------


wikiTableFromOutline :: [String] -> String -> String
wikiTablesFromOutline :: [String] -> String -> String
wikiTableFromOutline colorSwatch =
wikiTablesFromOutline colorSwatch outline =
intercalate "\n\n" $
wikiTableFromTree colorSwatch
<$> ( forestFromLineIndents
. indentLevelsFromLines
. lines
)
outline

wikiTableFromTree :: [String] -> Tree String -> String
wikiTableFromTree colorSwatch =
wikiTableFromRows
wikiTableFromRows
. levels
. levels
Line 522: Line 532:
. widthLabelledTree
. widthLabelledTree
. (paddedTree [] =<< treeDepth)
. (paddedTree [] =<< treeDepth)
. head -- Just the first tree of any forest
. forestFromLineIndents
. indentLevelsFromLines
. lines


--------------------------- TEST -------------------------
--------------------------- TEST -------------------------
Line 531: Line 537:
main =
main =
( putStrLn
( putStrLn
. wikiTableFromOutline
. wikiTablesFromOutline
[ "#ffffe6",
[ "#ffffe6",
"#ffebd2",
"#ffebd2",