EmbeddedJSPlugin Table API

This page describes the usage of EJS Table API of EmbeddedJSPlugin. See also EJS API List.

parseTable

parseTable(
 "| *A* | *B* |\n" +
 "| 1 | 2 |\n" +
 "| 3 | 4 |\n"
);
/*
Returns: {
 fields: ['A', 'B'],
 rows: [
 {A: 1, B: 2},
 {A: 3, B: 4}
 ],
}
*/

parseTable(
 "| 1 | 2 |\n" +
 "| 3 | 4 |\n",
 {header: false}
);
/*
Returns: [
 [1, 2],
 [3, 4]
]
*/

parseTable(
 "| *A* | *B* |\n" +
 "| 1 | 2 |\n" +
 "| 3 | 4 |\n",
 {header: true, fields: ['Foo', 'Bar']}
);
/*
Returns: {
 fields: ['Foo', 'Bar'],
 rows: [
 {Foo: 1, Bar: 2},
 {Foo: 3, Bar: 4}
 ],
}
*/

parseTable(
 "| 1 | 2 |\n" +
 "| 3 | 4 |\n",
 {header: false, fields: ['Foo', 'Bar']}
);
/*
Returns: {
 fields: ['Foo', 'Bar'],
 rows: [
 {Foo: 1, Bar: 2},
 {Foo: 3, Bar: 4}
 ],
}
*/

parseTable(
 "| *A* | *B* |\n" +
 "| 1 | 2 |\n" +
 "| 3 | 4 |\n",
 {fields: ['Foo', 'Bar']}
 function (row) {
 println(formatText("---++ Foo: $Foo", row));
 println(formatText("Bar: $Bar", row));
 }
);
/*
Prints:
---++ Foo: 1
Bar: 2
---++ Foo: 3
Bar: 4
*/

formatTable

formatTable({
 fields: ['A', 'B'],
 rows: [
 {A: 1, B: 2},
 {A: 3, B: 4}
 ]
});
/*
Returns:
| *A* | *B* |
| 1 | 2 |
| 3 | 4 |
*/

formatTable({
 fields: ['A', 'B'],
 rows: [
 {A: 1, B: 2},
 {A: 3, B: 4}
 ]
}, {header: false});
/*
Returns:
| 1 | 2 |
| 3 | 4 |
*/

formatTable([
 [1, 2],
 [3, 4]
]);
/*
Returns:
| 1 | 2 |
| 3 | 4 |
*/

formatTable({
 fields: ['Foo', 'Bar'],
 rows: [
 {Foo: 1, Bar: 2},
 {Foo: 3, Bar: 4}
 ]
}, function (row) {
 row.Bar = '%RED%' + row.Bar + '%ENDCOLOR%';
 return row;
});
/*
Returns:
| *Foo* | *Bar* |
| 1 | %RED%2%ENDCOLOR% |
| 3 | %RED%4%ENDCOLOR% |
*/

Special Characters

The EmbeddedJSPlugin Table API treats the following character sequences in the special ways:

Sequence Descrpition
%VBAR% The vertical bar (|)
0円 Null byte
\n Line feed
\r Carriage return
\t Tab
\b Backspace
\f Form feed
\v Vertical tab
\\ Backslash literal (\)

When formatting and parsing a table, it escapes and unescapes these sequences in addition to HTML entities. (escapeTable() and unescapeTable())

// Topic name: TestTable
| <%VBAR%gt;\n |
<!-- Note: \n is encoded as a backslash followed by n -->
// EJS Code
var table = parseTable(readTopic("TestTable"), {header: false});
table[0][0] == "<|>\n"; // Note: \n is the actual line break
formatTable(table); // returns the same text as TestTable
Edit | Attach | (削除) Watch (削除ここまで) | Print version | History : r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2018年04月20日 - PeterThoeny
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

AltStyle によって変換されたページ (->オリジナル) /