| 1 | /*global Autolinker */ |
| 2 | /** |
| 3 | * @abstract |
| 4 | * @class Autolinker.htmlParser.HtmlNode |
| 5 | * |
| 6 | * Represents an HTML node found in an input string. An HTML node is one of the |
| 7 | * following: |
| 8 | * |
| 9 | * 1. An {@link Autolinker.htmlParser.ElementNode ElementNode}, which represents |
| 10 | * HTML tags. |
| 11 | * 2. A {@link Autolinker.htmlParser.CommentNode CommentNode}, which represents |
| 12 | * HTML comments. |
| 13 | * 3. A {@link Autolinker.htmlParser.TextNode TextNode}, which represents text |
| 14 | * outside or within HTML tags. |
| 15 | * 4. A {@link Autolinker.htmlParser.EntityNode EntityNode}, which represents |
| 16 | * one of the known HTML entities that Autolinker looks for. This includes |
| 17 | * common ones such as " and   |
| 18 | */ |
| 19 | Autolinker.htmlParser.HtmlNode = Autolinker.Util.extend( Object, { |
| 20 | |
| 21 | /** |
| 22 | * @cfg {Number} offset (required) |
| 23 | * |
| 24 | * The offset of the HTML node in the original text that was parsed. |
| 25 | */ |
| 26 | offset : undefined, |
| 27 | |
| 28 | /** |
| 29 | * @cfg {String} text (required) |
| 30 | * |
| 31 | * The text that was matched for the HtmlNode. |
| 32 | * |
| 33 | * - In the case of an {@link Autolinker.htmlParser.ElementNode ElementNode}, |
| 34 | * this will be the tag's text. |
| 35 | * - In the case of an {@link Autolinker.htmlParser.CommentNode CommentNode}, |
| 36 | * this will be the comment's text. |
| 37 | * - In the case of a {@link Autolinker.htmlParser.TextNode TextNode}, this |
| 38 | * will be the text itself. |
| 39 | * - In the case of a {@link Autolinker.htmlParser.EntityNode EntityNode}, |
| 40 | * this will be the text of the HTML entity. |
| 41 | */ |
| 42 | text : undefined, |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * @constructor |
| 47 | * @param {Object} cfg The configuration properties for the Match instance, |
| 48 | * specified in an Object (map). |
| 49 | */ |
| 50 | constructor : function( cfg ) { |
| 51 | Autolinker.Util.assign( this, cfg ); |
| 52 | |
| 53 | // @if DEBUG |
| 54 | if( this.offset == null ) throw new Error( '`offset` cfg required' ); |
| 55 | if( this.text == null ) throw new Error( '`text` cfg required' ); |
| 56 | // @endif |
| 57 | }, |
| 58 | |
| 59 | |
| 60 | /** |
| 61 | * Returns a string name for the type of node that this class represents. |
| 62 | * |
| 63 | * @abstract |
| 64 | * @return {String} |
| 65 | */ |
| 66 | getType : Autolinker.Util.abstractMethod, |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * Retrieves the {@link #offset} of the HtmlNode. This is the offset of the |
| 71 | * HTML node in the original string that was parsed. |
| 72 | * |
| 73 | * @return {Number} |
| 74 | */ |
| 75 | getOffset : function() { |
| 76 | return this.offset; |
| 77 | }, |
| 78 | |
| 79 | |
| 80 | /** |
| 81 | * Retrieves the {@link #text} for the HtmlNode. |
| 82 | * |
| 83 | * @return {String} |
| 84 | */ |
| 85 | getText : function() { |
| 86 | return this.text; |
| 87 | } |
| 88 | |
| 89 | } ); |