Bootstrap Table
A Hugo shortcode to style Markdown tables to be human-readable with Bootstrap classes.
- Requires Bootstrap CSS framework on your site.
# file.md
{{< bootstrap_table "table table-dark table-striped table-bordered" >}}
| | Marginal Units | Unit Price ($) |
| ----------- | ----------- |----------- |
| For the first | 5 | $10 |
| For the next | 10 | $7 |
| For the next | ∞ | $5 |
{{< /bootstrap_table >}}
# bootstrap_table.html
{{ $htmlTable := .Inner | markdownify }}
{{ $class := .Get 0 | default "" }}
{{ $old := "<table>" }}
{{ $new := printf "<table class=\"%s\">" $class }}
{{ $htmlTable := replace $htmlTable $old $new }}
{{ $htmlTable | safeHTML }}
Marginal Units | Unit Price ($) | |
---|---|---|
For the first | 5 | $10 |
For the next | 10 | $7 |
For the next | ∞ | $5 |
Source: Zach Betz