Markdown: Nokogiri RuntimeError: Cannot replace a node with no parent

Problem is that <pre> blocks with multiple <code> nodes will fail. Such as

<pre><code>something</code> and <code>another</code></pre>

This is not a valid block to syntax highlight anyway, and should be ignored.


https://sentry.gitlab.net/gitlab/gitlabcom/issues/3093268/?referrer=gitlab_plugin

RuntimeError: Cannot replace a node with no parent
  lib/banzai/filter/syntax_highlight_filter.rb:115:in `replace_parent_pre_element'
    node.parent.replace(highlighted)
  lib/banzai/filter/syntax_highlight_filter.rb:67:in `highlight_node'
    replace_parent_pre_element(node, highlighted)
  lib/banzai/filter/syntax_highlight_filter.rb:22:in `block in call'
    highlight_node(node)
  lib/banzai/filter/syntax_highlight_filter.rb:21:in `call'
    doc.xpath(XPATH).each do |node|
  lib/banzai/pipeline/base_pipeline.rb:23:in `block (2 levels) in singleton class'
    html_pipeline.__send__(meth, text, context) # rubocop:disable GitlabSecurity/PublicSend
...
(229 additional frame(s) were not displayed)
Edited by Brett Walker