How to use diff2html - 10 common examples

To help you get started, weโ€™ve selected a few diff2html 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 Tencent / bk-bcs-saas / bcs-app / frontend / src / components / bk-diff / index.vue View on Github external
matching: 'lines'
                    })
                    return htmlReplace(html)
                } else {
                    diffJsonConf = this.getDiffJson(oldContent, newContent + '\n', context, outputFormat)

                    diffJsonConf.changeLines = 0
                    diffJsonConf[0].addedLines = 0
                    diffJsonConf[0].deletedLines = 0
                    const firstBlock = diffJsonConf[0].blocks[0]
                    firstBlock.header = ''
                    firstBlock.newStartLine = '0'
                    firstBlock.oldStartLine = '0'
                    firstBlock.lines.splice(firstBlock.lines.length - 1, 1)

                    const html = Diff2Html.getPrettyHtml(diffJsonConf, {
                        inputFormat: 'json',
                        outputFormat: outputFormat,
                        showFiles: false,
                        matching: 'lines'
                    })
                    return htmlReplace(html)
                    // return `<div style="line-height: ${this.minHeight}px;" class="diff-tip-box">ๆ•ฐๆฎๆฒกๆœ‰ๅทฎๅผ‚</div>`
                }
            }
        }
github weseek / growi / src / client / js / components / PageHistory / RevisionDiff.jsx View on Github external
&amp;&amp; revisionDiffOpened) {

      let previousText = previousRevision.body;
      // comparing ObjectId
      // eslint-disable-next-line eqeqeq
      if (currentRevision._id == previousRevision._id) {
        previousText = '';
      }

      const patch = createPatch(
        currentRevision.path,
        previousText,
        currentRevision.body,
      );

      diffViewHTML = Diff2Html.getPrettyHtml(patch);
    }

    const diffView = { __html: diffViewHTML };
    // eslint-disable-next-line react/no-danger
    return <div>;
  }
</div>
github FredrikNoren / ungit / components / textdiff / textdiff.js View on Github external
return this.server.getPromise('/diff', this.getDiffArguments()).then((diffs) => {
      if (typeof diffs !== 'string') {
        // Invalid value means there is no changes, show dummy diff withotu any changes
        diffs = `diff --git a/${this.filename} b/${this.filename}
                  index aaaaaaaa..bbbbbbbb 111111
                  --- a/${this.filename}
                  +++ b/${this.filename}`;
      }
      this.diffJson = diff2html.getJsonFromDiff(diffs);
    }).catch(err => {
      // The file existed before but has been removed, but we're trying to get a diff for it
github dittos / diffmonster / src / lib / DiffParser.ts View on Github external
export function parseDiff(diff: string) {
  // generate PR files API-like object https://developer.github.com/v3/pulls/#list-pull-requests-files
  const parsed = Diff2Html.getJsonFromDiff(diff) as DiffFile[];
  parsed.forEach(file => {
    file.filename = file.isDeleted ? file.oldName : file.newName;
    // TODO: GitHub doesn't provide checksum for content unchanged file
    file.sha = file.isDeleted ? file.checksumBefore : file.checksumAfter;
    if (file.isDeleted) {
      file.status = 'removed';
    } else if (file.isNew || file.isCopy) {
      file.status = 'added';
    } else if (file.isRename) {
      file.status = 'renamed';
      file.previous_filename = file.oldName;
    }
    let position = 0;
    file.blocks.forEach(block => {
      position++;
      block.lines.forEach(line => {
github pbu88 / diffy / backend / src / Diff.js View on Github external
var Diff2Html = require('diff2html').Diff2Html;
var _ = require('lodash');

(function(){
    /**
     * @param string rawDiffString -- the raw diff string
     */
    function Diff(rawDiffString) {

        /* Fields initialization */
        var jsonDiff = Diff2Html.getJsonFromDiff(rawDiffString);
        var diffFiles = _.map(jsonDiff, (jsonDiffFile) => {
            return new DiffFile(jsonDiffFile);
        });
        
        this.diffFiles = diffFiles;
        this.rawDiff = rawDiffString;
github FredrikNoren / ungit / components / textdiff / textdiff.js View on Github external
blocks.push(block);
          }
          lineCount += length;
          return blocks;
        }, []);
      }
      this.diffJson[0].isTrimmed = true;

      this.loadMoreCount(Math.min(loadLimit, Math.max(0, lineCount - this.loadCount)));

      let html;

      if (this.textDiffType.value() === 'sidebysidediff') {
        html = diff2html.getPrettySideBySideHtmlFromJson(this.diffJson);
      } else {
        html = diff2html.getPrettyHtmlFromJson(this.diffJson);
      }

      this.numberOfSelectedPatchLines = 0;
      let index = 0;

      // ko's binding resolution is not recursive, which means below ko.bind refresh method doesn't work for
      // data bind at getPatchCheckBox that is rendered with "html" binding.
      // which is reason why manually updating the html content and refreshing kobinding to have it render...
      if (this.patchLineList) {
        html = html.replace(/<span class="d2h-code-line-[a-z]+">(\+|\-)/g, (match, capture) =&gt; {
          if (this.patchLineList()[index] === undefined) {
            this.patchLineList()[index] = true;
          }

          return this.getPatchCheckBox(capture, index, this.patchLineList()[index++]);
        });</span>
github FredrikNoren / ungit / components / textdiff / textdiff.js View on Github external
if (lineCount &lt; this.loadCount) {
            block.lines = block.lines.slice(0, this.loadCount - lineCount);
            blocks.push(block);
          }
          lineCount += length;
          return blocks;
        }, []);
      }
      this.diffJson[0].isTrimmed = true;

      this.loadMoreCount(Math.min(loadLimit, Math.max(0, lineCount - this.loadCount)));

      let html;

      if (this.textDiffType.value() === 'sidebysidediff') {
        html = diff2html.getPrettySideBySideHtmlFromJson(this.diffJson);
      } else {
        html = diff2html.getPrettyHtmlFromJson(this.diffJson);
      }

      this.numberOfSelectedPatchLines = 0;
      let index = 0;

      // ko's binding resolution is not recursive, which means below ko.bind refresh method doesn't work for
      // data bind at getPatchCheckBox that is rendered with "html" binding.
      // which is reason why manually updating the html content and refreshing kobinding to have it render...
      if (this.patchLineList) {
        html = html.replace(/<span class="d2h-code-line-[a-z]+">(\+|\-)/g, (match, capture) =&gt; {
          if (this.patchLineList()[index] === undefined) {
            this.patchLineList()[index] = true;
          }
</span>
github buzzfeed-openlab / edgar-monitor / edgar-monitor.js View on Github external
var request = require('request'),
    fs = require('fs'),
    exec = require('child_process').exec,
    Diff2Html = require('diff2html').Diff2Html,
    pg = require('pg'),
    cheerio = require('cheerio'),
    uuid = require('node-uuid'),
    aws = require('aws-sdk'),
    s3 = new aws.S3({ apiVersion: '2006-03-01', 'region': 'us-east-1' }),
    ses = new aws.SES({ apiVersion: '2010-12-01', 'region': 'us-east-1' });

function handleError(err) {
    if (err) {
        var timeStamp = (new Date()).toString();
        console.log(timeStamp, ' Error:');
        console.log(err);
        console.log('-------');

        process.exit(1);
    }
github Tencent / bk-bcs-saas / bcs-app / frontend / src / components / bk-diff / index.vue View on Github external
createdHtml (oldContent, newContent, context, outputFormat) {
                function htmlReplace (html) {
                    return html.replace(
                        /<span class="d2h-code-line-ctn">(.+?)&lt;\/span&gt;/g,
                        '<span class="d2h-code-line-ctn"><code>$1</code></span>'
                    )
                }

                let diffJsonConf = this.getDiffJson(oldContent, newContent, context, outputFormat)

                this.$emit('change-count', diffJsonConf.changeLines)
                if (diffJsonConf.changeLines) {
                    const html = Diff2Html.getPrettyHtml(diffJsonConf, {
                        inputFormat: 'json',
                        outputFormat: outputFormat,
                        showFiles: false,
                        matching: 'lines'
                    })
                    return htmlReplace(html)
                } else {
                    diffJsonConf = this.getDiffJson(oldContent, newContent + '\n', context, outputFormat)

                    diffJsonConf.changeLines = 0
                    diffJsonConf[0].addedLines = 0
                    diffJsonConf[0].deletedLines = 0
                    const firstBlock = diffJsonConf[0].blocks[0]
                    firstBlock.header = ''
                    firstBlock.newStartLine = '0'
                    firstBlock.oldStartLine = '0'</span>
github ddchef / vue-code-diff / src / lib / code-diff / index.vue View on Github external
createdHtml (oldString, newString, context, outputFormat) {
      function hljs (html) {
        return html.replace(/<span class="d2h-code-line-ctn">(.+?)&lt;\/span&gt;/g, '<span class="d2h-code-line-ctn"><code>$1</code></span>')
      }
      let args = ['', oldString, newString, '', '', {context: context}]
      let dd = createPatch(...args)
      let outStr = Diff2Html.getJsonFromDiff(dd, {inputFormat: 'diff', outputFormat: outputFormat, showFiles: false, matching: 'lines'})
      let html = Diff2Html.getPrettyHtml(outStr, {inputFormat: 'json', outputFormat: outputFormat, showFiles: false, matching: 'lines'})
      return hljs(html)
    }
  }</span>