Display an outline as a nested table: Difference between revisions

Content added Content deleted
(→‎{{header|Go}}: Added a second example, based on the Perl 6 / zkl entries.)
Line 214: Line 214:
toNest(iNodes, 0, 0, &n)
toNest(iNodes, 0, 0, &n)
fmt.Println(toMarkup(n, cols, 4))
fmt.Println(toMarkup(n, cols, 4))

fmt.Println("\n")
const outline2 = `Display an outline as a nested table.
Parse the outline to a tree,
measuring the indent of each line,
translating the indentation to a nested structure,
and padding the tree to even depth.
count the leaves descending from each node,
defining the width of a leaf as 1,
and the width of a parent node as a sum.
(The sum of the widths of its children)
Propagating the sums upward as necessary.
and write out a table with 'colspan' values
either as a wiki table,
or as HTML.
Optionally add color to the nodes.`
cols2 := []string{blue, yellow, orange, green, pink}
var n2 nNode
iNodes2 := makeIndent(outline2, 4)
toNest(iNodes2, 0, 0, &n2)
fmt.Println(toMarkup(n2, cols2, 4))
}</lang>
}</lang>


Line 238: Line 259:
| |
| |
| style="background: #f0fff0; " colspan=1 | (The sum of the widths of its children)
| style="background: #f0fff0; " colspan=1 | (The sum of the widths of its children)
| |
| |
|}


{| class="wikitable" style="text-align: center;"
|-
| style="background: #e6ffff; " colSpan=9 | Display an outline as a nested table.
|-
| style="background: #ffffe6; " colspan=3 | Parse the outline to a tree,
| style="background: #ffebd2; " colspan=3 | count the leaves descending from each node,
| style="background: #f0fff0; " colspan=2 | and write out a table with 'colspan' values
| style="background: #ffeeff; " colspan=1 | Optionally add color to the nodes.
|-
| style="background: #ffffe6; " colspan=1 | measuring the indent of each line,
| style="background: #ffffe6; " colspan=1 | translating the indentation to a nested structure,
| style="background: #ffffe6; " colspan=1 | and padding the tree to even depth.
| style="background: #ffebd2; " colspan=1 | defining the width of a leaf as 1,
| style="background: #ffebd2; " colspan=2 | and the width of a parent node as a sum.
| style="background: #f0fff0; " colspan=1 | either as a wiki table,
| style="background: #f0fff0; " colspan=1 | or as HTML.
| |
|-
| |
| |
| |
| |
| style="background: #ffebd2; " colspan=1 | (The sum of the widths of its children)
| style="background: #ffebd2; " colspan=1 | Propagating the sums upward as necessary.
| |
| |
| |
| |