<commit_before>/*
 *  Title: Test whether code blocks unexpectedly contain <code> elements, which break the syntax
 *  highlighting.
 *
 *  Example 1: <pre class="brush:js"><code>var x = 1;</code></pre> is considered invalid and 
 *  should rather be written as <pre class="brush:js">var x = 1;</pre>.
 * 
 *  Implementation notes: This test checks whether <pre> elements contain <code> elements.
 */

docTests.codeInPre = {
  name: "code_in_pre",
  desc: "code_in_pre_desc",
  check: function checkCodeInPre(rootElement) {
    let codesInPres = rootElement.querySelectorAll("pre code");
    let matches = [];

    for (let i = 0; i < codesInPres.length; i++) {
      matches.push({
        node: codesInPres[i],
        msg: codesInPres[i].outerHTML,
        type: ERROR
      });
    }

    return matches;
  },
  fix: function fixCodeInPre(matches) {
    matches.forEach(match => {
      let children = new DocumentFragment();
      for(let i = 0; i < match.node.childNodes.length; i++) {
        children.appendChild(match.node.childNodes[i].cloneNode());
      }
      match.node.parentNode.replaceChild(children, match.node);
    });
  }
};<commit_msg>Deep-clone child nodes within <code> blocks, so that all contents are added when removing the wrapping <code> (issue #4)<commit_after>/*
 *  Title: Test whether code blocks unexpectedly contain <code> elements, which break the syntax
 *  highlighting.
 *
 *  Example 1: <pre class="brush:js"><code>var x = 1;</code></pre> is considered invalid and 
 *  should rather be written as <pre class="brush:js">var x = 1;</pre>.
 * 
 *  Implementation notes: This test checks whether <pre> elements contain <code> elements.
 */

docTests.codeInPre = {
  name: "code_in_pre",
  desc: "code_in_pre_desc",
  check: function checkCodeInPre(rootElement) {
    let codesInPres = rootElement.querySelectorAll("pre code");
    let matches = [];

    for (let i = 0; i < codesInPres.length; i++) {
      matches.push({
        node: codesInPres[i],
        msg: codesInPres[i].outerHTML,
        type: ERROR
      });
    }

    return matches;
  },
  fix: function fixCodeInPre(matches) {
    matches.forEach(match => {
      let children = new DocumentFragment();
      for(let i = 0; i < match.node.childNodes.length; i++) {
        children.appendChild(match.node.childNodes[i].cloneNode(true));
      }
      match.node.parentNode.replaceChild(children, match.node);
    });
  }
};
{'fraction_non_alphanumeric': 0.13638236505974455, 'fraction_numerical': 0.004532344458178822, 'mean_word_length': 3.2596491228070175, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4300233', 'n_tokens_mistral': 760, 'n_tokens_neox': 737, 'n_words': 202}