How to use the diff2html.Diff2Html.getJsonFromDiff function in diff2html

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 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 / v2 / SharedDiff.ts View on Github external
export function makeSharedDiff(raw_diff: string, date: Date = new Date()): SharedDiff {
    let expire_date = new Date();
    expire_date.setDate(date.getDate() + 1);
    return {
        created: date,
        expiresAt: expire_date,
        diff: Diff2Html.getJsonFromDiff(raw_diff),
        rawDiff: raw_diff,
    };
}
github yybawang / Adoc / resources / js / pages / Post / CodeDiff.jsx View on Github external
function 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>
github FredrikNoren / ungit / components / sidebysidediff / sidebysidediff.js View on Github external
self.server.get('/diff', this.getDiffArguments() , function(err, diffs) {
    if (typeof diffs === "string") {
      self.diffJson = diff2html.getJsonFromDiff(diffs);
      self.render();
    }

    if (callback) callback();
  });
}
github Qihoo360 / wayne / src / frontend / src / app / shared / diff / diff.component.ts View on Github external
newStr = YAML.dump(this.formatJson(this.diffTpl.newStr));
      }
    } catch {
      oldstr = '';
      newStr = '';
      this.messageService.showError('SHARED.DIFF.CHECK_DATA');
    }
    try {
      const dd = createPatch(
        this.diffTpl.fileName,
        oldstr,
        newStr,
        this.diffTpl.newHeader,
        this.diffTpl.oldHeader
      );
      const outStr = Diff2Html.getJsonFromDiff(
        dd,
        { inputFormat: this.inputType, outputFormat: this.outStyle, showFiles: false, matching: 'lines' }
      );
      const html = Diff2Html.getPrettyHtml(
        outStr, { inputFormat: 'json', outputFormat: this.outStyle, showFiles: false, matching: 'lines' }
      );
      this.html = html;
    } catch {
      this.messageService.showError('SHARED.DIFF.TRANS_ERROR');
      this.html = null;
    }
  }
github Tencent / bk-bcs-saas / bcs-app / frontend / src / components / bk-diff / index.vue View on Github external
getDiffJson (oldContent, newContent, context, outputFormat) {
                const args = ['', oldContent, newContent, '', '', { context: context }]
                const patch = createPatch(...args)

                const outStr = Diff2Html.getJsonFromDiff(patch, {
                    inputFormat: 'diff',
                    outputFormat: outputFormat,
                    showFiles: true,
                    matching: 'lines'
                })

                const addedLines = outStr[0].addedLines
                const deleteLines = outStr[0].deletedLines
                const changeLines = Math.max(addedLines, deleteLines)
                outStr.changeLines = changeLines

                return outStr
            },
            createdHtml (oldContent, newContent, context, outputFormat) {
github pbu88 / diffy / frontend / src / app / SharedDiff.ts View on Github external
export function makeSharedDiff(raw_diff: string, date: Date = new Date()): SharedDiff {
    let expire_date = new Date();
    expire_date.setDate(date.getDate() + 1);
    return {
        created: date,
        expiresAt: expire_date,
        diff: Diff2Html.getJsonFromDiff(raw_diff),
        rawDiff: raw_diff,
    };
}