From 5ffca36b842c2b4351b4671100a03d5189df3870 Mon Sep 17 00:00:00 2001 From: BBaoVanC Date: Sat, 23 Apr 2022 17:54:05 -0500 Subject: [PATCH] Add table formatting, requires using custom "table" shortcode --- assets/css/bobastyle.css | 21 +++++++++++++++++++++ layouts/shortcodes/table.html | 10 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 layouts/shortcodes/table.html diff --git a/assets/css/bobastyle.css b/assets/css/bobastyle.css index 45358b5..5e3cb0e 100644 --- a/assets/css/bobastyle.css +++ b/assets/css/bobastyle.css @@ -436,6 +436,27 @@ hr { border-color: var(--background-5); } +table.markdown { + border-collapse: collapse; + border: 2px solid var(--text-normal); +} + +.markdown thead { + background-color: var(--background-4); +} + +.markdown th, +.markdown td { + padding: 8px; +} + +.markdown tbody tr:nth-child(odd) { + background-color: var(--background); +} +.markdown tbody tr:nth-child(even) { + background-color: var(--background-2); +} + * { box-sizing: border-box; } diff --git a/layouts/shortcodes/table.html b/layouts/shortcodes/table.html new file mode 100644 index 0000000..3a43ab0 --- /dev/null +++ b/layouts/shortcodes/table.html @@ -0,0 +1,10 @@ +{{/* See https://willschenk.com/articles/2020/styling_tables_with_hugo/ */}} + +{{ $class := "markdown" }} +{{ with .Get "class" }} + {{ $class = delimit (slice $class .) " " }} +{{ end }} + +{{ $htmlTable := .Inner | markdownify }} +{{ $new := printf `` $class }} +{{ (replace $htmlTable "
" $new) | safeHTML }}