Skip to content

Instantly share code, notes, and snippets.

@kinoute
Created April 21, 2021 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinoute/c2db61fa6549f474948a5c3937efde9f to your computer and use it in GitHub Desktop.
Save kinoute/c2db61fa6549f474948a5c3937efde9f to your computer and use it in GitHub Desktop.
Add a wrapper around tables to allow overflow on Jekyll websites
.table-wrapper {
overflow: auto;
padding-top: 10px;
padding-bottom: 10px;
}
# _plugins/table_wrapper.rb
Jekyll::Hooks.register :documents, :post_render do |doc|
doc.output.gsub! /<table>/, '<div class="table-wrapper" markdown="block"><table>'
doc.output.gsub! /<\/table>/, '</table></div>'
end
@electronicayciencia
Copy link

electronicayciencia commented Nov 12, 2023

For GitHub pages users, with no support for custom plugins: you can get the same effect using Liquid's replace.

{{ content | 
    replace: '<table>', '<div class="table-wrapper" markdown="block"><table>' |
    replace: '</table>', '</table></div>' }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment