You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
anchorTagStackCount=0,// used to only process text around anchor tags, and any inner text/html they may have
236
225
resultHtml=[];
237
226
238
227
for(vari=0,len=htmlNodes.length;i<len;i++){
239
-
varhtmlNode=htmlNodes[i];
228
+
varnode=htmlNodes[i],
229
+
nodeType=node.getType(),
230
+
nodeText=node.getText();
240
231
241
-
if(htmlNode.getType()==='element'){
232
+
if(nodeType==='element'){
242
233
// Process HTML nodes in the input `textOrHtml`
243
-
if(htmlNode.getTagName()==='a'){
244
-
if(!htmlNode.isClosing()){// it's the start <a> tag
234
+
if(node.getTagName()==='a'){
235
+
if(!node.isClosing()){// it's the start <a> tag
245
236
anchorTagStackCount++;
246
237
}else{// it's the end </a> tag
247
238
anchorTagStackCount=Math.max(anchorTagStackCount-1,0);// attempt to handle extraneous </a> tags by making sure the stack count never goes below 0
248
239
}
249
240
}
250
-
resultHtml.push(htmlNode.getText());// now add the text of the tag itself verbatim
241
+
resultHtml.push(nodeText);// now add the text of the tag itself verbatim
242
+
243
+
}elseif(nodeType==='entity'){
244
+
resultHtml.push(nodeText);// append HTML entity nodes (such as ' ') verbatim
251
245
252
246
}else{
253
247
// Process text nodes in the input `textOrHtml`
254
-
vartext=htmlNode.getText();
255
-
256
248
if(anchorTagStackCount===0){
257
-
// If we're not within an <a> tag, process the text node
258
-
varunescapedText=Autolinker.Util.splitAndCapture(text,htmlCharacterEntitiesRegex);// split at HTML entities, but include the HTML entities in the results array
* Parses text and HTML entity nodes from a given string. The input string should not have any HTML tags (elements)
133
+
* within it.
134
+
*
135
+
* @private
136
+
* @param {String} text The text to parse.
137
+
* @return {Autolinker.htmlParser.HtmlNode[]} An array of HtmlNodes to represent the
138
+
* {@link Autolinker.htmlParser.TextNode TextNodes} and {@link Autolinker.htmlParser.EntityNode EntityNodes} found.
139
+
*/
140
+
parseTextAndEntityNodes : function(text){
141
+
varnodes=[],
142
+
textAndEntityTokens=Autolinker.Util.splitAndCapture(text,this.htmlCharacterEntitiesRegex);// split at HTML entities, but include the HTML entities in the results array
143
+
144
+
// Every even numbered token is a TextNode, and every odd numbered token is an EntityNode
145
+
// For example: an input `text` of "Test "this" today" would turn into the
0 commit comments