Code Monkey home page Code Monkey logo

codediff.js's Introduction

codediff.js

Build Status

codediff.js is a two-column JavaScript diff visualization with syntax highlighting and character-by-character differences.

It was originally based on jsdifflib, but has been rewritten almost entirely.

Try the online demo!

Screenshot of webdiff in action

codediff.js is used by webdiff.

Usage

<!-- Third-party dependencies -->
<script src="jquery.min.js"></script>
<script src="highlight.min.js"></script>
<link rel="stylesheet" href="googlecode.css">  <!-- highlight.js theme -->

<!-- codediff -->
<script src="difflib.js"></script>
<script src="codediff.js"></script>
<link rel="stylesheet" href="codediff.css">

<!-- DOM -->
<p>Here's the diff!</p>    
<div id="diffview"></div>

<!-- Usage -->
<script type="text/javascript">
$('#diffview').append(
    codediff.buildView(codeBefore, codeAfter, {
        /* options -- see below */
    }));
</script>

Options

Here are possible keys you can pass through the options parameter:

  • language: Language to use for syntax highlighting. This parameter is passed through to highlight.js, which does the highlighting. Any value it will accept is fine. You can do hljs.getLanguage(language) to see if a language code is valid. A null value (the default) will disable syntax highlighting. Example values include "python" or "javascript". (default: null)
  • beforeName: Text to place above the left side of the diff.
  • afterName: Text to place above the right side of the diff.
  • contextSize: Minimum number of lines of context to show around each diff hunk. (default: 3).
  • minJumpSize: Minimum number of equal lines to collapse into a "Show N more lines" link. (default: 10)
  • wordWrap: By default, code will go all the way to the right margin of the diff. If there are 60 characters of space, character 61 will wrap to the next line, even mid-word. To wrap at word boundaries instead, set this option.

Here's an example usage with a filled-out options parameter:

$('#diffview').append(
    codediff.buildView(codeBefore, codeAfter, {
        language: 'python',
        beforeName: 'oldfilename.py',
        afterName: 'newfilename.py',
        contextSize: 8,
        minJumpSize: 5,
        wordWrap: true
    }));

Development

To iterate on the project locally, open one of the test*.html files.

To run the tests, run:

npm install
grunt test

codediff.js's People

Contributors

danvk avatar cemerick avatar mmv avatar splewako avatar yonatan avatar

Watchers

psweatte avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.