<commit_before>// Displays the HTML source of a CodeMirror editor as a rendered preview
// in an iframe.
define(["jquery", "backbone-events", "./mark-tracker"], function($, BackboneEvents, markTracker) {
  "use strict";

  function LivePreview(options) {
    var self = {codeMirror: options.codeMirror, title: ""},
        codeMirror = options.codeMirror,
        iframe = document.createElement("iframe"),
        previewLoader = options.previewLoader || "/templates/previewloader.html",
        previewArea = options.previewArea,
        marks = markTracker(codeMirror),
        telegraph, // communication channel to the preview iframe
        knownDoc;  // the latest known document generated by slowparse

    // event listening for proxied event messages from our preview iframe.
    function listenForEvents() {
      window.addEventListener("message", function(evt) {
        var message = JSON.parse(evt.data);
        if (typeof message.type !== "string" || message.type.indexOf("previewloader") === -1) {
          return;
        }
        marks.clear();
        var route = message.route.slice();
        if(route.length > 0) {
          var e = knownDoc.querySelector("body");
          while(route.length > 0) {
            e = e.childNodes[route.splice(0,1)[0]];
          }
          var start = e.parseInfo.openTag.start,
              end = e.parseInfo.closeTag.end;
          marks.mark(start, end, "preview-to-editor-highlight");
          if (message.type === "previewloader:click") {
            codeMirror.scrollIntoView(codeMirror.posFromIndex(start));
          }
        }
      });
    }

    // set up the iframe so that it always triggers an initial
    // content injection by telling codemirror to reparse on load:
    iframe.onload = function() {
      codeMirror.reparse();
    };

    // then set up the preview load from URL
    iframe.src = previewLoader;

    // set up the code-change handling.
    codeMirror.on("reparse", function(event) {
      if (!event.error || options.ignoreErrors) {
        // add the preview iframe to the editor on the first
        // attempt to parse the Code Mirror text.
        if(!iframe.contentWindow) {<commit_msg>fixed highlight for close-tag-less elements<commit_after>// Displays the HTML source of a CodeMirror editor as a rendered preview
// in an iframe.
define(["jquery", "backbone-events", "./mark-tracker"], function($, BackboneEvents, markTracker) {
  "use strict";

  function LivePreview(options) {
    var self = {codeMirror: options.codeMirror, title: ""},
        codeMirror = options.codeMirror,
        iframe = document.createElement("iframe"),
        previewLoader = options.previewLoader || "/templates/previewloader.html",
        previewArea = options.previewArea,
        marks = markTracker(codeMirror),
        telegraph, // communication channel to the preview iframe
        knownDoc;  // the latest known document generated by slowparse

    // event listening for proxied event messages from our preview iframe.
    function listenForEvents() {
      window.addEventListener("message", function(evt) {
        var message = JSON.parse(evt.data);
        if (typeof message.type !== "string" || message.type.indexOf("previewloader") === -1) {
          return;
        }
        marks.clear();
        var route = message.route.slice();
        if(route.length > 0) {
          var e = knownDoc.querySelector("body");
          while(route.length > 0) {
            e = e.childNodes[route.splice(0,1)[0]];
          }
          var parseInfo = e.parseInfo,
              start = parseInfo.openTag.start,
              end = (parseInfo.closeTag ? parseInfo.closeTag.end : parseInfo.openTag.end);
          marks.mark(start, end, "preview-to-editor-highlight");
          if (message.type === "previewloader:click") {
            codeMirror.scrollIntoView(codeMirror.posFromIndex(start));
          }
        }
      });
    }

    // set up the iframe so that it always triggers an initial
    // content injection by telling codemirror to reparse on load:
    iframe.onload = function() {
      codeMirror.reparse();
    };

    // then set up the preview load from URL
    iframe.src = previewLoader;

    // set up the code-change handling.
    codeMirror.on("reparse", function(event) {
      if (!event.error || options.ignoreErrors) {
        // add the preview iframe to the editor on the first
        // attempt to parse the Code Mirror text.
        if(!iframe.contentWindow) {
{'fraction_non_alphanumeric': 0.11625835189309577, 'fraction_numerical': 0.0026726057906458797, 'mean_word_length': 2.4922239502332815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '243281', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1189, 'n_words': 342}