@@ -289,6 +289,8 @@ Autolinker.prototype = {
289289 * @return {String } The HTML, with matches automatically linked.
290290 */
291291 link : function ( textOrHtml ) {
292+ if ( ! textOrHtml ) { return "" ; } // handle `null` and `undefined`
293+
292294 var htmlParser = this . getHtmlParser ( ) ,
293295 htmlNodes = htmlParser . parse ( textOrHtml ) ,
294296 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, {
14081410/**
14091411 * @abstract
14101412 * @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  
14181426 */
14191427Autolinker . htmlParser . HtmlNode = Autolinker . Util . extend ( Object , {
1420-
1428+
14211429 /**
14221430 * @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.
14311442 */
14321443 text : "" ,
1433-
1434-
1444+
1445+
14351446 /**
14361447 * @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).
14381450 */
14391451 constructor : function ( cfg ) {
14401452 Autolinker . Util . assign ( this , cfg ) ;
14411453 } ,
14421454
1443-
1455+
14441456 /**
14451457 * Returns a string name for the type of node that this class represents.
1446- *
1458+ *
14471459 * @abstract
14481460 * @return {String }
14491461 */
14501462 getType : Autolinker . Util . abstractMethod ,
1451-
1452-
1463+
1464+
14531465 /**
14541466 * Retrieves the {@link #text} for the HtmlNode.
1455- *
1467+ *
14561468 * @return {String }
14571469 */
14581470 getText : function ( ) {
@@ -1506,104 +1518,110 @@ Autolinker.htmlParser.CommentNode = Autolinker.Util.extend( Autolinker.htmlParse
15061518/**
15071519 * @class Autolinker.htmlParser.ElementNode
15081520 * @extends Autolinker.htmlParser.HtmlNode
1509- *
1521+ *
15101522 * 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.
15131526 */
15141527Autolinker . htmlParser . ElementNode = Autolinker . Util . extend ( Autolinker . htmlParser . HtmlNode , {
1515-
1528+
15161529 /**
15171530 * @cfg {String} tagName (required)
1518- *
1531+ *
15191532 * The name of the tag that was matched.
15201533 */
15211534 tagName : '' ,
1522-
1535+
15231536 /**
15241537 * @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.
15271541 */
15281542 closing : false ,
15291543
1530-
1544+
15311545 /**
15321546 * Returns a string name for the type of node that this class represents.
1533- *
1547+ *
15341548 * @return {String }
15351549 */
15361550 getType : function ( ) {
15371551 return 'element' ;
15381552 } ,
1539-
1553+
15401554
15411555 /**
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+ *
15441559 * @return {String }
15451560 */
15461561 getTagName : function ( ) {
15471562 return this . tagName ;
15481563 } ,
1549-
1550-
1564+
1565+
15511566 /**
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+ *
15551570 * @return {Boolean }
15561571 */
15571572 isClosing : function ( ) {
15581573 return this . closing ;
15591574 }
1560-
1575+
15611576} ) ;
15621577/*global Autolinker */
15631578/**
15641579 * @class Autolinker.htmlParser.EntityNode
15651580 * @extends Autolinker.htmlParser.HtmlNode
1566- *
1581+ *
15671582 * 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.
15741591 */
15751592Autolinker . htmlParser . EntityNode = Autolinker . Util . extend ( Autolinker . htmlParser . HtmlNode , {
1576-
1593+
15771594 /**
15781595 * Returns a string name for the type of node that this class represents.
1579- *
1596+ *
15801597 * @return {String }
15811598 */
15821599 getType : function ( ) {
15831600 return 'entity' ;
15841601 }
1585-
1602+
15861603} ) ;
15871604/*global Autolinker */
15881605/**
15891606 * @class Autolinker.htmlParser.TextNode
15901607 * @extends Autolinker.htmlParser.HtmlNode
1591- *
1608+ *
15921609 * 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.
15951613 */
15961614Autolinker . htmlParser . TextNode = Autolinker . Util . extend ( Autolinker . htmlParser . HtmlNode , {
1597-
1615+
15981616 /**
15991617 * Returns a string name for the type of node that this class represents.
1600- *
1618+ *
16011619 * @return {String }
16021620 */
16031621 getType : function ( ) {
16041622 return 'text' ;
16051623 }
1606-
1624+
16071625} ) ;
16081626/*global Autolinker */
16091627/**
0 commit comments