/**
     * @ngdoc method
     * @name sdCompareVersionsArticle#highlightDifferences
     * @param {String} newText - current text
     * @param {String} oldText - old text to compare with
     * @description Highlight the differences between new text and old text
     */
    highlightDifferences(newText, oldText) {
        let mapWords = {};
        let pOldText = this.extractHtml(oldText, mapWords);
        let pNewText = this.extractHtml(newText, mapWords);
        let diffs = this.diffMatchPatch.diff_main(pOldText, pNewText);

        this.diffMatchPatch.diff_cleanupSemantic(diffs);
        diffs = this.splitByTranslationOfTags(diffs, this.reverseMap(mapWords, false));

        let text = this.diffMatchPatch
            .diff_prettyHtml(diffs);

        text = this.replaceWords(text, this.reverseMap(mapWords, true));
        return text;
    }
Beispiel #2
0
 const computeDiff = (text1,text2) => {
   let dmp = new DiffMatchPatch();
   let d = dmp.diff_main(text1, text2);
   dmp.diff_cleanupSemantic(d);
   return dmp.diff_prettyHtml(d);
 }