Render hooks for tables?

Currently, we have render-hooks for images, anchor tags, and headings. Are there any plans for implementing render-hooks for tables as well?

I use Bootstrap and tables in Bootstrap need to have classes like “table”, “table-*” for styling them. For now, I made a shortcode as a hack to apply these classes to .Inner. But I feel it would be really great if we had render-hooks for tables as well.

{{ .Inner | markdownify | replaceRE "<table>" (printf `<table class="table %s">` (.Get 0 | default "")) | safeHTML }}

I “fixed” this requirement by creating a class “prose” for my content. That prose class then is receiving all the classes required in the SCSS, something like this:

.prose {
table {
  .dark & {
    @extend .table-dark;
  }

  .light & {
    @extend .table-light;
  }

  @extend .table;
  @extend .table-sm;
}
}

I think a render hook would be great, but will be hard to implement, because it requires more than just one single loop around the code (as in <a>something</a>) for headers/footers, rows and definitions for instance for column span, width etc…

If you simply need to apply one or more classes to the <table> element…

config.toml

[markup.goldmark.parser.attribute]
block = true

markdown

Name|Type
:--|:--
Spot|Dog
Felix|Cat
{.table .foo}
6 Likes

I don’t get why it should be difficult, given that tables end up rendered anyway so hugo knows the bonds of the object, doesn’t it?

The reason why we haven’t done this is not about how hard it would be to implement. The render hooks comes with a significant performance cost meaning the hooks needs to add significant value (which is the case for links, images and headings).

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.