diff options
Diffstat (limited to 'extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight')
6 files changed, 445 insertions, 0 deletions
diff --git a/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.css b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.css new file mode 100644 index 00000000..2c5bb4a8 --- /dev/null +++ b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/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/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.js b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.js new file mode 100644 index 00000000..fb5a0be6 --- /dev/null +++ b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ce.MWSyntaxHighlightNode.js @@ -0,0 +1,89 @@ +/*! + * VisualEditor ContentEditable MWSyntaxHighlightNode class. + * + * @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * ContentEditable MediaWiki syntax highlight node. + * + * @class + * @abstract + * + * @constructor + */ +ve.ce.MWSyntaxHighlightNode = function VeCeMWSyntaxHighlightNode() { +}; + +/* Inheritance */ + +OO.initClass( ve.ce.MWSyntaxHighlightNode ); + +/* Static Properties */ + +ve.ce.MWSyntaxHighlightNode.static.name = 'mwSyntaxHighlight'; + +ve.ce.MWSyntaxHighlightNode.static.primaryCommandName = 'syntaxhighlight'; + +/* Methods */ + +/** */ +ve.ce.MWSyntaxHighlightNode.prototype.generateContents = function () { + if ( !this.getModel().isLanguageSupported() ) { + return $.Deferred().reject().promise(); + } + // Parent method + return ve.ce.MWExtensionNode.prototype.generateContents.apply( this, arguments ); +}; + +/** */ +ve.ce.MWSyntaxHighlightNode.prototype.onSetup = function () { + // Parent method + ve.ce.MWExtensionNode.prototype.onSetup.call( this ); + + // DOM changes + 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 ]; +}; + +/* Concrete subclasses */ + +ve.ce.MWBlockSyntaxHighlightNode = function VeCeMWBlockSyntaxHighlightNode() { + // Parent method + ve.ce.MWBlockExtensionNode.super.apply( this, arguments ); + + // Mixin method + ve.ce.MWSyntaxHighlightNode.call( this ); +}; + +OO.inheritClass( ve.ce.MWBlockSyntaxHighlightNode, ve.ce.MWBlockExtensionNode ); + +OO.mixinClass( ve.ce.MWBlockSyntaxHighlightNode, ve.ce.MWSyntaxHighlightNode ); + +ve.ce.MWBlockSyntaxHighlightNode.static.name = 'mwBlockSyntaxHighlight'; + +ve.ce.MWInlineSyntaxHighlightNode = function VeCeMWInlineSyntaxHighlightNode() { + // Parent method + ve.ce.MWInlineExtensionNode.super.apply( this, arguments ); + + // Mixin method + ve.ce.MWSyntaxHighlightNode.call( this ); +}; + +OO.inheritClass( ve.ce.MWInlineSyntaxHighlightNode, ve.ce.MWInlineExtensionNode ); + +OO.mixinClass( ve.ce.MWInlineSyntaxHighlightNode, ve.ce.MWSyntaxHighlightNode ); + +ve.ce.MWInlineSyntaxHighlightNode.static.name = 'mwInlineSyntaxHighlight'; + +/* Registration */ + +ve.ce.nodeFactory.register( ve.ce.MWBlockSyntaxHighlightNode ); +ve.ce.nodeFactory.register( ve.ce.MWInlineSyntaxHighlightNode ); diff --git a/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js new file mode 100644 index 00000000..a3ea9597 --- /dev/null +++ b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.dm.MWSyntaxHighlightNode.js @@ -0,0 +1,135 @@ +/*! + * VisualEditor DataModel MWSyntaxHighlightNode class. + * + * @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * DataModel MediaWiki syntax highlight node. + * + * @class + * @abstract + * + * @constructor + */ +ve.dm.MWSyntaxHighlightNode = function VeDmMWSyntaxHighlightNode() { +}; + +/* Inheritance */ + +OO.initClass( ve.dm.MWSyntaxHighlightNode ); + +/* Static members */ + +ve.dm.MWSyntaxHighlightNode.static.name = 'mwSyntaxHighlight'; + +ve.dm.MWSyntaxHighlightNode.static.extensionName = 'syntaxhighlight'; + +ve.dm.MWSyntaxHighlightNode.static.getMatchRdfaTypes = function () { + return [ 'mw:Extension/syntaxhighlight', 'mw:Extension/source' ]; +}; + +/* Static methods */ + +/** + * @inheritdoc + */ +ve.dm.MWSyntaxHighlightNode.static.toDataElement = function ( domElements, converter ) { + // Parent method + var dataElement = ve.dm.MWExtensionNode.static.toDataElement( domElements, converter ), + isInline = this.isHybridInline( domElements, converter ), + type = isInline ? 'mwInlineSyntaxHighlight' : 'mwBlockSyntaxHighlight'; + + dataElement.type = type; + + return dataElement; +}; + +( function () { + var supportedLanguages = [ undefined ]; + + /** + * Register supported languages. + * + * @param {Array} languages + */ + ve.dm.MWSyntaxHighlightNode.static.addLanguages = function ( languages ) { + ve.batchPush( supportedLanguages, languages ); + }; + + /** + * Check if a language is supported + * + * @param {string} language Language name + * @return {boolean} The language is supported + */ + ve.dm.MWSyntaxHighlightNode.static.isLanguageSupported = function ( language ) { + return supportedLanguages.indexOf( language || undefined ) !== -1; + }; + + /** + * Get an array of all languages + * + * @return {Array} All currently supported languages + */ + ve.dm.MWSyntaxHighlightNode.static.getLanguages = function () { + return supportedLanguages.slice(); + }; +}() ); + +/* Methods */ + +/** + * Check if the node's current language is supported + * + * @return {boolean} The language is supported + */ +ve.dm.MWSyntaxHighlightNode.prototype.isLanguageSupported = function () { + return this.constructor.static.isLanguageSupported( this.getLanguage() ); +}; + +ve.dm.MWSyntaxHighlightNode.prototype.getLanguage = function () { + return this.getAttribute( 'mw' ).attrs.lang; +}; + +/* Concrete subclasses */ + +ve.dm.MWBlockSyntaxHighlightNode = function VeDmMWBlockSyntaxHighlightNode() { + // Parent method + ve.dm.MWBlockExtensionNode.super.apply( this, arguments ); + + // Mixin method + ve.dm.MWSyntaxHighlightNode.call( this ); +}; + +OO.inheritClass( ve.dm.MWBlockSyntaxHighlightNode, ve.dm.MWBlockExtensionNode ); + +OO.mixinClass( ve.dm.MWBlockSyntaxHighlightNode, ve.dm.MWSyntaxHighlightNode ); + +ve.dm.MWBlockSyntaxHighlightNode.static.name = 'mwBlockSyntaxHighlight'; + +ve.dm.MWBlockSyntaxHighlightNode.static.tagName = 'div'; + +ve.dm.MWInlineSyntaxHighlightNode = function VeDmMWInlineSyntaxHighlightNode() { + // Parent method + ve.dm.MWInlineExtensionNode.super.apply( this, arguments ); + + // Mixin method + ve.dm.MWSyntaxHighlightNode.call( this ); +}; + +OO.inheritClass( ve.dm.MWInlineSyntaxHighlightNode, ve.dm.MWInlineExtensionNode ); + +OO.mixinClass( ve.dm.MWInlineSyntaxHighlightNode, ve.dm.MWSyntaxHighlightNode ); + +ve.dm.MWInlineSyntaxHighlightNode.static.name = 'mwInlineSyntaxHighlight'; + +ve.dm.MWInlineSyntaxHighlightNode.static.tagName = 'code'; + +ve.dm.MWInlineSyntaxHighlightNode.static.isContent = true; + +/* Registration */ + +ve.dm.modelRegistry.register( ve.dm.MWBlockSyntaxHighlightNode ); +ve.dm.modelRegistry.register( ve.dm.MWInlineSyntaxHighlightNode ); diff --git a/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.css b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.css new file mode 100644 index 00000000..37644b95 --- /dev/null +++ b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.css @@ -0,0 +1,10 @@ +/*! + * VisualEditor UserInterface MWSyntaxHighlightInspector styles. + * + * @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +.ve-ui-mwSyntaxHighlightInspector-content .ve-ui-mwExtensionInspector-input textarea { + font-family: monospace, Courier; +} diff --git a/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.js b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.js new file mode 100644 index 00000000..257951af --- /dev/null +++ b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspector.js @@ -0,0 +1,163 @@ +/*! + * VisualEditor UserInterface MWSyntaxHighlightInspector class. + * + * @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * MediaWiki syntax highlight inspector. + * + * @class + * @extends ve.ui.MWLiveExtensionInspector + * + * @constructor + * @param {Object} [config] Configuration options + */ +ve.ui.MWSyntaxHighlightInspector = function VeUiMWSyntaxHighlightInspector() { + // Parent constructor + ve.ui.MWSyntaxHighlightInspector.super.apply( this, arguments ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.MWSyntaxHighlightInspector, ve.ui.MWLiveExtensionInspector ); + +/* Static properties */ + +ve.ui.MWSyntaxHighlightInspector.static.name = 'syntaxhighlight'; + +ve.ui.MWSyntaxHighlightInspector.static.icon = 'alienextension'; + +ve.ui.MWSyntaxHighlightInspector.static.size = 'large'; + +ve.ui.MWSyntaxHighlightInspector.static.title = OO.ui.deferMsg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title' ); + +ve.ui.MWSyntaxHighlightInspector.static.modelClasses = [ ve.dm.MWBlockSyntaxHighlightNode, ve.dm.MWInlineSyntaxHighlightNode ]; + +ve.ui.MWSyntaxHighlightInspector.static.dir = 'ltr'; + +/* Methods */ + +/** + * @inheritdoc + */ +ve.ui.MWSyntaxHighlightInspector.prototype.initialize = function () { + var languageField, codeField, showLinesField, + noneMsg = ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-none' ); + // Parent method + ve.ui.MWSyntaxHighlightInspector.super.prototype.initialize.call( this ); + + this.language = new OO.ui.ComboBoxWidget( { + menu: { + filterFromInput: true, + items: $.map( ve.dm.MWSyntaxHighlightNode.static.getLanguages(), function ( lang ) { + return new OO.ui.MenuOptionWidget( { data: lang, label: lang || noneMsg } ); + } ) + }, + input: { validate: function ( input ) { + return ve.dm.MWSyntaxHighlightNode.static.isLanguageSupported( input ); + } } + } ); + this.language.getInput().connect( this, { change: 'onLanguageInputChange' } ); + + this.showLinesCheckbox = new OO.ui.CheckboxInputWidget(); + + languageField = new OO.ui.FieldLayout( this.language, { + align: 'top', + label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-language' ) + } ); + codeField = new OO.ui.FieldLayout( this.input, { + align: 'top', + label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-code' ) + } ); + showLinesField = new OO.ui.FieldLayout( this.showLinesCheckbox, { + align: 'inline', + label: ve.msg( 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-showlines' ) + } ); + + // Initialization + this.$content.addClass( 've-ui-mwSyntaxHighlightInspector-content' ); + this.form.$element.prepend( + languageField.$element, + codeField.$element, + showLinesField.$element + ); +}; + +/** + * Handle input change events + * + * @param {string} value New value + */ +ve.ui.MWSyntaxHighlightInspector.prototype.onLanguageInputChange = function () { + var inspector = this; + this.language.getInput().isValid().done( function ( valid ) { + inspector.getActions().setAbilities( { done: valid } ); + } ); +}; + +/** + * @inheritdoc + */ +ve.ui.MWSyntaxHighlightInspector.prototype.getReadyProcess = function ( data ) { + return ve.ui.MWSyntaxHighlightInspector.super.prototype.getReadyProcess.call( this, data ) + .next( function () { + if ( this.language.input.getValue() ) { + this.input.focus(); + } else { + this.language.getMenu().toggle( true ); + } + }, this ); +}; + +/** + * @inheritdoc + */ +ve.ui.MWSyntaxHighlightInspector.prototype.getSetupProcess = function ( data ) { + return ve.ui.MWSyntaxHighlightInspector.super.prototype.getSetupProcess.call( this, data ) + .next( function () { + var attrs = this.selectedNode.getAttribute( 'mw' ).attrs, + language = attrs.lang || '', + showLines = attrs.line !== undefined; + + if ( ve.dm.MWSyntaxHighlightNode.static.isLanguageSupported( language ) ) { + this.language.input.setValue( language ); + } + this.language.input.on( 'change', this.onChangeHandler ); + + this.showLinesCheckbox.setSelected( showLines ); + this.showLinesCheckbox.on( 'change', this.onChangeHandler ); + }, this ); +}; + +/** + * @inheritdoc + */ +ve.ui.MWSyntaxHighlightInspector.prototype.getTeardownProcess = function ( data ) { + return ve.ui.MWSyntaxHighlightInspector.super.prototype.getTeardownProcess.call( this, data ) + .first( function () { + this.language.input.off( 'change', this.onChangeHandler ); + this.showLinesCheckbox.off( 'change', this.onChangeHandler ); + }, this ); +}; + +/** + * @inheritdoc + */ +ve.ui.MWSyntaxHighlightInspector.prototype.updateMwData = function ( mwData ) { + var language, showLines; + + // Parent method + ve.ui.MWSyntaxHighlightInspector.super.prototype.updateMwData.call( this, mwData ); + + language = this.language.input.getValue(); + showLines = this.showLinesCheckbox.isSelected(); + + mwData.attrs.lang = language || undefined; + mwData.attrs.line = showLines ? '1' : undefined; +}; + +/* Registration */ + +ve.ui.windowFactory.register( ve.ui.MWSyntaxHighlightInspector ); diff --git a/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspectorTool.js b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspectorTool.js new file mode 100644 index 00000000..1192976b --- /dev/null +++ b/extensions/SyntaxHighlight_GeSHi/modules/ve-syntaxhighlight/ve.ui.MWSyntaxHighlightInspectorTool.js @@ -0,0 +1,37 @@ +/*! + * VisualEditor UserInterface MWSyntaxHighlightInspectorTool class. + * + * @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/*global ve, OO */ + +/** + * MediaWiki UserInterface syntax highlight tool. + * + * @class + * @extends ve.ui.InspectorTool + * @constructor + * @param {OO.ui.ToolGroup} toolGroup + * @param {Object} [config] Configuration options + */ +ve.ui.MWSyntaxHighlightInspectorTool = function VeUiMWSyntaxHighlightInspectorTool( toolGroup, config ) { + ve.ui.InspectorTool.call( this, toolGroup, config ); +}; +OO.inheritClass( ve.ui.MWSyntaxHighlightInspectorTool, ve.ui.InspectorTool ); +ve.ui.MWSyntaxHighlightInspectorTool.static.name = 'syntaxhighlight'; +ve.ui.MWSyntaxHighlightInspectorTool.static.group = 'object'; +ve.ui.MWSyntaxHighlightInspectorTool.static.icon = 'alienextension'; +ve.ui.MWSyntaxHighlightInspectorTool.static.title = OO.ui.deferMsg( + 'syntaxhighlight-visualeditor-mwsyntaxhighlightinspector-title' ); +ve.ui.MWSyntaxHighlightInspectorTool.static.modelClasses = [ ve.dm.MWBlockSyntaxHighlightNode, ve.dm.MWInlineSyntaxHighlightNode ]; +ve.ui.MWSyntaxHighlightInspectorTool.static.commandName = 'syntaxhighlight'; +ve.ui.toolFactory.register( ve.ui.MWSyntaxHighlightInspectorTool ); + +ve.ui.commandRegistry.register( + new ve.ui.Command( + 'syntaxhighlight', 'window', 'open', + { args: [ 'syntaxhighlight' ], supportedSelections: [ 'linear' ] } + ) +); |