-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,020 additions
and
99 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Checks whether `subject` contains substring at specific `index`. | ||
* | ||
* @ignore | ||
* @param {string} subject The subject to search in. | ||
* @param {string} substring The substring to search/ | ||
* @param {number} index The index to search substring. | ||
* @param {boolean} lookBehind Whether to look behind (true) or ahead (false). | ||
* @return {boolean} Returns a boolean whether the substring exists. | ||
*/ | ||
export default function hasSubstringAtIndex(subject, substring, index, lookBehind = true) { | ||
let indexOffset = 0; | ||
if (lookBehind) { | ||
indexOffset = - substring.length + 1; | ||
} | ||
const extractedSubstring = subject.substr(index + indexOffset, substring.length); | ||
return extractedSubstring.toLowerCase() === substring; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { REGEXP_WHITESPACE } from 'helper/reg_exp/const'; | ||
|
||
const STATE_START_TAG = 0; | ||
const STATE_NON_WHITESPACE = 1; | ||
const STATE_DONE = 2; | ||
|
||
/** | ||
* Parses the tag name from html content | ||
* | ||
* @param {string} tagContent The tag content | ||
* @return {string} Returns the tag name | ||
*/ | ||
export default function parseTagName(tagContent) { | ||
let state = STATE_START_TAG; | ||
let tagName = ''; | ||
let index = 0; | ||
while (state !== STATE_DONE) { | ||
const char = tagContent[index++].toLowerCase(); | ||
switch (char) { | ||
case '<': | ||
break; | ||
case '>': | ||
state = STATE_DONE; | ||
break; | ||
default: | ||
if (REGEXP_WHITESPACE.test(char)) { | ||
if (state === STATE_NON_WHITESPACE) { | ||
state = STATE_DONE; | ||
} | ||
} else { | ||
if (state === STATE_START_TAG) { | ||
state = STATE_NON_WHITESPACE; | ||
} | ||
if (char !== '/') { | ||
tagName += char; | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
return tagName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { expect } from 'chai'; | ||
import parseTagName from 'helper/strip/parse_tag_name'; | ||
|
||
describe('parseTagName', function() { | ||
|
||
it('should parse the tag name from markup', function () { | ||
expect(parseTagName("<img title=\"foo 'bar'\"/>")).to.be.equal('img'); | ||
expect(parseTagName("< b>Wonderful world</b>")).to.be.equal('b'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.