Index: trunk/parsers/wikidom/tests/wiki.test.js |
— | — | @@ -119,7 +119,7 @@ |
120 | 120 | { |
121 | 121 | 'type': 'ilink', |
122 | 122 | 'range': { 'offset': 15, 'length': 4 }, |
123 | | - 'data': { 'title': 'Main_Page' } |
| 123 | + 'data': { 'namespace': 'Main', 'title': 'Main_Page' } |
124 | 124 | } |
125 | 125 | ] |
126 | 126 | } |
— | — | @@ -306,3 +306,32 @@ |
307 | 307 | } |
308 | 308 | ] ); |
309 | 309 | } ); |
| 310 | + |
| 311 | +test( 'Transclusion', function() { |
| 312 | + assertSerializations( [ |
| 313 | + { |
| 314 | + 'subject': 'transclusion', |
| 315 | + 'dom': { 'blocks': [ { |
| 316 | + 'type': 'transclusion', |
| 317 | + 'namespace': 'Template', |
| 318 | + 'title': 'Test' |
| 319 | + } ] }, |
| 320 | + 'html': '<a href="https://www.mediawiki.org/wiki/Template:Test">Template:Test</a>', |
| 321 | + 'wikitext': '{{Test}}' |
| 322 | + } |
| 323 | + ] ); |
| 324 | +} ); |
| 325 | + |
| 326 | +test( 'Parameter', function() { |
| 327 | + assertSerializations( [ |
| 328 | + { |
| 329 | + 'subject': 'transclusion', |
| 330 | + 'dom': { 'blocks': [ { |
| 331 | + 'type': 'parameter', |
| 332 | + 'name': '1' |
| 333 | + } ] }, |
| 334 | + 'html': '{{{1}}}', |
| 335 | + 'wikitext': '{{{1}}}' |
| 336 | + } |
| 337 | + ] ); |
| 338 | +} ); |
Index: trunk/parsers/wikidom/lib/wiki.Context.js |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +wiki.Context = function() { |
| 3 | + |
| 4 | + /* Private Members */ |
| 5 | + |
| 6 | + var params = {}; |
| 7 | + |
| 8 | + /* Methods */ |
| 9 | + |
| 10 | + this.pageExists = function( namespace, title ) { |
| 11 | + return false; |
| 12 | + }; |
| 13 | + |
| 14 | + this.getPageDom = function( namespace, title ) { |
| 15 | + return ''; |
| 16 | + }; |
| 17 | + |
| 18 | + this.setParam = function( name, document ) { |
| 19 | + params[name] = document; |
| 20 | + }; |
| 21 | + |
| 22 | + this.getParam = function( name ) { |
| 23 | + return name in params ? params[name] : null; |
| 24 | + }; |
| 25 | +}; |
Property changes on: trunk/parsers/wikidom/lib/wiki.Context.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 26 | + native |
Added: svn:mime-type |
2 | 27 | + text/plain |
Index: trunk/parsers/wikidom/lib/wiki.HtmlRenderer.js |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | /** |
3 | 3 | * Serializes a WikiDom into HTML. |
4 | 4 | */ |
5 | | -wiki.HtmlRenderer = function() { |
| 5 | +wiki.HtmlRenderer = function( context ) { |
6 | 6 | |
7 | 7 | /* Private Members */ |
8 | 8 | |
— | — | @@ -12,7 +12,9 @@ |
13 | 13 | 'heading': renderHeading, |
14 | 14 | 'paragraph': renderParagraph, |
15 | 15 | 'list': renderList, |
16 | | - 'table': renderTable |
| 16 | + 'table': renderTable, |
| 17 | + 'transclusion': renderTransclusion, |
| 18 | + 'parameter': renderParameter |
17 | 19 | }; |
18 | 20 | |
19 | 21 | /* Private Methods */ |
— | — | @@ -96,6 +98,20 @@ |
97 | 99 | return out.join( '\n' ); |
98 | 100 | } |
99 | 101 | |
| 102 | + function renderTransclusion( transclusion ) { |
| 103 | + var title = []; |
| 104 | + if ( transclusion.namespace !== 'Main' ) { |
| 105 | + title.push( transclusion.namespace ) |
| 106 | + } |
| 107 | + title.push( transclusion.title ); |
| 108 | + title = title.join( ':' ); |
| 109 | + return wiki.util.xml.tag( 'a', { 'href': '/wiki/' + title }, title ); |
| 110 | + } |
| 111 | + |
| 112 | + function renderParameter( parameter ) { |
| 113 | + return '{{{' + parameter.name + '}}}'; |
| 114 | + } |
| 115 | + |
100 | 116 | function renderItem( item ) { |
101 | 117 | if ( 'lists' in item && item.lists.length ) { |
102 | 118 | var out = []; |
Index: trunk/parsers/wikidom/lib/wiki.WikitextRenderer.js |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | /** |
3 | 3 | * Serializes a WikiDom into Wikitext. |
4 | 4 | */ |
5 | | -wiki.WikitextRenderer = function() { |
| 5 | +wiki.WikitextRenderer = function( context ) { |
6 | 6 | |
7 | 7 | /* Private Members */ |
8 | 8 | |
— | — | @@ -12,7 +12,9 @@ |
13 | 13 | 'heading': renderHeading, |
14 | 14 | 'paragraph': renderParagraph, |
15 | 15 | 'list': renderList, |
16 | | - 'table': renderTable |
| 16 | + 'table': renderTable, |
| 17 | + 'transclusion': renderTransclusion, |
| 18 | + 'parameter': renderParameter |
17 | 19 | }; |
18 | 20 | |
19 | 21 | /* Private Methods */ |
— | — | @@ -99,6 +101,21 @@ |
100 | 102 | return out.join( '\n' ); |
101 | 103 | } |
102 | 104 | |
| 105 | + function renderTransclusion( transclusion ) { |
| 106 | + var title = []; |
| 107 | + if ( transclusion.namespace === 'Main' ) { |
| 108 | + title.push( '' ); |
| 109 | + } else if ( transclusion.namespace !== 'Template' ) { |
| 110 | + title.push( transclusion.namespace ) |
| 111 | + } |
| 112 | + title.push( transclusion.title ); |
| 113 | + return '{{' + title.join( ':' ) + '}}'; |
| 114 | + } |
| 115 | + |
| 116 | + function renderParameter( parameter ) { |
| 117 | + return '{{{' + parameter.name + '}}}'; |
| 118 | + } |
| 119 | + |
103 | 120 | function renderItem( item, path ) { |
104 | 121 | if ( 'lists' in item && item.lists.length ) { |
105 | 122 | var out = []; |
Index: trunk/parsers/wikidom/lib/wiki.js |
— | — | @@ -21,6 +21,13 @@ |
22 | 22 | * table |
23 | 23 | * rows: Array of arrays of cell objects |
24 | 24 | * attributes: Plain object |
| 25 | + * transclusion |
| 26 | + * namespace: String |
| 27 | + * title: String |
| 28 | + * parameters: Array of documents |
| 29 | + * parameter |
| 30 | + * name: String or integer |
| 31 | + * default: Document object |
25 | 32 | * |
26 | 33 | * // Components |
27 | 34 | * |