Jforrester has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/74563


Change subject: De-alienate <code>foo</code> blocks (code element)
......................................................................

De-alienate <code>foo</code> blocks (code element)

Adding the <code> element as a matched text style annotation, plus some
tests (for all the other un-tested text styles as well, whilst I'm at
it).

We'll need an icon, a button and a way of the buttons not forever
extending the length of the toolbar to properly edit <code> spans, but
this is a start.

Bug: 51590
Change-Id: I5438bcf2ec6eeb2e50400f8013964f91c33ce455
---
M modules/ve/ce/annotations/ve.ce.TextStyleAnnotation.js
M modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js
M modules/ve/test/ce/ve.ce.ContentBranchNode.test.js
3 files changed, 147 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/63/74563/1

diff --git a/modules/ve/ce/annotations/ve.ce.TextStyleAnnotation.js 
b/modules/ve/ce/annotations/ve.ce.TextStyleAnnotation.js
index 40227f4..ce5f535 100644
--- a/modules/ve/ce/annotations/ve.ce.TextStyleAnnotation.js
+++ b/modules/ve/ce/annotations/ve.ce.TextStyleAnnotation.js
@@ -222,3 +222,20 @@
 ve.ce.TextStyleSubScriptAnnotation.static.name = 'textStyle/subScript';
 ve.ce.TextStyleSubScriptAnnotation.static.tagName = 'sub';
 ve.ce.annotationFactory.register( ve.ce.TextStyleSubScriptAnnotation );
+
+/**
+ * ContentEditable code annotation.
+ *
+ * @class
+ * @extends ve.ce.TextStyleAnnotation
+ * @constructor
+ * @param {ve.dm.TextStyleCodeScriptAnnotation} model
+ */
+ve.ce.TextStyleCodeScriptAnnotation = function 
VeCeTextStyleCodeScriptAnnotation( model, config ) {
+       ve.ce.TextStyleAnnotation.call( this, model, config );
+       this.$.addClass( 've-ce-TextStyleCodeScriptAnnotation' );
+};
+ve.inheritClass( ve.ce.TextStyleCodeScriptAnnotation, 
ve.ce.TextStyleAnnotation );
+ve.ce.TextStyleCodeScriptAnnotation.static.name = 'textStyle/code';
+ve.ce.TextStyleCodeScriptAnnotation.static.tagName = 'code';
+ve.ce.annotationFactory.register( ve.ce.TextStyleCodeScriptAnnotation );
diff --git a/modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js 
b/modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js
index 67d22ba..2ecd932 100644
--- a/modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js
+++ b/modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js
@@ -41,7 +41,8 @@
                'strong': 'strong',
                'em': 'emphasize',
                'sup': 'superScript',
-               'sub': 'subScript'
+               'sub': 'subScript',
+               'code': 'code'
        };
        return {
                'type': 'textStyle/' + 
types[domElements[0].nodeName.toLowerCase()]
@@ -60,7 +61,8 @@
                'strong': 'strong',
                'emphasize': 'em',
                'superScript': 'sup',
-               'subScript': 'sub'
+               'subScript': 'sub',
+               'code': 'code'
        };
        return [ doc.createElement( nodeNames[dataElement.type.substring( 10 )] 
) ];
 };
@@ -254,3 +256,19 @@
 ve.dm.TextStyleSubScriptAnnotation.static.name = 'textStyle/subScript';
 ve.dm.TextStyleSubScriptAnnotation.static.matchTagNames = ['sub'];
 ve.dm.modelRegistry.register( ve.dm.TextStyleSubScriptAnnotation );
+
+/**
+ * DataModel code script annotation.
+ *
+ * @class
+ * @extends ve.dm.TextStyleAnnotation
+ * @constructor
+ * @param {Object} element
+ */
+ve.dm.TextStyleCodeScriptAnnotation = function 
VeDmTextStyleCodeScriptAnnotation( element ) {
+       ve.dm.TextStyleAnnotation.call( this, element );
+};
+ve.inheritClass( ve.dm.TextStyleCodeScriptAnnotation, 
ve.dm.TextStyleAnnotation );
+ve.dm.TextStyleCodeScriptAnnotation.static.name = 'textStyle/code';
+ve.dm.TextStyleCodeScriptAnnotation.static.matchTagNames = ['code'];
+ve.dm.modelRegistry.register( ve.dm.TextStyleCodeScriptAnnotation );
diff --git a/modules/ve/test/ce/ve.ce.ContentBranchNode.test.js 
b/modules/ve/test/ce/ve.ce.ContentBranchNode.test.js
index 1cd4504..8b239af 100644
--- a/modules/ve/test/ce/ve.ce.ContentBranchNode.test.js
+++ b/modules/ve/test/ce/ve.ce.ContentBranchNode.test.js
@@ -35,6 +35,116 @@
                        'html': '<b>abc</b>'
                },
                {
+                       'msg': 'Italic text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/italic' } ]],
+                               ['b', [ { 'type': 'textStyle/italic' } ]],
+                               ['c', [ { 'type': 'textStyle/italic' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<i>abc</i>'
+               },
+               {
+                       'msg': 'Underline text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/underline' } ]],
+                               ['b', [ { 'type': 'textStyle/underline' } ]],
+                               ['c', [ { 'type': 'textStyle/underline' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<u>abc</u>'
+               },
+               {
+                       'msg': 'Strikethrough text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/strike' } ]],
+                               ['b', [ { 'type': 'textStyle/strike' } ]],
+                               ['c', [ { 'type': 'textStyle/strike' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<s>abc</s>'
+               },
+               {
+                       'msg': 'Small text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/small' } ]],
+                               ['b', [ { 'type': 'textStyle/small' } ]],
+                               ['c', [ { 'type': 'textStyle/small' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<small>abc</small>'
+               },
+               {
+                       'msg': 'Big text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/big' } ]],
+                               ['b', [ { 'type': 'textStyle/big' } ]],
+                               ['c', [ { 'type': 'textStyle/big' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<big>abc</big>'
+               },
+               {
+                       'msg': 'Strong text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/strong' } ]],
+                               ['b', [ { 'type': 'textStyle/strong' } ]],
+                               ['c', [ { 'type': 'textStyle/strong' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<strong>abc</strong>'
+               },
+               {
+                       'msg': 'Emphasized text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/emphasize' } ]],
+                               ['b', [ { 'type': 'textStyle/emphasize' } ]],
+                               ['c', [ { 'type': 'textStyle/emphasize' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<em>abc</em>'
+               },
+               {
+                       'msg': 'Superscript text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/superScript' } ]],
+                               ['b', [ { 'type': 'textStyle/superScript' } ]],
+                               ['c', [ { 'type': 'textStyle/superScript' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<sup>abc</sup>'
+               },
+               {
+                       'msg': 'Subscript text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/subScript' } ]],
+                               ['b', [ { 'type': 'textStyle/subScript' } ]],
+                               ['c', [ { 'type': 'textStyle/subScript' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<sub>abc</sub>'
+               },
+               {
+                       'msg': 'Code text',
+                       'data': [
+                               { 'type': 'paragraph' },
+                               ['a', [ { 'type': 'textStyle/code' } ]],
+                               ['b', [ { 'type': 'textStyle/code' } ]],
+                               ['c', [ { 'type': 'textStyle/code' } ]],
+                               { 'type': '/paragraph' }
+                       ],
+                       'html': '<code>abc</code>'
+               },
+               {
                        'msg': 'Bold character, plain character, italic 
character',
                        'data': [
                                { 'type': 'paragraph' },

-- 
To view, visit https://gerrit.wikimedia.org/r/74563
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5438bcf2ec6eeb2e50400f8013964f91c33ce455
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Jforrester <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to