@@ -289,6 +289,8 @@ Autolinker.prototype = {
289
289
* @return {String } The HTML, with matches automatically linked.
290
290
*/
291
291
link : function ( textOrHtml ) {
292
+ if ( ! textOrHtml ) { return "" ; } // handle `null` and `undefined`
293
+
292
294
var htmlParser = this . getHtmlParser ( ) ,
293
295
htmlNodes = htmlParser . parse ( textOrHtml ) ,
294
296
anchorTagStackCount = 0 , // used to only process text around anchor tags, and any inner text/html they may have
@@ -1408,51 +1410,61 @@ Autolinker.htmlParser.HtmlParser = Autolinker.Util.extend( Object, {
1408
1410
/**
1409
1411
* @abstract
1410
1412
* @class Autolinker.htmlParser.HtmlNode
1411
- *
1412
- * Represents an HTML node found in an input string. An HTML node is one of the following:
1413
- *
1414
- * 1. An {@link Autolinker.htmlParser.ElementNode ElementNode}, which represents HTML tags.
1415
- * 2. A {@link Autolinker.htmlParser.TextNode TextNode}, which represents text outside or within HTML tags.
1416
- * 3. A {@link Autolinker.htmlParser.EntityNode EntityNode}, which represents one of the known HTML
1417
- * entities that Autolinker looks for. This includes common ones such as " and  
1413
+ *
1414
+ * Represents an HTML node found in an input string. An HTML node is one of the
1415
+ * following:
1416
+ *
1417
+ * 1. An {@link Autolinker.htmlParser.ElementNode ElementNode}, which represents
1418
+ * HTML tags.
1419
+ * 2. A {@link Autolinker.htmlParser.CommentNode CommentNode}, which represents
1420
+ * HTML comments.
1421
+ * 3. A {@link Autolinker.htmlParser.TextNode TextNode}, which represents text
1422
+ * outside or within HTML tags.
1423
+ * 4. A {@link Autolinker.htmlParser.EntityNode EntityNode}, which represents
1424
+ * one of the known HTML entities that Autolinker looks for. This includes
1425
+ * common ones such as " and  
1418
1426
*/
1419
1427
Autolinker . htmlParser . HtmlNode = Autolinker . Util . extend ( Object , {
1420
-
1428
+
1421
1429
/**
1422
1430
* @cfg {String} text (required)
1423
- *
1424
- * The original text that was matched for the HtmlNode.
1425
- *
1426
- * - In the case of an {@link Autolinker.htmlParser.ElementNode ElementNode}, this will be the tag's
1427
- * text.
1428
- * - In the case of a {@link Autolinker.htmlParser.TextNode TextNode}, this will be the text itself.
1429
- * - In the case of a {@link Autolinker.htmlParser.EntityNode EntityNode}, this will be the text of
1430
- * the HTML entity.
1431
+ *
1432
+ * The original text that was matched for the HtmlNode.
1433
+ *
1434
+ * - In the case of an {@link Autolinker.htmlParser.ElementNode ElementNode},
1435
+ * this will be the tag's text.
1436
+ * - In the case of an {@link Autolinker.htmlParser.CommentNode CommentNode},
1437
+ * this will be the comment's text.
1438
+ * - In the case of a {@link Autolinker.htmlParser.TextNode TextNode}, this
1439
+ * will be the text itself.
1440
+ * - In the case of a {@link Autolinker.htmlParser.EntityNode EntityNode},
1441
+ * this will be the text of the HTML entity.
1431
1442
*/
1432
1443
text : "" ,
1433
-
1434
-
1444
+
1445
+
1435
1446
/**
1436
1447
* @constructor
1437
- * @param {Object } cfg The configuration properties for the Match instance, specified in an Object (map).
1448
+ * @param {Object } cfg The configuration properties for the Match instance,
1449
+ * specified in an Object (map).
1438
1450
*/
1439
1451
constructor : function ( cfg ) {
1440
1452
Autolinker . Util . assign ( this , cfg ) ;
1441
1453
} ,
1442
1454
1443
-
1455
+
1444
1456
/**
1445
1457
* Returns a string name for the type of node that this class represents.
1446
- *
1458
+ *
1447
1459
* @abstract
1448
1460
* @return {String }
1449
1461
*/
1450
1462
getType : Autolinker . Util . abstractMethod ,
1451
-
1452
-
1463
+
1464
+
1453
1465
/**
1454
1466
* Retrieves the {@link #text} for the HtmlNode.
1455
- *
1467
+ *
1456
1468
* @return {String }
1457
1469
*/
1458
1470
getText : function ( ) {
@@ -1506,104 +1518,110 @@ Autolinker.htmlParser.CommentNode = Autolinker.Util.extend( Autolinker.htmlParse
1506
1518
/**
1507
1519
* @class Autolinker.htmlParser.ElementNode
1508
1520
* @extends Autolinker.htmlParser.HtmlNode
1509
- *
1521
+ *
1510
1522
* Represents an HTML element node that has been parsed by the {@link Autolinker.htmlParser.HtmlParser}.
1511
- *
1512
- * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more details.
1523
+ *
1524
+ * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more
1525
+ * details.
1513
1526
*/
1514
1527
Autolinker . htmlParser . ElementNode = Autolinker . Util . extend ( Autolinker . htmlParser . HtmlNode , {
1515
-
1528
+
1516
1529
/**
1517
1530
* @cfg {String} tagName (required)
1518
- *
1531
+ *
1519
1532
* The name of the tag that was matched.
1520
1533
*/
1521
1534
tagName : '' ,
1522
-
1535
+
1523
1536
/**
1524
1537
* @cfg {Boolean} closing (required)
1525
- *
1526
- * `true` if the element (tag) is a closing tag, `false` if its an opening tag.
1538
+ *
1539
+ * `true` if the element (tag) is a closing tag, `false` if its an opening
1540
+ * tag.
1527
1541
*/
1528
1542
closing : false ,
1529
1543
1530
-
1544
+
1531
1545
/**
1532
1546
* Returns a string name for the type of node that this class represents.
1533
- *
1547
+ *
1534
1548
* @return {String }
1535
1549
*/
1536
1550
getType : function ( ) {
1537
1551
return 'element' ;
1538
1552
} ,
1539
-
1553
+
1540
1554
1541
1555
/**
1542
- * Returns the HTML element's (tag's) name. Ex: for an <img> tag, returns "img".
1543
- *
1556
+ * Returns the HTML element's (tag's) name. Ex: for an <img> tag,
1557
+ * returns "img".
1558
+ *
1544
1559
* @return {String }
1545
1560
*/
1546
1561
getTagName : function ( ) {
1547
1562
return this . tagName ;
1548
1563
} ,
1549
-
1550
-
1564
+
1565
+
1551
1566
/**
1552
- * Determines if the HTML element (tag) is a closing tag. Ex: <div> returns
1553
- * `false`, while </div> returns `true`.
1554
- *
1567
+ * Determines if the HTML element (tag) is a closing tag. Ex: <div>
1568
+ * returns `false`, while </div> returns `true`.
1569
+ *
1555
1570
* @return {Boolean }
1556
1571
*/
1557
1572
isClosing : function ( ) {
1558
1573
return this . closing ;
1559
1574
}
1560
-
1575
+
1561
1576
} ) ;
1562
1577
/*global Autolinker */
1563
1578
/**
1564
1579
* @class Autolinker.htmlParser.EntityNode
1565
1580
* @extends Autolinker.htmlParser.HtmlNode
1566
- *
1581
+ *
1567
1582
* Represents a known HTML entity node that has been parsed by the {@link Autolinker.htmlParser.HtmlParser}.
1568
- * Ex: '&nbsp;', or '&#160;' (which will be retrievable from the {@link #getText} method.
1569
- *
1570
- * Note that this class will only be returned from the HtmlParser for the set of checked HTML entity nodes
1571
- * defined by the {@link Autolinker.htmlParser.HtmlParser#htmlCharacterEntitiesRegex}.
1572
- *
1573
- * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more details.
1583
+ * Ex: '&nbsp;', or '&#160;' (which will be retrievable from the {@link #getText}
1584
+ * method.
1585
+ *
1586
+ * Note that this class will only be returned from the HtmlParser for the set of
1587
+ * checked HTML entity nodes defined by the {@link Autolinker.htmlParser.HtmlParser#htmlCharacterEntitiesRegex}.
1588
+ *
1589
+ * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more
1590
+ * details.
1574
1591
*/
1575
1592
Autolinker . htmlParser . EntityNode = Autolinker . Util . extend ( Autolinker . htmlParser . HtmlNode , {
1576
-
1593
+
1577
1594
/**
1578
1595
* Returns a string name for the type of node that this class represents.
1579
- *
1596
+ *
1580
1597
* @return {String }
1581
1598
*/
1582
1599
getType : function ( ) {
1583
1600
return 'entity' ;
1584
1601
}
1585
-
1602
+
1586
1603
} ) ;
1587
1604
/*global Autolinker */
1588
1605
/**
1589
1606
* @class Autolinker.htmlParser.TextNode
1590
1607
* @extends Autolinker.htmlParser.HtmlNode
1591
- *
1608
+ *
1592
1609
* Represents a text node that has been parsed by the {@link Autolinker.htmlParser.HtmlParser}.
1593
- *
1594
- * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more details.
1610
+ *
1611
+ * See this class's superclass ({@link Autolinker.htmlParser.HtmlNode}) for more
1612
+ * details.
1595
1613
*/
1596
1614
Autolinker . htmlParser . TextNode = Autolinker . Util . extend ( Autolinker . htmlParser . HtmlNode , {
1597
-
1615
+
1598
1616
/**
1599
1617
* Returns a string name for the type of node that this class represents.
1600
- *
1618
+ *
1601
1619
* @return {String }
1602
1620
*/
1603
1621
getType : function ( ) {
1604
1622
return 'text' ;
1605
1623
}
1606
-
1624
+
1607
1625
} ) ;
1608
1626
/*global Autolinker */
1609
1627
/**
0 commit comments