Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt |
— | — | @@ -746,12 +746,11 @@ |
747 | 747 | // class. Can we work out a static negative class instead? |
748 | 748 | // XXX: Exclude uppercase chars from non-latin languages too! |
749 | 749 | trail:(! [A-Z \t(),.:-] tc:text_char { return tc })* { |
750 | | - var obj = new TagTk( 'a', |
751 | | - [ |
752 | | - new KV('data-mw-type', 'internal') |
753 | | - ] ), |
| 750 | + var obj = new SelfclosingTagTk( 'wikilink' ), |
754 | 751 | textTokens = []; |
755 | 752 | obj.attribs.push( new KV('href', target) ); |
| 753 | + |
| 754 | + // Deal with content. XXX: Properly support pipe-trick etc |
756 | 755 | if (lcontent && lcontent.length) { |
757 | 756 | textTokens = lcontent; |
758 | 757 | if (trail) { |
— | — | @@ -765,8 +764,10 @@ |
766 | 765 | textTokens = $.extend(true, [], target); |
767 | 766 | } |
768 | 767 | } |
| 768 | + |
| 769 | + obj.attribs.push( new KV( 'content', flatten( textTokens ) ) ); |
769 | 770 | //console.warn( "XXX:" + pp([obj].concat(textTokens, [new EndTagTk( 'a' )])) ); |
770 | | - return [obj].concat(textTokens, [new EndTagTk( 'a' )]); |
| 771 | + return [obj]; |
771 | 772 | } |
772 | 773 | |
773 | 774 | link_text |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js |
— | — | @@ -65,6 +65,7 @@ |
66 | 66 | return { async: true }; |
67 | 67 | } |
68 | 68 | } else { |
| 69 | + token.rank = this.rank; |
69 | 70 | return { token: token }; |
70 | 71 | } |
71 | 72 | }; |
— | — | @@ -80,6 +81,7 @@ |
81 | 82 | // Remove the target from the attributes |
82 | 83 | expandData.token.attribs = attributes; |
83 | 84 | if ( expandData.async ) { |
| 85 | + expandData.token.rank = this.rank; |
84 | 86 | expandData.cb( [expandData.token], false ); |
85 | 87 | } |
86 | 88 | }; |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js |
— | — | @@ -0,0 +1,48 @@ |
| 2 | +/** |
| 3 | + * Simple link handler. Registers after template expansions, as an |
| 4 | + * asynchronous transform. |
| 5 | + * |
| 6 | + * @author Gabriel Wicke <gwicke@wikimedia.org> |
| 7 | + * |
| 8 | + * * Collect description/parameter tokens between 'a' tags |
| 9 | + * * Extract image options and add image html if target is media/image |
| 10 | + * namespace |
| 11 | + * * |
| 12 | + * |
| 13 | + * |
| 14 | + * TODO: keep round-trip information in meta tag or the like |
| 15 | + * |
| 16 | + * |
| 17 | + * |
| 18 | + * Pro/Contra of single token vs. tags and tokens |
| 19 | + * - Need to collect description tokens between a and /a |
| 20 | + * + noinclude etc handled automatically by having all tokens on content level |
| 21 | + */ |
| 22 | + |
| 23 | +function WikiLinkHandler( manager, isInclude ) { |
| 24 | + this.manager = manager; |
| 25 | + this.manager.addTransform( this.onWikiLink.bind( this ), this.rank, 'tag', 'wikilink' ); |
| 26 | +} |
| 27 | + |
| 28 | +WikiLinkHandler.prototype.rank = 1.15; // after AttributeExpander |
| 29 | + |
| 30 | +WikiLinkHandler.prototype.onWikiLink = function ( token, manager, cb ) { |
| 31 | + // Split off and normalize namespace |
| 32 | + // Compare with image/media namespaces |
| 33 | + // handle image |
| 34 | + // handle |
| 35 | + // Check if page exists |
| 36 | + // |
| 37 | + var obj = new TagTk( 'a', [ this.manager.env.lookupKV( token.attribs, 'href' ) ] ); |
| 38 | + obj.attribs.push( new KV('data-mw-type', 'internal') ); |
| 39 | + var out = [obj].concat( this.manager.env.lookupKV( token.attribs, 'content' ).v, |
| 40 | + new EndTagTk( 'a' ) ); |
| 41 | + //console.warn( JSON.stringify( out, null, 2 ) ); |
| 42 | + return { tokens: out }; |
| 43 | +}; |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +if (typeof module == "object") { |
| 48 | + module.exports.WikiLinkHandler = WikiLinkHandler; |
| 49 | +} |
Property changes on: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 50 | + native |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | Sanitizer = require('./ext.core.Sanitizer.js').Sanitizer, |
28 | 28 | TemplateHandler = require('./ext.core.TemplateHandler.js').TemplateHandler, |
29 | 29 | AttributeExpander = require('./ext.core.AttributeExpander.js').AttributeExpander, |
| 30 | + WikiLinkHandler = require('./ext.core.LinkHandler.js').WikiLinkHandler, |
30 | 31 | Cite = require('./ext.Cite.js').Cite, |
31 | 32 | FauxHTML5 = require('./mediawiki.HTML5TreeBuilder.node.js').FauxHTML5, |
32 | 33 | DOMPostProcessor = require('./mediawiki.DOMPostProcessor.js').DOMPostProcessor, |
— | — | @@ -165,7 +166,8 @@ |
166 | 167 | // Expand attributes after templates to avoid expanding unused branches |
167 | 168 | // XXX: Should we support further processing after attribute |
168 | 169 | // expansion? |
169 | | - AttributeExpander |
| 170 | + AttributeExpander, |
| 171 | + WikiLinkHandler |
170 | 172 | /* ExtensionHandler1, */ |
171 | 173 | /* ExtensionHandler2, */ |
172 | 174 | ], |