r106207 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106206‎ | r106207 | r106208 >
Date:15:55, 14 December 2011
Author:gwicke
Status:deferred (Comments)
Tags:
Comment:
Add implicit level attribute to WikiDom headings.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMConverter.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.DOMConverter.js
@@ -31,6 +31,26 @@
3232 handler: this._convertHTMLLeaf,
3333 type: 'paragraph'
3434 };
 35+ case 'h1':
 36+ case 'h2':
 37+ case 'h3':
 38+ case 'h4':
 39+ case 'h5':
 40+ case 'h6':
 41+ var res = {
 42+ handler: this._convertHTMLLeaf,
 43+ type: 'heading',
 44+ attribs: { }
 45+ };
 46+ switch ( nodeName.toLowerCase() ) {
 47+ case 'h1': res.attribs.level = 1; break;
 48+ case 'h2': res.attribs.level = 2; break;
 49+ case 'h3': res.attribs.level = 3; break;
 50+ case 'h4': res.attribs.level = 4; break;
 51+ case 'h5': res.attribs.level = 5; break;
 52+ case 'h6': res.attribs.level = 6; break;
 53+ }
 54+ return res;
3555 case 'li':
3656 case 'dl':
3757 case 'dd':
@@ -99,6 +119,9 @@
100120 // Call a handler for the particular node type
101121 var hi = this.getHTMLHandlerInfo( cnode.nodeName );
102122 var res = hi.handler.call(this, cnode, 0, hi.type );
 123+ if ( hi.attribs ) {
 124+ $.extend( res.node.attributes, hi.attribs );
 125+ }
103126 out.children.push( res.node );
104127 break;
105128 case Node.TEXT_NODE:
@@ -170,6 +193,9 @@
171194 // Call a handler for the particular node type
172195 var hi = this.getHTMLHandlerInfo( cnode.nodeName );
173196 var res = hi.handler.call(this, cnode, offset + 1, hi.type );
 197+ if ( hi.attribs ) {
 198+ $.extend( res.node.attributes, hi.attribs );
 199+ }
174200 wnode.children.push( res.node );
175201 offset = res.offset;
176202 break;

Follow-up revisions

RevisionCommit summaryAuthorDate
r106312Follow-up to r106208 and r106207. Both good catches, thanks Yair! As this code...gwicke10:13, 15 December 2011

Comments

#Comment by Yair rand (talk | contribs)   05:25, 15 December 2011

Re "switch ( nodeName.toLowerCase() ) {case 'h1': res.attribs.level = 1;case 'h2'"... etc., since it's already verified that nodeName is H1-H6, couldn't the entire section just be replaced with return { handler: this._convertHTMLLeaf, type: 'heading', attribs: { level: +nodeName.substr(1) } }; ?

Status & tagging log