Code highlighting with line numbers

Jekyll 3 and 4 produce invalid HTML from highlighted code with line numbers. Validation of the produced HTML may report:

Error: Element table not allowed as child of element code […]

  1. Turn off HTML compression with the following setting in _config.yml:

    compress_html:
      ignore:
        envs: all
    
  2. Check that HTML validation reports no errors on this page.

  3. Remove the setting for HTML compression, to get the default compression provided by the theme.

  4. Check that HTML validation now reports an error that refers to the second example below. The error may also produce incorrect formatting.

The examples below are from a Jekyll docs page.

The first example uses the workaround explained in the theme docs:

1
2
3
def foo
  puts 'foo'
end

The second example doesn’t use the workaround:

>
1
2
3
def foo
  puts 'foo'
end