Skip to content

Commit 56d1e1d

Browse files
Merge pull request #3758 from opral/update-docs
Update-docs
2 parents ca07930 + 83ccb84 commit 56d1e1d

4 files changed

Lines changed: 57 additions & 5 deletions

File tree

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,27 @@ HTML Diff is a simple way to generate and display diffs for any app UI.
77
- 🎨 **Uses your styles**: Uses your existing CSS.
88
- 🔧 **Framework Agnostic**: Works with React, Vue, Svelte, Angular, and more.
99

10+
Visit [the documentation](https://html-diff.lix.dev) for more information.
11+
12+
## Installation
13+
14+
```bash
15+
pnpm add @lix-js/html-diff
16+
```
17+
18+
Optional default styling:
19+
20+
```ts
21+
import "@lix-js/html-diff/default.css";
22+
```
23+
24+
## Quickstart
25+
1026
Assume you want to diff a table that's displayed to users. You render the before and after HTML, then pass both into the `renderHtmlDiff` function to get the diff:
1127

1228
```typescript
1329
import { renderHtmlDiff } from "@lix-js/html-diff";
30+
import "@lix-js/html-diff/default.css";
1431

1532
const tableBefore = renderTable(beforeData);
1633
const tableAfter = renderTable(afterData);
@@ -22,7 +39,11 @@ const diff = renderHtmlDiff({
2239
// diffAttribute: 'data-id',
2340
});
2441

25-
render(diff, document.getElementById("diff-container"));
26-
```
42+
// Vanilla render
43+
document.getElementById("diff-container")!.innerHTML = diff;
2744

28-
For more information, [visit the documentation](https://html-diff.lix.dev).
45+
// React render
46+
function DiffView({ html }: { html: string }) {
47+
return <div dangerouslySetInnerHTML={{ __html: html }} />;
48+
}
49+
```

docs/guide/index.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,32 @@ npm install @lix-js/html-diff
114114

115115
## Usage
116116

117+
### Quickstart
118+
119+
```ts
120+
import { renderHtmlDiff } from "@lix-js/html-diff";
121+
import "@lix-js/html-diff/default.css";
122+
123+
const beforeHtml = `<p data-diff-key="x9n4" class="my-text">The quick brown fox</p>`;
124+
const afterHtml = `<p data-diff-key="x9n4" class="my-text">The fast red fox</p>`;
125+
126+
const diff = renderHtmlDiff({ beforeHtml, afterHtml });
127+
128+
// Vanilla
129+
document.getElementById("diff-container")!.innerHTML = diff;
130+
131+
// React
132+
function Diff({ html }: { html: string }) {
133+
return <div dangerouslySetInnerHTML={{ __html: html }} />;
134+
}
135+
```
136+
137+
Include the default styling if you want ready-made highlights:
138+
139+
```ts
140+
import "@lix-js/html-diff/default.css";
141+
```
142+
117143
### Step 1: Add `data-diff-key` attributes
118144

119145
Add unique [`data-diff-key`](/guide/attributes.html#data-diff-key) attributes to elements you want to track for changes. Use random, short identifiers (not semantic names):

docs/playground.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Playground
22

33
Try the HTML diff tool in real-time! Paste your "before" and "after" HTML to see how the diff would look.
4-
Make sure to include [`data-diff-key`](/guide/attributes.html#data-diff-key) attributes for elements.
4+
Make sure to include [`data-diff-key`](/guide/attributes.html#data-diff-key) attributes for elements you want to track changes for.
5+
6+
You can also use these optional attributes to control diffing behavior:
7+
- [`data-diff-mode="words"`](/guide/attributes.html#words) - Enable word-level diffing within elements
8+
- [`data-diff-mode="element"`](/guide/attributes.html#element) - Use atomic element-level diffing
9+
- [`data-diff-show-when-removed`](/guide/attributes.html#data-diff-show-when-removed) - Show removed elements with strikethrough styling
510

611
import DiffPlayground from "./components/diff-playground";
712

rspress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export default defineConfig({
133133
icon: "github",
134134
mode: "link",
135135
content:
136-
"https://github.com/opral/monorepo/tree/main/packages/lix/lix-html-diff",
136+
"https://github.com/opral/monorepo/tree/main/packages/lix/html-diff",
137137
},
138138
],
139139
},

0 commit comments

Comments
 (0)