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