Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marc-bernard-tools/abap-html-diff
Library to highlight the content difference between two HTML strings (htmldiff)
https://github.com/marc-bernard-tools/abap-html-diff
abap diff html open-source sap text
Last synced: 2 months ago
JSON representation
Library to highlight the content difference between two HTML strings (htmldiff)
- Host: GitHub
- URL: https://github.com/marc-bernard-tools/abap-html-diff
- Owner: Marc-Bernard-Tools
- License: mit
- Created: 2022-06-02T13:41:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-05T12:01:05.000Z (9 months ago)
- Last Synced: 2024-08-02T19:01:53.942Z (5 months ago)
- Topics: abap, diff, html, open-source, sap, text
- Language: ABAP
- Homepage: https://github.com/Marc-Bernard-Tools
- Size: 103 KB
- Stars: 6
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
![Version](https://img.shields.io/endpoint?url=https://shield.abap.space/version-shield-json/github/Marc-Bernard-Tools/ABAP-HTML-Diff/src/zcl_htmldiff.clas.abap/c_version&label=Version&color=blue)
[![License](https://img.shields.io/github/license/Marc-Bernard-Tools/ABAP-HTML-Diff?label=License&color=success)](LICENSE)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg?color=success)](https://github.com/Marc-Bernard-Tools/.github/blob/main/CODE_OF_CONDUCT.md)
[![REUSE Status](https://api.reuse.software/badge/github.com/Marc-Bernard-Tools/ABAP-HTML-Diff)](https://api.reuse.software/info/github.com/Marc-Bernard-Tools/ABAP-HTML-Diff)# ABAP HTML Diff
Library to highlight the content difference between two HTML strings (htmldiff).
Made by [Marc Bernard Tools](https://marcbernardtools.com/) giving back to the [SAP Community](https://community.sap.com/)
NO WARRANTIES, [MIT License](LICENSE)
## HTML Diff
This is a diffing library that understands HTML. Best suited for cases when you want to show a diff of user-generated HTML.
- The implementation is a port of JavaScript (https://github.com/alaorneto/htmldiffer, no license defined)
- which is a port of CoffeeScript (https://github.com/tnwinc/htmldiff.js, MIT license)
- which is a port of the original Ruby (https://github.com/myobie/htmldiff, MIT license)An enhancement was made so the code can also produce the diff of two texts (tags are treated like text).
## Prerequisites
SAP Basis 7.4 or higher
## Installation
You can install ABAP Differ using [abapGit](https://github.com/abapGit/abapGit) either creating a new online repository for https://github.com/Marc-Bernard-Tools/ABAP-HTML-Diff or downloading the repository [ZIP file](https://github.com/Marc-Bernard-Tools/ABAP-HTML-Diff/archive/main.zip) and creating a new offline repository.
We recommend using package `$HTMLDIFF`.
## Usage
### Diffing HTML
The following produces the diff of two example HTML snippets:
```abap
DATA:
lv_original TYPE string,
lv_modified TYPE string,
lv_diff TYPE string,
li_htmldiff TYPE REF TO zif_htmldiff.lv_original = '\n'
&& 'First paragraph.
\n'
&& '
- \n'
- Item A \n'
- Item B \n'
- Item C \n'
&& '
&& '
&& '
&& '
&& ' \n'
&& ' This is some interesting text.\n'.
lv_modified = '\n'
&& '
First paragraph.
\n'&& '
- \n'
- Item A \n'
- Item B \n'
- Item D \n'
&& '
&& '
&& '
&& '
&& ' \n'
&& ' This is some new text.\n'.
REPLACE ALL OCCURRENCES OF '\n' IN lv_original WITH cl_abap_char_utilities=>newline.
REPLACE ALL OCCURRENCES OF '\n' IN lv_modified WITH cl_abap_char_utilities=>newline.
li_htmldiff = zcl_htmldiff=>create( ).
lv_diff = li_htmldiff->htmldiff(
iv_before = lv_original
iv_after = lv_modified
iv_with_img = abap_false ).
```
Result:
```html
First paragraph.
- Item A
- Item B
- Item
CD
This is some
```
By setting the image parameter to true, you can also mark changed images as deletions or insertions:
```abap
lv_diff = li_htmldiff->htmldiff(
iv_before = lv_original
iv_after = lv_modified
iv_with_img = abap_true ).
```
Result:
```html
First paragraph.
- Item A
- Item B
- Item
CD
This is some
```
There are a few other options you can set in the `constructor`/`create` statement:
- `iv_inserts`: Show `` tags (default: on)
- `iv_deletes`: Show `` tags (default: on)
- `iv_css_classes`: Add CSS classes to `` and `` tags (default: off)
- `iv_support_chinese`: Treat Chinese characters as individual words (default: off)
Using CSS classes, the result will distinguish between inserts (class `diffins`), deletes (class `diffdel`), and updates (class `diffmod`).
See the [test classes](https://github.com/Marc-Bernard-Tools/ABAP-HTML-Diff/blob/main/src/zcl_htmldiff.clas.testclasses.abap) for more examples.
### Diffing Text
The following produces the diff of two example text snippets:
```abap
DATA:
lv_original TYPE string,
lv_modified TYPE string,
lv_diff TYPE string,
li_htmldiff TYPE REF TO zif_htmldiff.
lv_original = 'a c'.
lv_modified = 'a b c'.
lv_diff = li_htmldiff->textdiff(
iv_before = lv_original
iv_after = lv_modified ).
```
Result:
```text
a b c
```
Example 2:
```abap
lv_original = 'a b c'.
lv_modified = 'a c'.
lv_diff = li_htmldiff->textdiff(
iv_before = lv_original
iv_after = lv_modified ).
```
Result:
```text
a b c
```
### Styling
Here's an examle for styling the insertions and deletions using CSS.
```css
/* CSS for and tags */
ins { background-color: #ddffdd; }
ins img { border-color: #ddffdd; }
del { background-color: #ffdddd; }
del img { border-color: #ffdddd; }
```
With the CSS class option, use the following:
```css
/* CSS for insert, delete, and modify classes */
.diffins { background-color: #ddffdd; }
.diffdel { background-color: #ffdddd; }
.diffmod { background-color: #ffffdd; }
```
## Contributions
All contributions are welcome! Read our [Contribution Guidelines](CONTRIBUTING.md), fork this repo, and create a pull request.
## About
Made with :heart: in Canada
Copyright 2021 Marc Bernard
Follow [@marcfbe](https://twitter.com/marcfbe) on Twitter