-
Notifications
You must be signed in to change notification settings - Fork 0
M3X-720: Enhance ins/del wrapping on atomic tags while diffing #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
7f20a6c
f25c8a8
6929c95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,18 +88,26 @@ | |
| return result && result[1]; | ||
| } | ||
|
|
||
| // inspect the last tag in word (from its opening '<'); to an earlier '>' in that | ||
| // slice means loose text e.g. "a > b" in a <script>, not a tag, so they bail out. | ||
|
Comment on lines
+91
to
+92
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why those comment are inline?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. paraphrase it, I'm struggling to understand what you mean here |
||
|
|
||
| /** | ||
| * Checks if the current word is the end of an atomic tag (i.e. it has all the characters, | ||
| * except for the end bracket of the closing tag, such as '<iframe></iframe'). | ||
| * | ||
| * @param {string} word The characters of the current token read so far. | ||
| * @param {string} tag The ending tag to look for. | ||
| * | ||
| * @return {boolean} True if the word is now a complete token (including the end tag), | ||
| * false otherwise. | ||
| * @return {boolean} True if word ends with an opening (non-self-closing) tag for the given | ||
| * atomic tag name. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not about specifically atomic tags, isn't? same for |
||
| */ | ||
| function isOpeningTagOf(word, tag){ | ||
| var tagText = word.substring(word.lastIndexOf('<')); | ||
| if (tagText.indexOf('>') !== tagText.length - 1) return false; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not use inline conditions. same for closing tag |
||
| return new RegExp('^<' + tag + '(\\s|>)').test(tagText) && !/\/>$/.test(tagText); | ||
| } | ||
|
|
||
| /** | ||
| * @return {boolean} True if word ends with a closing tag for the given atomic tag name. | ||
| */ | ||
| function isEndOfAtomicTag(word, tag){ | ||
| return word.substring(word.length - tag.length - 2) === ('</' + tag); | ||
| function isClosingTagOf(word, tag){ | ||
| var tagText = word.substring(word.lastIndexOf('<')); | ||
| if (tagText.indexOf('>') !== tagText.length - 1) return false; | ||
| return new RegExp('^</' + tag + '(\\s|>)').test(tagText); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -175,6 +183,7 @@ | |
| var mode = 'char'; | ||
| var currentWord = ''; | ||
| var currentAtomicTag = ''; | ||
| var currentAtomicTagDepth = 0; | ||
| var words = []; | ||
| for (var i = 0; i < html.length; i++){ | ||
| var char = html[i]; | ||
|
|
@@ -184,6 +193,8 @@ | |
| if (atomicTag){ | ||
| mode = 'atomic_tag'; | ||
| currentAtomicTag = atomicTag; | ||
| // skip standalone tags like <script> and <style> | ||
| currentAtomicTagDepth = isEndOfTag(char) ? 1 : 0; | ||
| currentWord += char; | ||
| } else if (isStartofHTMLComment(currentWord)){ | ||
| mode = 'html_comment'; | ||
|
|
@@ -202,14 +213,22 @@ | |
| } | ||
| break; | ||
| case 'atomic_tag': | ||
| if (isEndOfTag(char) && isEndOfAtomicTag(currentWord, currentAtomicTag)){ | ||
| currentWord += '>'; | ||
| words.push(createToken(currentWord)); | ||
| currentWord = ''; | ||
| currentAtomicTag = ''; | ||
| mode = 'char'; | ||
| } else { | ||
| currentWord += char; | ||
| currentWord += char; | ||
| // track the same name nested tags depth; | ||
| // end the atomic token only when it returns to 0. | ||
| if (isEndOfTag(char)){ | ||
| if (isClosingTagOf(currentWord, currentAtomicTag)){ | ||
| currentAtomicTagDepth--; | ||
| if (currentAtomicTagDepth <= 0){ | ||
| words.push(createToken(currentWord)); | ||
| currentWord = ''; | ||
| currentAtomicTag = ''; | ||
| currentAtomicTagDepth = 0; | ||
| mode = 'char'; | ||
|
sirenevenkii marked this conversation as resolved.
|
||
| } | ||
| } else if (isOpeningTagOf(currentWord, currentAtomicTag)){ | ||
| currentAtomicTagDepth++; | ||
| } | ||
| } | ||
| break; | ||
| case 'html_comment': | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.