Index: trunk/parsers/wikidom/lib/wiki.AnnotationRenderer.js |
— | — | @@ -10,6 +10,21 @@ |
11 | 11 | |
12 | 12 | /* Methods */ |
13 | 13 | |
| 14 | + /** |
| 15 | + * Adds a set of insertions around a range of text. |
| 16 | + * |
| 17 | + * Insertions for the same range will be nested in order of declaration. |
| 18 | + * @example |
| 19 | + * ar = new wiki.AnnotationRenderer(); |
| 20 | + * ar.wrapWithText( { 'offset': 1, 'length': 1 }, '[', ']' ); |
| 21 | + * ar.wrapWithText( { 'offset': 1, 'length': 1 }, '{', '}' ); |
| 22 | + * // Outputs: "a[{b}]c" |
| 23 | + * console.log( ar.apply( 'abc' ) ); |
| 24 | + * |
| 25 | + * @param range Object: Range to insert text around |
| 26 | + * @param pre String: Text to insert before range |
| 27 | + * @param post String: Text to insert after range |
| 28 | + */ |
14 | 29 | this.wrapWithText = function( range, pre, post ) { |
15 | 30 | var start = range.offset; |
16 | 31 | if ( !( start in insertions ) ) { |
— | — | @@ -25,12 +40,27 @@ |
26 | 41 | } |
27 | 42 | }; |
28 | 43 | |
| 44 | + /** |
| 45 | + * Adds a set of opening and closing XML tags around a range of text. |
| 46 | + * |
| 47 | + * This is a convenience function, and has the same nesting behavior as wrapWithText. |
| 48 | + * |
| 49 | + * @param range Object: Range to insert XML tags around |
| 50 | + * @param tag String: XML tag name |
| 51 | + * @param attributes Object: XML tag attributes (optional) |
| 52 | + */ |
29 | 53 | this.wrapWithXml = function( range, tag, attributes ) { |
30 | 54 | that.wrapWithText( |
31 | 55 | range, wiki.util.xml.open( tag, attributes ), wiki.util.xml.close( tag ) |
32 | 56 | ); |
33 | 57 | }; |
34 | 58 | |
| 59 | + /** |
| 60 | + * Applies insertions to text. |
| 61 | + * |
| 62 | + * @param text String: Text to apply insertions to |
| 63 | + * @return String: Wrapped text |
| 64 | + */ |
35 | 65 | this.apply = function( text ) { |
36 | 66 | var out = ''; |
37 | 67 | for ( var i = 0, iMax = text.length; i <= iMax; i++ ) { |