Add VisualEditor support for 'line' attribute

The line attribute sets line='1', as both Parsoid and VE
expect proper XML attributes.

Change-Id: I10b5717fcc4b8e84a3030425a4a6a9a865272830
This commit is contained in:
Ed Sanders 2015-06-06 17:40:26 +01:00
parent 04f2b607fa
commit d38d9c1994
6 changed files with 46 additions and 3 deletions

View file

@ -51,6 +51,7 @@
"VisualEditor/ve.ui.MWSyntaxHighlightInspectorTool.js" "VisualEditor/ve.ui.MWSyntaxHighlightInspectorTool.js"
], ],
"styles": [ "styles": [
"VisualEditor/ve.ce.MWSyntaxHighlightNode.css",
"VisualEditor/ve.ui.MWSyntaxHighlightInspector.css" "VisualEditor/ve.ui.MWSyntaxHighlightInspector.css"
], ],
"dependencies": [ "dependencies": [
@ -59,6 +60,7 @@
"messages": [ "messages": [
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title" "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title"
], ],
"targets": [ "desktop", "mobile" ] "targets": [ "desktop", "mobile" ]

View file

@ -10,6 +10,7 @@
"syntaxhighlight-error-category-desc": "There was an error when attempting to highlight code included on the page.", "syntaxhighlight-error-category-desc": "There was an error when attempting to highlight code included on the page.",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code": "Code", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code": "Code",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language": "Language", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language": "Language",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines": "Show line numbers",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title": "Code block", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title": "Code block",
"syntaxhighlight-error-pygments-invocation-failure": "Failed to invoke Pygments", "syntaxhighlight-error-pygments-invocation-failure": "Failed to invoke Pygments",
"syntaxhighlight-error-unknown-language": "Unknown language \"$1\"", "syntaxhighlight-error-unknown-language": "Unknown language \"$1\"",

View file

@ -15,6 +15,7 @@
"syntaxhighlight-error-category-desc": "Description on [[Special:TrackingCategories]] for the {{msg-mw|syntaxhighlight-error-category}} tracking category.", "syntaxhighlight-error-category-desc": "Description on [[Special:TrackingCategories]] for the {{msg-mw|syntaxhighlight-error-category}} tracking category.",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code": "Label for the code input field\n{{Identical|Code}}", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code": "Label for the code input field\n{{Identical|Code}}",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language": "Label for the language field\n{{Identical|Language}}", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language": "Label for the language field\n{{Identical|Language}}",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines": "Label for the checkbox to show line numbers",
"syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title": "Title for the VisualEditor syntax highlighter inspector, above the text area for the code", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title": "Title for the VisualEditor syntax highlighter inspector, above the text area for the code",
"syntaxhighlight-error-pygments-invocation-failure": "Error message shown when the syntax highlighting library failed with an unspecified error", "syntaxhighlight-error-pygments-invocation-failure": "Error message shown when the syntax highlighting library failed with an unspecified error",
"syntaxhighlight-error-unknown-language": "Error message shown when the programming language name was not recognized by the syntax highlighting library. Parameters:\n* $1 - the language name", "syntaxhighlight-error-unknown-language": "Error message shown when the programming language name was not recognized by the syntax highlighting library. Parameters:\n* $1 - the language name",

View file

@ -0,0 +1,11 @@
/*!
* VisualEditor ContentEditable MWSyntaxHighlightNode styles.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
.ve-ce-mwSyntaxHighlightNode pre {
/* Prevent silly wrapping on Safari and Chrome (https://bugs.webkit.org/show_bug.cgi?id=35935) */
word-wrap: normal;
}

View file

@ -50,6 +50,13 @@ ve.ce.MWSyntaxHighlightNode.prototype.onSetup = function () {
this.$element.addClass( 've-ce-mwSyntaxHighlightNode' ); this.$element.addClass( 've-ce-mwSyntaxHighlightNode' );
}; };
/** */
ve.ce.MWSyntaxHighlightNode.prototype.getBoundingRect = function () {
// HACK: Because nodes can overflow due to the pre tag, just use the
// first rect (of the wrapper div) for placing the context.
return this.rects[0];
};
/* Registration */ /* Registration */
ve.ce.nodeFactory.register( ve.ce.MWSyntaxHighlightNode ); ve.ce.nodeFactory.register( ve.ce.MWSyntaxHighlightNode );

View file

@ -52,6 +52,8 @@ ve.ui.MWSyntaxHighlightInspector.prototype.initialize = function () {
} }
} ); } );
this.showLinesCheckbox = new OO.ui.CheckboxInputWidget();
var languageField = new OO.ui.FieldLayout( this.language, { var languageField = new OO.ui.FieldLayout( this.language, {
align: 'top', align: 'top',
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language' ) label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language' )
@ -59,11 +61,19 @@ ve.ui.MWSyntaxHighlightInspector.prototype.initialize = function () {
codeField = new OO.ui.FieldLayout( this.input, { codeField = new OO.ui.FieldLayout( this.input, {
align: 'top', align: 'top',
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code' ) label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code' )
} ),
showLinesField = new OO.ui.FieldLayout( this.showLinesCheckbox, {
align: 'inline',
label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines' )
} ); } );
// Initialization // Initialization
this.$content.addClass( 've-ui-mwSyntaxHighlightInspector-content' ); this.$content.addClass( 've-ui-mwSyntaxHighlightInspector-content' );
this.form.$element.prepend( languageField.$element, codeField.$element ); this.form.$element.prepend(
languageField.$element,
codeField.$element,
showLinesField.$element
);
}; };
/** /**
@ -86,12 +96,18 @@ ve.ui.MWSyntaxHighlightInspector.prototype.getReadyProcess = function ( data ) {
ve.ui.MWSyntaxHighlightInspector.prototype.getSetupProcess = function ( data ) { ve.ui.MWSyntaxHighlightInspector.prototype.getSetupProcess = function ( data ) {
return ve.ui.MWSyntaxHighlightInspector.super.prototype.getSetupProcess.call( this, data ) return ve.ui.MWSyntaxHighlightInspector.super.prototype.getSetupProcess.call( this, data )
.next( function () { .next( function () {
var language = this.selectedNode.getAttribute( 'mw' ).attrs.lang || ''; var attrs = this.selectedNode.getAttribute( 'mw' ).attrs,
language = attrs.lang || '',
showLines = attrs.line !== undefined;
this.language.setValue( language ); this.language.setValue( language );
if ( !language ) { if ( !language ) {
this.language.setValidityFlag( true ); this.language.setValidityFlag( true );
} }
this.language.on( 'change', this.onChangeHandler ); this.language.on( 'change', this.onChangeHandler );
this.showLinesCheckbox.setSelected( showLines );
this.showLinesCheckbox.on( 'change', this.onChangeHandler );
}, this ); }, this );
}; };
@ -102,6 +118,7 @@ ve.ui.MWSyntaxHighlightInspector.prototype.getTeardownProcess = function ( data
return ve.ui.MWSyntaxHighlightInspector.super.prototype.getTeardownProcess.call( this, data ) return ve.ui.MWSyntaxHighlightInspector.super.prototype.getTeardownProcess.call( this, data )
.first( function () { .first( function () {
this.language.off( 'change', this.onChangeHandler ); this.language.off( 'change', this.onChangeHandler );
this.showLinesCheckbox.off( 'change', this.onChangeHandler );
}, this ); }, this );
}; };
@ -112,7 +129,11 @@ ve.ui.MWSyntaxHighlightInspector.prototype.updateMwData = function ( mwData ) {
// Parent method // Parent method
ve.ui.MWSyntaxHighlightInspector.super.prototype.updateMwData.call( this, mwData ); ve.ui.MWSyntaxHighlightInspector.super.prototype.updateMwData.call( this, mwData );
mwData.attrs.lang = this.language.getValue(); var language = this.language.getValue(),
showLines = this.showLinesCheckbox.isSelected();
mwData.attrs.lang = language || undefined;
mwData.attrs.line = showLines ? '1' : undefined;
}; };
/* Registration */ /* Registration */