How to use the diff.diffWordsWithSpace function in diff

To help you get started, we’ve selected a few diff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Khan / OpenResponses / lib / components / slate-rich-editor.js View on Github external
decorateNode: (text, node) => {
          if (!this.props.diffBase) {
            return;
          }

          const baseDocument = Slate.Value.fromJSON(
            JSON.parse(this.props.diffBase.rawData),
          ).document;
          const currentDocument = this.state.state.document;
          const diffs = diffWordsWithSpace(
            baseDocument.text,
            currentDocument.text,
          );

          let characters = text.characters.asMutable();

          let index = 0;
          const document = this.state.state.document;
          for (let diff of diffs) {
            if (diff.removed) {
              continue;
            }
            if (diff.added) {
              for (
                let characterIndex = index;
                characterIndex < index + diff.value.length;
github rtfpessoa / diff2html / src / printer-utils.js View on Github external
first: {
          prefix: linePrefix1,
          line: utils.escape(unprefixedLine1)
        },
        second: {
          prefix: linePrefix2,
          line: utils.escape(unprefixedLine2)
        }
      };
    }

    let diff;
    if (config.diffStyle === "char") {
      diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2);
    } else {
      diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2);
    }

    let highlightedLine = "";

    const changedWords = [];
    if (config.diffStyle === "word" && config.matching === "words") {
      let treshold = 0.25;

      if (typeof config.matchWordsThreshold !== "undefined") {
        treshold = config.matchWordsThreshold;
      }

      const matcher = Rematch.rematch(function(a, b) {
        const amod = a.value;
        const bmod = b.value;
github arangodb / arangodb / js / node / node_modules / mocha / lib / reporters / base.js View on Github external
function errorDiff(actual, expected) {
  return diff
    .diffWordsWithSpace(actual, expected)
    .map(function(str) {
      if (str.added) {
        return colorLines('diff added', str.value);
      }
      if (str.removed) {
        return colorLines('diff removed', str.value);
      }
      return str.value;
    })
    .join('');
}
github ILIAS-eLearning / ILIAS / Modules / Chatroom / chat / node_modules / mocha / lib / reporters / base.js View on Github external
function errorDiff(actual, expected) {
  return diff
    .diffWordsWithSpace(actual, expected)
    .map(function(str) {
      if (str.added) {
        return colorLines('diff added', str.value);
      }
      if (str.removed) {
        return colorLines('diff removed', str.value);
      }
      return str.value;
    })
    .join('');
}
github mochajs / mocha / lib / reporters / base.js View on Github external
function errorDiff(actual, expected) {
  return diff
    .diffWordsWithSpace(actual, expected)
    .map(function(str) {
      if (str.added) {
        return colorLines('diff added', str.value);
      }
      if (str.removed) {
        return colorLines('diff removed', str.value);
      }
      return str.value;
    })
    .join('');
}
github brigadecore / brigade / brigade-worker / node_modules / mocha / lib / reporters / base.js View on Github external
function errorDiff(actual, expected) {
  return diff
    .diffWordsWithSpace(actual, expected)
    .map(function(str) {
      if (str.added) {
        return colorLines('diff added', str.value);
      }
      if (str.removed) {
        return colorLines('diff removed', str.value);
      }
      return str.value;
    })
    .join('');
}
github publiclab / Leaflet.DistortableImage / node_modules / mocha / lib / reporters / base.js View on Github external
function errorDiff(actual, expected) {
  return diff
    .diffWordsWithSpace(actual, expected)
    .map(function(str) {
      if (str.added) {
        return colorLines('diff added', str.value);
      }
      if (str.removed) {
        return colorLines('diff removed', str.value);
      }
      return str.value;
    })
    .join('');
}
github labhackercd / wikilegis / wikilegis / static / javascript / content / modules / amendmentDiff.js View on Github external
function buildMarkup(oldText, newText) {
    const diffElement = document.createDocumentFragment();
    diff.diffWordsWithSpace(oldText, newText).forEach((part) => {
      let className = '';
      if (part.added) className = 'diff-added';
      else if (part.removed) className = 'diff-removed';

      const span = document.createElement('span');
      $(span).addClass(className);
      span.appendChild(document.createTextNode(part.value));
      diffElement.appendChild(span);
    });
    return diffElement;
  }
github rtfpessoa / diff2html / dist / diff2html.js View on Github external
var prefixSize = 1;

    if (config.isCombined) {
      prefixSize = 2;
    }

    linePrefix1 = diffLine1.substr(0, prefixSize);
    linePrefix2 = diffLine2.substr(0, prefixSize);
    unprefixedLine1 = diffLine1.substr(prefixSize);
    unprefixedLine2 = diffLine2.substr(prefixSize);

    var diff;
    if (config.charByChar) {
      diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2);
    } else {
      diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2);
    }

    var highlightedLine = '';

    var changedWords = [];
    if (!config.charByChar && config.matching === 'words') {
      var treshold = 0.25;

      if (typeof (config.matchWordsThreshold) !== 'undefined') {
        treshold = config.matchWordsThreshold;
      }

      var matcher = Rematch.rematch(function(a, b) {
        var amod = a.value;
        var bmod = b.value;