Git Product home page Git Product logo

Comments (2)

RexSkz avatar RexSkz commented on July 17, 2024

Good idea! It's not supported now, but I will implement it in Viewer.

Prism is a good syntax-highlighting library (I use it in many projects), but it's too wasteful to highlight JSON, and I need to take some extra steps to align the unchanged lines.

I'll add a new prop to Differ:

interface DifferOptions {
  outputTokens?: boolean;
}

It will add a field tokens to each DiffResult item. The Viewer will automatically enable the syntax highlight feature if the field exists.

There will also be a new prop to Viewer:

interface ViewerProps {
  syntaxHighlightTheme?: string;
}

It will add a class json-diff-viewer-theme-${syntaxHighlightTheme} to the viewer for CSS to take effect.

I'll provide a theme "monokai" first (which is my favourite theme). Other themes may be added in future (by me or by others).

from json-diff-kit.

RexSkz avatar RexSkz commented on July 17, 2024

Sorry for being late; I've finished the syntax highlight feature, but the usage is different from the beginning since there're inline diff and I need to handle the two segment array (inline diff result & syntax highlight result) in <Viewer> component.

The playground has been updated, just check the "syntax highlight" checkbox on the left to enable it:

image

The usage in your code is simple:

  1. Add syntaxHighlight={{ theme: 'monokai' }} to the <Viewer> component is enough (other theme values are ok, it will enable the syntax highlight feature and add a className json-diff-viewer-theme-monokai to the DOM).
  2. Import the CSS which has the corresponding theme. For now I only support the monokai theme, which is at 'json-diff-kit/dist/viewer-monokai.css', you can write your own theme according to this file.

from json-diff-kit.

Related Issues (20)

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.