|
64 | 64 | return /--\>$/.test(word); |
65 | 65 | } |
66 | 66 |
|
| 67 | + /** |
| 68 | + * Regular expression to check atomic tags. |
| 69 | + * @see function diff. |
| 70 | + */ |
| 71 | + var atomicTagsRegExp; |
| 72 | + // Added head and style (for style tags inside the body) |
| 73 | + var defaultAtomicTagsRegExp = new RegExp('^<(iframe|object|math|svg|script|head|style)'); |
| 74 | + |
67 | 75 | /** |
68 | 76 | * Checks if the current word is the beginning of an atomic tag. An atomic tag is one whose |
69 | 77 | * child nodes should not be compared - the entire tag should be treated as one token. This |
|
75 | 83 | * null otherwise |
76 | 84 | */ |
77 | 85 | function isStartOfAtomicTag(word){ |
78 | | - var result = /^<(iframe|object|math|svg|script)/.exec(word); |
| 86 | + var result = atomicTagsRegExp.exec(word); |
79 | 87 | return result && result[1]; |
80 | 88 | } |
81 | 89 |
|
|
897 | 905 | * @param {string} className (Optional) The class attribute to include in <ins> and <del> tags. |
898 | 906 | * @param {string} dataPrefix (Optional) The data prefix to use for data attributes. The |
899 | 907 | * operation index data attribute will be named `data-${dataPrefix-}operation-index`. |
| 908 | + * @param {string} atomicTags (Optional) List of atomic tag names. The list has to be in the |
| 909 | + * form 'tag1|tag2|tag3|...' e. g. 'head|script|style|...'. If not used, the default list |
| 910 | + * 'iframe|object|math|svg|script|head|style' will be used. |
900 | 911 | * |
901 | 912 | * @return {string} The combined HTML content with differences wrapped in <ins> and <del> tags. |
902 | 913 | */ |
903 | | - function diff(before, after, className, dataPrefix){ |
| 914 | + function diff(before, after, className, dataPrefix, atomicTags){ |
904 | 915 | if (before === after) return before; |
905 | 916 |
|
| 917 | + // Enable user provided atomic tag list. |
| 918 | + atomicTags ? (atomicTagsRegExp = new RegExp('^<(' + atomicTags + ')')) : (atomicTagsRegExp = defaultAtomicTagsRegExp); |
| 919 | + |
906 | 920 | before = htmlToTokens(before); |
907 | 921 | after = htmlToTokens(after); |
908 | 922 | var ops = calculateOperations(before, after); |
|
0 commit comments