Published
Edited
Jun 9, 2019
4 stars
Insert cell
Insert cell
Insert cell
Handlebars = {
const hb = await require('handlebars@4.1.2/dist/handlebars.min.js');
// Register a helper.
// n is the argument, block the inner content.
hb.registerHelper('times', (n, block) => {
let s = '', i = n;
while(i-- > 0) s += block.fn(i);
return s;
});
return hb;
}
Insert cell
Insert cell
table_hbs = Handlebars.compile(`
<table>
{{#if headers}}
<thead>
<tr>{{#each headers}}<th>{{@this}}</th>{{/each}}</tr>
</thead>
{{/if}}

<tbody>
{{#each rows}}
<tr>{{#each @this}}<td>{{{@this}}}</td>{{/each}}</tr>
{{/each}}
</tbody>
</table>
`)
Insert cell
Insert cell
choochoo_hbs = Handlebars.compile(`
🚂{{#times size}}🚃{{/times}}{{#if late ~}}
{{#times late ~}}&nbsp;{{/times}}🏃
{{/if}}
`)
Insert cell
Insert cell
md`
### Departures

${table_hbs({headers: ['Train', 'Status'], rows: [
['Train 1', choochoo_hbs({size: 5})],
['<span style=color:red>Train 2</span>', choochoo_hbs({size: 3, late: 55})],
['Train 3', choochoo_hbs({size: 8})],
]})}
`
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more