Jump to content

Display an outline as a nested table: Difference between revisions

m
(→‎{{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 s =
head
. forestFromLineIndents
. indentLevelsFromLines
$. lines s
 
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
<> "| "
<> txt
cw color width =
let go w
Line 645 ⟶ 642:
<> "style=\"text-align: center;\"\n|-\n"
<> intercalate "|-\n" (wikiRow <$> rows)
<> "|}"</lang>
</lang>
{{Out}}
{| class="wikitable" style="text-align: center;"
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.