An open API service indexing awesome lists of open source software.

https://github.com/zsmatrix62/diff-html


https://github.com/zsmatrix62/diff-html

diff-html extism

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

          

# diff-html

A WebAssembly plugin for Extism that performs HTML diffing between two HTML documents.

For more information about using Extism plugins, see the [Extism official documentation](https://extism.org/docs/overview).

## Features

- Performs semantic HTML diffing
- Preserves document structure
- Highlights changes with and tags
- Works as a lightweight WebAssembly module

## Example

### Input JSON
```json
{
"before": "

Original content with some text

",
"after": "

Modified content with different text

"
}
```

### Output HTML
```html



OriginalModified content
with somewith different text



```

### Rendered Output
```html



Original
Modified content
with some
with different text



```

## Installation

1. Install Extism CLI and Rust toolchain:
```bash
make setup
```

2. Build the optimized WebAssembly module:
```bash
make build
```

3. The compiled WebAssembly module will be available at:
```
target/wasm32-unknown-unknown/release/diff_html.wasm
```

## Usage with Extism

### Rust Example

```rust
use extism_pdk::*;

#[plugin_fn]
pub fn diff_html(input: String) -> FnResult {
let input: serde_json::Value = serde_json::from_str(&input)?;

let before = input["before"].as_str().unwrap();
let after = input["after"].as_str().unwrap();

let result = diff_html_rs::diff(before, after);
Ok(result)
}
```

### JavaScript Example

```javascript
import { Plugin } from 'extism';

async function diffHtml(before, after) {
const plugin = await Plugin.fromWasmFile(
'./target/wasm32-unknown-unknown/release/diff_html.wasm'
);

const input = JSON.stringify({
before,
after
});

const output = await plugin.call('diff_html', input);
return output.text();
}

// Example usage
const beforeHtml = '

Content

';
const afterHtml = '

Modified Content

';

diffHtml(beforeHtml, afterHtml).then(result => {
console.log('Diff result:', result);
});
```

## License

MIT