Overview

The Diff extension parses + and - symbols on the head of lines, and highlights them as added/deleted lines.

export default function Layout( { children } ) {
return (
<div>
{ children }
</div>
<main className={ styles.main }>
<section>{ children }</section>
</main>
);
}
JSX

This works with the LineNumbers extension:

export default function Layout( { children } ) {
return (
<div>
{ children }
</div>
<main className={ styles.main }>
<section>{ children }</section>
</main>
);
}
JSX

Usage

Register the Gutter and Diff extensions:

import { RyuseiLight, Gutter, Diff } from '@ryusei/light';
RyuseiLight.compose( { Gutter, Diff } );
// Register LineNumbers if necessary.
// RyuseiLight.compose( { Gutter, Diff, LineNumbers } );
JavaScript

Or import the extension files:

<script src="path-to-the-file/gutter.min.js"></script>
<script src="path-to-the-file/diff.min.js"></script>
<!-- Import line-numbers.min.js if necessary -->
<!--<script src="path-to-the-file/line-numbers.min.js"></script>-->
HTML

Next, prepend + for added lines and/or - for removed ones to your snippet:

<pre>
export default function Layout( { children } ) {
return (
- <div>
- { children }
- </div>
+ <main className={ styles.main }>
+ <section>{ children }</section>
+ </main>
);
}
</pre>

Then, set the diff option to true:

ryuseilight.apply( 'pre', { diff: true } );
JavaScript

Options

The Diff extension accepts some options by providing an object literal instead of true.

OptionDescription
removeSymbolsWhether to remove +/- symbols or convert them to a space.
addedSymbolDetermines a symbol for added lines. The default value is +.
deletedSymbolDetermines a symbol for deleted (removed) lines. The default value is -.

By default, the Diff extension converts + and - to spaces. You can remove them by setting removeSymbols to true.

Also, the default symbols can be changed by addedSymbol and deletedSymbol options:

ryuseilight.apply( 'pre', {
diff: {
addedSymbol : '>',
deletedSymbol: '<',
},
} );
JavaScript