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))
Line 2,349: Line 2,349:




# wikiTableFromOutline :: [String] -> String -> String
# wikiTablesFromOutline :: [String] -> String -> String
def wikiTableFromOutline(colorSwatch):
def wikiTablesFromOutline(colorSwatch):
'''Wikitable markup for a nested (colspan) table
'''Wikitable markup for (colspan) tables representing
representing the indentation of a given outline.
the indentation of a given outline.
Each key-line point (child of the root) has a
Each key-line point (child of a tree root) has a
distinct color, inherited by all its descendants.
distinct color, inherited by all its descendants.
The first color in the swatch is for the root node.
The first color in the swatch is for the root node.
A sequence of tables is generated where the outline
represents a forest rather than a singly-rooted tree.
'''
'''
def go(s):
def go(outline):
return '\n\n'.join([
wikiTableFromTree(colorSwatch)(tree) for tree in
forestFromLevels(
indentLevelsFromLines(
outline.splitlines()
)
)
])
return go


# wikiTableFromTree :: [String] -> Tree String -> String
def wikiTableFromTree(colorSwatch):
'''A wikitable rendered from a single tree'''
def go(tree):
return compose(
return compose(
wikiTableFromRows,
wikiTableFromRows,
Line 2,363: Line 2,380:
paintedTree(colorSwatch),
paintedTree(colorSwatch),
widthMeasuredTree,
widthMeasuredTree,
fullDepthTree,
fullDepthTree
head,
)(tree)

forestFromLevels,
indentLevelsFromLines
)(
s.splitlines()
)
return go
return go


Line 2,392: Line 2,405:


print(
print(
wikiTableFromOutline([
wikiTablesFromOutline([
"#ffffe6",
"#ffffe6",
"#ffebd2",
"#ffebd2",