Skip to content

Commit

Permalink
Changed pipe based separation of atomic tags to comma separation (eas…
Browse files Browse the repository at this point in the history
…ier handling on the command line).
  • Loading branch information
mn4367 committed Mar 27, 2018
1 parent c36b3f6 commit 9c96241
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
32 changes: 10 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ of these three parameters it will be ignored:
- `dataPrefix` (string) The data prefix to use for data attributes. The so called *operation
index data attribute* will be named `data-${dataPrefix-}operation-index`. If not used,
the default attribute name `data-operation-index` will be added on every inserted
`<ins>` and `<del>` tag. The value of this attribute is an auto incremented counter.
- `atomicTags` (string) A list of tag names. The list has to be in the form `tag1|tag2|...`
e. g. `head|script|style`. An atomic tag is one whose child nodes should not be
compared - the entire tag should be treated as one token. This is useful for tags where
it does not make sense to insert `<ins>` and `<del>` tags. If not used, this default
list will be used: `iframe|object|math|svg|script|video|head|style`.
`<ins>` and `<del>` tag. The value of this attribute is an auto incremented counter.
- `atomicTags` (string) Comma separated list of tag names. The list has to be in the form
`tag1,tag2,...` e. g. `head,script,style`. An atomic tag is one whose child nodes should
not be compared - the entire tag should be treated as one token. This is useful for tags
where it does not make sense to insert `<ins>` and `<del>` tags. If not used, the default
list will be used:
`iframe,object,math,svg,script,video,head,style`.
### Example
Expand Down Expand Up @@ -98,7 +99,7 @@ Result:
## Command line interface

```bash
htmldiff beforeFile afterFile diffedFile [Options]
htmldiff beforeFile afterFile diffedFile [-c className] [-p dataPrefix] [-t atomicTags]
```

Parameters:
Expand All @@ -114,21 +115,8 @@ Parameters:

Options:

- `-c` `className` (optional): className will be added as a class attribute
on every `<ins>` and `<del>` tag.

- `-p` `dataPrefix` (optional): The data prefix to use for data attributes.
The operation index data attribute will be named
`data-${dataPrefix-}operation-index`. If not used, the default attribute
name `data-operation-index` will be added on every `<ins>` and `<del>` tag.
The value of this attribute is an auto incremented counter.
- `-t` `atomicTags` (optional): List of tag names. The list has to be in the
form `tag1|tag2|...` e. g. `head|script|style`. An atomic tag is one whose
child nodes should not be compared - the entire tag should be treated as
one token. This is useful for tags where it does not make sense to insert
`<ins>` and `<del>` tags. If not used, this default list will be used:
`iframe|object|math|svg|script|video|head|style`.
`-c className`, `-p dataPrefix` and `-t atomicTags` are all optional. For a
description please see API documentation above.


## Development
Expand Down
11 changes: 6 additions & 5 deletions js/htmldiff.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
* @param {string} className (Optional) The class attribute to include in `<ins>` and `<del>` tags.
* @param {string} dataPrefix (Optional) The data prefix to use for data attributes. The
* operation index data attribute will be named `data-${dataPrefix-}operation-index`.
* @param {string} atomicTags (Optional) List of tag names. The list has to be in the form
* `tag1|tag2|...` e. g. `head|script|style`. An atomic tag is one whose child nodes
* should not be compared - the entire tag should be treated as one token. This is
* useful for tags where it does not make sense to insert <ins> and <del> tags.
* If not used, the default list `iframe|object|math|svg|script|video|head|style` will be used.
* @param {string} atomicTags (Optional) Comma separated list of tag names. The list has to
* be in the form `tag1,tag2,...` e. g. `head,script,style`. An atomic tag is one whose
* child nodes should not be compared - the entire tag should be treated as one token.
* This is useful for tags where it does not make sense to insert `<ins>` and `<del>`
* tags. If not used, the default list `iframe,object,math,svg,script,video,head,style`
* will be used.
*
* @return {string} The combined HTML content with differences wrapped in `<ins>` and `<del>` tags.
*/
Expand Down
12 changes: 7 additions & 5 deletions js/htmldiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
*/
var atomicTagsRegExp;
// Added head and style (for style tags inside the body)
var defaultAtomicTagsRegExp = new RegExp('^<(iframe|object|math|svg|script|video|head|style)');
var defaultAtomicTagsRegExp = new RegExp('^<(iframe,object,math,svg,script,video,head,style)');

/**
* Checks if the current word is the beginning of an atomic tag. An atomic tag is one whose
Expand Down Expand Up @@ -943,17 +943,19 @@
* @param {string} className (Optional) The class attribute to include in <ins> and <del> tags.
* @param {string} dataPrefix (Optional) The data prefix to use for data attributes. The
* operation index data attribute will be named `data-${dataPrefix-}operation-index`.
* @param {string} atomicTags (Optional) List of atomic tag names. The list has to be in the
* form 'tag1|tag2|tag3|...' e. g. 'head|script|style|...'. If not used, the default list
* 'iframe|object|math|svg|script|video|head|style' will be used.
* @param {string} atomicTags (Optional) Comma separated list of atomic tag names. The
* list has to be in the form `tag1,tag2,...` e. g. `head,script,style`. If not used,
* the default list `iframe,object,math,svg,script,video,head,style` will be used.
*
* @return {string} The combined HTML content with differences wrapped in <ins> and <del> tags.
*/
function diff(before, after, className, dataPrefix, atomicTags){
if (before === after) return before;

// Enable user provided atomic tag list.
atomicTags ? (atomicTagsRegExp = new RegExp('^<(' + atomicTags + ')')) : (atomicTagsRegExp = defaultAtomicTagsRegExp);
atomicTags ?
(atomicTagsRegExp = new RegExp('^<(' + atomicTags.replace(/\s*/g, "").trim() + ')'))
: (atomicTagsRegExp = defaultAtomicTagsRegExp);

before = htmlToTokens(before);
after = htmlToTokens(after);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Diff and markup HTML with <ins> and <del> tags",
"companyname": "idesis GmbH",
"copyright": "©2018, idesis GmbH; ©2012 The Network Inc. and contributors",
"version": "0.9.0",
"version": "0.9.1",
"identifier": "de.idesis.node-htmldiff",
"keywords": [
"diff",
Expand Down

0 comments on commit 9c96241

Please sign in to comment.