How to use the diff2html.Diff2Html.getPrettyHtml 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 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 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>
github fabsrc / graphql-schema-diff / src / html.ts View on Github external
export async function createHtmlOutput(
  diff: string,
  options: Options = {}
): Promise {
  const { outputDirectory = 'schemaDiff' } = options;

  const adjustedDiff = diff
    .replace(/(---\s.*)\sremoved/, '$1')
    .replace(/(\+\+\+\s.*)\sadded/, '$1');
  const diffHtml = Diff2Html.getPrettyHtml(adjustedDiff, {
    inputFormat: 'diff',
    matching: 'lines',
    outputFormat: 'side-by-side',
    rawTemplates: {
      'tag-file-renamed': ''
    }
  });
  await fs.ensureDir(outputDirectory);
  const diff2HtmlPath = path.dirname(require.resolve('diff2html/package.json'));
  await fs.copy(path.join(diff2HtmlPath, 'dist'), outputDirectory);
  const htmlOutput = htmlTemplate(diffHtml);
  await fs.writeFile(path.join(outputDirectory, 'index.html'), htmlOutput);
}
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 zeebe-io / zeebe-modeler / tasks / send-license-book-summary.js View on Github external
function getHtmlFromDiff(diff, currentVersion) {
  const style = fs.readFileSync(require.resolve('diff2html/dist/diff2html.min.css'));

  const diffHtml = diff2html.getPrettyHtml(diff, { inputFormat: 'diff', showFiles: true, matching: 'lines', outputFormat: 'side-by-side' });

  const html = `





<title>Camunda Modeler ${currentVersion} Third Party Notices Changes Summary</title>
<style>${style}</style>


  <h1>
    Camunda Modeler Third Party Notices Changes
  </h1>
${diffHtml}
github buzzfeed-openlab / edgar-monitor / edgar-monitor.js View on Github external
diffDocs(oldLink, newLink, function(err, diff) {
                    if (err) { return cb(err); }

                    var body = Diff2Html.getPrettyHtml(diff, { inputFormat: 'diff' }),
                        html = buildDiffHtml(body),
                        filename = entry.guid + '.html';

                    fs.writeFileSync(filename, html);
                    uploadFileToS3('edgar-diffs', filename, html, { ACL: 'public-read', ContentType: 'text/html' }, function(err, link) {
                        if (err) { return cb(err); }

                        var secondsInAWeek = 604800;
                        var params = { Bucket: 'edgar-diffs', Key: filename, Expires: secondsInAWeek };
                        s3.getSignedUrl('getObject', params, function(err, url) {
                            cb(err, url);
                        });
                    });

                });
github tessereact / tessereact / src / components / _lib / diff / index.js View on Github external
function diffToHTML (diff, options = {}) {
  if (!diff) {
    return ''
  }

  return Diff2Html.getPrettyHtml(
    diff, {
      outputFormat: options.sideBySide ? 'side-by-side' : 'line-by-line'
    }
  )
}