Jump to content

Display an outline as a nested table: Difference between revisions

m
syntax highlighting fixup automation
m (J: better contrast)
m (syntax highlighting fixup automation)
Line 82:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">outline2table(db, Delim:= "`t"){
oNum:=[], oMID:=[], oNod := [], oKid := [], oPnt := [], oMbr := [], oLvl := []
oCrl := ["#ffffe6;", "#ffebd2;", "#f0fff0;", "#e6ffff;", "#ffeeff;"]
Line 211:
return [html, wTable]
}
</syntaxhighlight>
</lang>
Examples:<langsyntaxhighlight AutoHotkeylang="autohotkey">db =
(
Display an outline as a nested table.
Line 233:
Gui, Show
MsgBox % "HTML:`n" result.1 "`n`nWikitable:`n" result.2
return</langsyntaxhighlight>
{{out}}
HTML:
Line 292:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 445:
toNest(iNodes2, 0, 0, &n2)
fmt.Println(toMarkup(n2, cols2, 4))
}</langsyntaxhighlight>
 
{{out}}
Line 503:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">{-# LANGUAGE TupleSections #-}
 
module OutlineTree where
Line 644:
<> "style=\"text-align: center;\"\n|-\n"
<> intercalate "|-\n" (wikiRow <$> rows)
<> "|}"</langsyntaxhighlight>
{{Out}}
{| class="wikitable" style="text-align: center;"
Line 675:
Implementation:
 
<langsyntaxhighlight Jlang="j">depth=: (i.~ ~.)@(0 i."1~' '=];._2)
tree=: (i: 0>.<:@{:)\
width=: {{NB. y is tree
Line 707:
end.
r=.r,'|}',LF
}}</langsyntaxhighlight>
 
Given the task example outline:
 
<langsyntaxhighlight Jlang="j">outline=:{{)n
Display an outline as a nested table.
Parse the outline to a tree,
Line 724:
either as a wiki table,
or as HTML.
}}</langsyntaxhighlight>
 
Generated output from <tt>task outline</tt> was:
Line 754:
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">(() => {
"use strict";
 
Line 1,299:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
{| class="wikitable" style="text-align:center;"
Line 1,327:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using DataFrames
 
text = """
Line 1,404:
textplus = text * " Optionally add color to the nodes."
htmlfromdataframe(processtable(textplus))
</langsyntaxhighlight>{{out}}
<h4>A Rosetta Code Nested Table</h4><table style="width:100%" class="wikitable" >
<tr>
Line 1,479:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">s = "Display an outline as a nested table.
Parse the outline to a tree,
measuring the indent of each line,
Line 1,598:
]
AppendTo[str, "</table>"];
StringRiffle[str, "\n"]</langsyntaxhighlight>
{{out}}
<pre><table style='text-align: center;'>
Line 1,631:
=={{header|Nim}}==
 
<langsyntaxhighlight Nimlang="nim">import strutils
 
const Outline = """Display an outline as a nested table.
Line 1,800:
nodelists.writeWikiTable()
echo "HTML:"
nodelists.writeHtml()</langsyntaxhighlight>
 
{{out}}
Line 1,859:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
Line 1,913:
and write out a table with 'colspan' values
either as a wiki table,
or as HTML.</langsyntaxhighlight>
{{out}}
<table border=1 cellspacing=0>
Line 1,946:
=={{header|Phix}}==
Can output in either html or wikitable markup
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">html</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span><span style="color: #0000FF;">,</span>
Line 2,063:
<span style="color: #000000;">markup</span><span style="color: #0000FF;">(</span><span style="color: #000000;">outlines</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span><span style="color: #000000;">colours</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
in html:
Line 2,184:
=={{header|Python}}==
===Python: Procedural===
<langsyntaxhighlight lang="python">"""Display an outline as a nested table. Requires Python >=3.6."""
 
import itertools
Line 2,452:
table_format = "wiki"
 
example(table_format)</langsyntaxhighlight>
{{out}}
 
Line 2,514:
 
===Python: Functional===
<langsyntaxhighlight lang="python">'''Display an outline as a nested table'''
 
from itertools import chain, cycle, takewhile
Line 2,877:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
{| class="wikitable" style="text-align: center;"
Line 2,911:
Strictly speaking, this is not a nested table. It is just a single level table that has some column spans > 1. For an example of using actual nested tables, see the task entry: [[Rosetta_Code/List_authors_of_task_descriptions#Raku|List_authors_of_task_descriptions#Raku]], [[Rosetta_Code/List_authors_of_task_descriptions/Full_list|(and full output)]].
 
<syntaxhighlight lang="raku" perl6line>my $outline = q:to/END/;
Display an outline as a nested table.
Parse the outline to a tree,
Line 3,055:
}
( $r, $g, $b ).map( ((*+$m) * 255).Int)».base(16).join
}</langsyntaxhighlight>
 
{{out}}
Line 3,123:
{{libheader|Wren-dynamic}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "/dynamic" for Struct
import "/fmt" for Fmt
 
Line 3,271:
var iNodes2 = makeIndent.call(outline2, 4)
toNest.call(iNodes2, 0, 0, n2)
System.print(toMarkup.call(n2, cols2, 4))</langsyntaxhighlight>
 
{{out}}
Line 3,329:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn parseOutline(outline){ //--> "tree" annotated with spans
var [const] indent=" "*100; // no tabs
 
Line 3,392:
out.writeln("|}");
out.text
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">outlineText:=Data(Void,
#<<<
"Display an outline as a nested table.
Line 3,411:
 
rows,cols,title,trees := parseOutline(outlineText);
makeMarkup(rows,cols,title,trees).println();</langsyntaxhighlight>
{{out}}
{| class="wikitable" style="text-align: center;"
Line 3,437:
 
And the Raku example:
<langsyntaxhighlight lang="zkl">outlineText:=Data(Void,
#<<<
"Display an outline as a nested table.
Line 3,457:
 
rows,cols,title,trees := parseOutline(outlineText);
makeMarkup(rows,cols,title,trees).println();</langsyntaxhighlight>
{{out}}
{| class="wikitable" style="text-align: center;"
10,333

edits

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