Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/216434
Change subject: Add support for 'display' and 'line' attribute ...................................................................... Add support for 'display' and 'line' attribute Doesn't support 'inline' for now as that would require converting the node to a content node. The line attribute sets line='1', as both Parsoid and VE expect proper XML attributes. The official documentation about what values line can take is incorrect (see bug T101602). Change-Id: I10b5717fcc4b8e84a3030425a4a6a9a865272830 --- M extension.json M i18n/en.json M i18n/qqq.json A modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.css M modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.js M modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.js 6 files changed, 84 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SyntaxHighlight_GeSHi refs/changes/34/216434/1 diff --git a/extension.json b/extension.json index 9d5e58e..23bc2fd 100644 --- a/extension.json +++ b/extension.json @@ -41,6 +41,7 @@ "modules/VisualEditor/ve.ui.MWSyntaxHighlightInspectorTool.js" ], "styles": [ + "modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.css", "modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.css" ], "dependencies": [ @@ -49,6 +50,9 @@ ], "messages": [ "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code", + "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-default", + "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-wrap", + "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-inline", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title" ], diff --git a/i18n/en.json b/i18n/en.json index 0172d4d..5468be3 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -11,6 +11,9 @@ "syntaxhighlight-err-loading": "(error loading supported language list)", "syntaxhighlight-err-language": "Invalid language.", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code": "Code", + "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-default": "Default", + "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-wrap": "Wrap lines", + "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-inline": "Inline", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language": "Language", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title": "Code block", "geshi.css": "/* CSS placed here will be applied to GeSHi syntax highlighting */" diff --git a/i18n/qqq.json b/i18n/qqq.json index fa81ade..e23425b 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -14,6 +14,9 @@ "syntaxhighlight-err-loading": "Error message shown to the user if loading the list of supported languages fails.", "syntaxhighlight-err-language": "Error message shown if the user inputs an invalid or unsupported language.", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code": "Label for the code input field", + "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-default": "Label for the 'default' value of the display attribute.", + "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-wrap": "Label for the 'wrap lines' value of the display attribute.", + "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-inline": "Label for the 'inline' value of the display attribute.", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language": "Label for the language field", "syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title": "Title for the VisualEditor syntax highlighter inspector", "geshi.css": "CSS comment" diff --git a/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.css b/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.css new file mode 100644 index 0000000..2c5bb4a --- /dev/null +++ b/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.css @@ -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; +} diff --git a/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.js b/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.js index 8da70f0..8a4cc10 100644 --- a/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.js +++ b/modules/VisualEditor/ve.ce.MWSyntaxHighlightNode.js @@ -56,6 +56,13 @@ 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 */ ve.ce.nodeFactory.register( ve.ce.MWSyntaxHighlightNode ); diff --git a/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.js b/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.js index e94a33d..2d5d675 100644 --- a/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.js +++ b/modules/VisualEditor/ve.ui.MWSyntaxHighlightInspector.js @@ -52,6 +52,28 @@ } } ); + this.displaySelect = new OO.ui.ButtonSelectWidget( { + items: [ + new OO.ui.ButtonOptionWidget( { + data: 'pre', + label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-default' ) + } ), + new OO.ui.ButtonOptionWidget( { + data: 'div', + label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-wrap' ) + } ) + // TODO: Support inline nodes + /* + new OO.ui.ButtonOptionWidget( { + data: 'none', + label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-display-inline' ) + } ) + */ + ] + } ); + + this.showLinesCheckbox = new OO.ui.CheckboxInputWidget(); + var languageField = new OO.ui.FieldLayout( this.language, { align: 'top', label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language' ) @@ -59,11 +81,24 @@ codeField = new OO.ui.FieldLayout( this.input, { align: 'top', label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code' ) + } ), + displayField = new OO.ui.FieldLayout( this.displaySelect, { + align: 'top', + label: 'Display' + } ), + showLinesField = new OO.ui.FieldLayout( this.showLinesCheckbox, { + align: 'inline', + label: 'Show line numbers' } ); // Initialization this.$content.addClass( 've-ui-mwSyntaxHighlightInspector-content' ); - this.form.$element.prepend( languageField.$element, codeField.$element ); + this.form.$element.prepend( + languageField.$element, + codeField.$element, + displayField.$element, + showLinesField.$element + ); }; /** @@ -86,10 +121,20 @@ ve.ui.MWSyntaxHighlightInspector.prototype.getSetupProcess = function ( data ) { return ve.ui.MWSyntaxHighlightInspector.super.prototype.getSetupProcess.call( this, data ) .next( function () { - var language = this.selectedNode.getAttribute( 'mw' ).attrs.lang || ''; + var attrs = this.selectedNode.getAttribute( 'mw' ).attrs, + language = attrs.lang || '', + display = attrs.enclose || 'pre', + showLines = attrs.line !== undefined; + this.language.setValue( language ); this.language.setValidityFlag( true ); this.language.on( 'change', this.onChangeHandler ); + + this.displaySelect.selectItemByData( display ); + this.displaySelect.on( 'choose', this.onChangeHandler ); + + this.showLinesCheckbox.setSelected( showLines ); + this.showLinesCheckbox.on( 'change', this.onChangeHandler ); }, this ); }; @@ -100,6 +145,8 @@ return ve.ui.MWSyntaxHighlightInspector.super.prototype.getTeardownProcess.call( this, data ) .first( function () { this.language.off( 'change', this.onChangeHandler ); + this.displaySelect.off( 'choose', this.onChangeHandler ); + this.showLinesCheckbox.off( 'change', this.onChangeHandler ); }, this ); }; @@ -110,7 +157,13 @@ // Parent method ve.ui.MWSyntaxHighlightInspector.super.prototype.updateMwData.call( this, mwData ); - mwData.attrs.lang = this.language.getValue(); + var language = this.language.getValue(), + display = this.displaySelect.getSelectedItem().getData(), + showLines = this.showLinesCheckbox.isSelected(); + + mwData.attrs.lang = language || undefined; + mwData.attrs.enclose = display && display !== 'pre' ? display : undefined; + mwData.attrs.line = showLines ? '1' : undefined; }; /* Registration */ -- To view, visit https://gerrit.wikimedia.org/r/216434 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I10b5717fcc4b8e84a3030425a4a6a9a865272830 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/SyntaxHighlight_GeSHi Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits