Skip to content

Getting Started

A remark plugin providing an alternative syntax to author diff code blocks in Markdown.

To learn more about some of the drawbacks of classic diff code blocks and how remark-auto-diff tries to solve them, check out the “Why a new syntax?” page.

  1. Install remark-auto-diff using your favorite package manager:

    Terminal window
    npm i remark-auto-diff
  2. The plugin can be used in any project using remark including Astro and Starlight.

    Add the plugin in your Astro configuration in the astro.config.mjs file.

    astro.config.mjs
    // @ts-check
    import starlight from '@astrojs/starlight'
    import { defineConfig } from 'astro/config'
    import { remarkAutoDiff } from 'remark-auto-diff'
    export default defineConfig({
    integrations: [
    starlight({
    title: 'My Docs',
    }),
    ],
    markdown: {
    remarkPlugins: [remarkAutoDiff],
    },
    })

When using the remark-auto-diff plugin, a first code block is used to specify the “before” version of the code immediately followed by a second code block to specify the “after” version of the code. The auto-diff attribute is added to the opening code fence of both code blocks to specify that the plugin should compute the diff automatically.

Markdown Code Editor
My Markdown content.
```js auto-diff
console.log('removed line')
```
```js auto-diff
console.log('added line')
```

The above example will automatically be transformed by the plugin to:

My Markdown content.
```diff lang=js
- console.log('removed line')
+ console.log('added line')
```

When rendered by Expressive Code, the above example would be rendered as:

console.log('removed line')
console.log('added line')