10.13 Markdown, HTML and multi-format tables
The custom output layer demonstrates a useful design: one internal table can be rendered to CSV, Markdown or standalone HTML. Keeping one table model reduces the risk that presentation formats calculate different answers.
Markdown rendering
Markdown tables escape pipe characters so data do not create unintended columns, and embedded newlines are replaced for a one-row representation. Cells can carry bold emphasis, indentation and right alignment; footnotes can be appended below the table. These are presentation instructions, not additional scientific values.
Markdown is excellent for review notes, repositories and inclusion in this book. It is a weak interchange format for complex data because parser dialects vary and alignment syntax, emphasis and footnotes mingle with values.
Standalone HTML tables
The custom renderer can create a responsive standalone HTML table with light/dark styling and the originating command. This makes a table independently reviewable without a full analysis report. As with report.html, the display is not the preferred numeric API; use the corresponding CSV when available.
HTML output must escape cell text. Visual features such as bold rows or indentation should reinforce a named structure—totals, subgroups or hierarchy—and should not be the only way a machine consumer can identify it.
Choosing a format
| Need | Best starting format | Reason |
|---|---|---|
| Numeric import | CSV | Rectangular, broad tool support |
| Nested typed structure | JSON | Arrays, objects and native types |
| Repository review | Markdown | Readable diffs and inline rendering |
| Standalone human table | HTML | Responsive styling and browser support |
| Regulated archive | Machine file + rendered view | Values and reviewed presentation retained |
One-table cross-check
For a multi-format export, select difficult test cells: a comma, quote, pipe, newline, missing numeric value, negative value, long label and footnote. Confirm that each renderer preserves the logical table. Then compare row/column counts and representative values after parsing CSV and HTML/Markdown where practical.
Rendering can legitimately change alignment and escaping. It must not change grouping, rounding policy or the underlying numbers without an explicit format-specific rule.
Common mistakes
- Importing Markdown as if it were a stable data schema.
- Calculating HTML and CSV values through separate code paths.
- Using bold or indentation as the only marker of row type.
- Forgetting to test pipes and newlines in labels.
Checklist
- Design the internal table once and render outward.
- Retain a machine-readable format beside presentation formats.
- Test escaping with adversarial labels.
- State rounding and footnote rules consistently.
Further reading
See CSV conventions, HTML anatomy and the planned Chapter 13A on custom.