[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceExtensions[REL1_27]: VisualEditor: introducing DOM preprocessor

2017-03-24 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/344609 )

Change subject: VisualEditor: introducing DOM preprocessor
..


VisualEditor: introducing DOM preprocessor

A DOM preprocessor is introduced which currently only replaces certain
spans (underline and strike). This is neccessary because it is the
correct way to handle nested spans, where regexs would fail. In the wake
of this change, handling of external links was improved, as the html
produced was a mess.

Patch Set 2: Implemented CR

Change-Id: I6a63524576ebc0869bb77c9621106d563625f390
---
M VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js
1 file changed, 44 insertions(+), 11 deletions(-)

Approvals:
  Robert Vogel: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js 
b/VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js
index e655a45..e987169 100644
--- a/VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js
+++ b/VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js
@@ -337,7 +337,7 @@
}
 
function _image2wiki(text) {
-   var images = 
text.match(/(]*?)>)?]*?)\/>(<\/a>)?/gi);
+   var images = 
text.match(/(]*?)>)?]*?)\/?>(<\/a>)?/gi);
if (!images)
return text;
 
@@ -614,13 +614,15 @@
_externalLinkNo++;
}
linkHtml = anchorFormat.format(
-   encodeURI( linkTarget.replace( /%20/g, 
' ' ) ), // href
-   linkLabel,  
// linkLabel
-   'external_link',
// data-bs-type
-   'external bs-external-link 
bs-protocol-'+protocol,  // class
-   $( '' ).text( link ).html(),  
// data-bs-wikitext
-   encodeURI( linkTarget.replace( /%20/g, 
' ' ) ), // data-mce-href
-   $( '' ).text( linkLabel ).html()  
// title
+   encodeURI( linkTarget.replace( /%20/g, 
' ' ) ),  // href
+   linkLabel,  
 // linkLabel
+   'external_link',
 // data-bs-type
+   'external bs-external-link 
bs-protocol-' + protocol, // class
+   // encoding neccessary, because this is 
possible: [http://www.hallowelt.biz Hallo 
Welt!]
+   encodeURI( $( '' ).text( link 
).html() ),  // data-bs-wikitext
+   encodeURI( linkTarget.replace( /%20/g, 
' ' ) ),  // data-mce-href
+   // encoding neccessary, because this is 
possible: [http://www.hallowelt.biz Hallo 
Welt!]
+   encodeURI( $( '' ).text( 
linkLabel ).html() )  // title
);
text = text.replace("[" + linkNoWrap + "]", 
linkHtml);
}
@@ -1425,7 +1427,7 @@
$(document).trigger('BSVisualEditorBeforeHtmlToWiki', 
[textObject]);
// get the text back
text = textObject.text;
-   // Normalize UTF8 spaces as aof TinyMCE 3.4.9
+   // Normalize UTF8 spaces as of TinyMCE 3.4.9
text = text.replace(/\u00a0/gi, '');
//Save content of pre tags
text = _preservePres(text);
@@ -1438,8 +1440,6 @@
text = text.replace(/(.*?)<\/i>/gmi, "''$1''");
//underline needs no conversion
text = text.replace(/(.*?)<\/strike>/gi, "$1");
-   text = text.replace(/(.*?)<\/span>/gi, "$1");
-   text = text.replace(/(.*?)<\/span>/gi, "$1");
//sub and sup need no conversion
 
text = text.replace(/]*>/gmi, 
"@@br_emptyline_first@@");
@@ -2289,6 +2289,37 @@
}
 
/**
+* Preprocess HTML in DOM form. This is mainly used to replace tags
+* @param {String} text
+* @returns {String}
+*/
+   function _preprocessHtml2Wiki( text ) {
+   // convert html text to DOM
+   var $dom = $( "" + text + "" );
+
+   // perform the actual preprocessing
+   $dom.find( "span[style*='text-decoration: underline']" 
).replaceWith( function() {
+   return "" + $( this ).html() + 

[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceExtensions[REL1_27]: VisualEditor: introducing DOM preprocessor

2017-03-24 Thread Robert Vogel (Code Review)
Robert Vogel has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/344609 )

Change subject: VisualEditor: introducing DOM preprocessor
..

VisualEditor: introducing DOM preprocessor

A DOM preprocessor is introduced which currently only replaces certain
spans (underline and strike). This is neccessary because it is the
correct way to handle nested spans, where regexs would fail. In the wake
of this change, handling of external links was improved, as the html
produced was a mess.

Patch Set 2: Implemented CR

Change-Id: I6a63524576ebc0869bb77c9621106d563625f390
---
M VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js
1 file changed, 44 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions 
refs/changes/09/344609/1

diff --git a/VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js 
b/VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js
index e655a45..e987169 100644
--- a/VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js
+++ b/VisualEditor/resources/tiny_mce_plugins/bswikicode/plugin.js
@@ -337,7 +337,7 @@
}
 
function _image2wiki(text) {
-   var images = 
text.match(/(]*?)>)?]*?)\/>(<\/a>)?/gi);
+   var images = 
text.match(/(]*?)>)?]*?)\/?>(<\/a>)?/gi);
if (!images)
return text;
 
@@ -614,13 +614,15 @@
_externalLinkNo++;
}
linkHtml = anchorFormat.format(
-   encodeURI( linkTarget.replace( /%20/g, 
' ' ) ), // href
-   linkLabel,  
// linkLabel
-   'external_link',
// data-bs-type
-   'external bs-external-link 
bs-protocol-'+protocol,  // class
-   $( '' ).text( link ).html(),  
// data-bs-wikitext
-   encodeURI( linkTarget.replace( /%20/g, 
' ' ) ), // data-mce-href
-   $( '' ).text( linkLabel ).html()  
// title
+   encodeURI( linkTarget.replace( /%20/g, 
' ' ) ),  // href
+   linkLabel,  
 // linkLabel
+   'external_link',
 // data-bs-type
+   'external bs-external-link 
bs-protocol-' + protocol, // class
+   // encoding neccessary, because this is 
possible: [http://www.hallowelt.biz Hallo 
Welt!]
+   encodeURI( $( '' ).text( link 
).html() ),  // data-bs-wikitext
+   encodeURI( linkTarget.replace( /%20/g, 
' ' ) ),  // data-mce-href
+   // encoding neccessary, because this is 
possible: [http://www.hallowelt.biz Hallo 
Welt!]
+   encodeURI( $( '' ).text( 
linkLabel ).html() )  // title
);
text = text.replace("[" + linkNoWrap + "]", 
linkHtml);
}
@@ -1425,7 +1427,7 @@
$(document).trigger('BSVisualEditorBeforeHtmlToWiki', 
[textObject]);
// get the text back
text = textObject.text;
-   // Normalize UTF8 spaces as aof TinyMCE 3.4.9
+   // Normalize UTF8 spaces as of TinyMCE 3.4.9
text = text.replace(/\u00a0/gi, '');
//Save content of pre tags
text = _preservePres(text);
@@ -1438,8 +1440,6 @@
text = text.replace(/(.*?)<\/i>/gmi, "''$1''");
//underline needs no conversion
text = text.replace(/(.*?)<\/strike>/gi, "$1");
-   text = text.replace(/(.*?)<\/span>/gi, "$1");
-   text = text.replace(/(.*?)<\/span>/gi, "$1");
//sub and sup need no conversion
 
text = text.replace(/]*>/gmi, 
"@@br_emptyline_first@@");
@@ -2289,6 +2289,37 @@
}
 
/**
+* Preprocess HTML in DOM form. This is mainly used to replace tags
+* @param {String} text
+* @returns {String}
+*/
+   function _preprocessHtml2Wiki( text ) {
+   // convert html text to DOM
+   var $dom = $( "" + text + "" );
+
+   // perform the actual preprocessing
+   $dom.find( "span[style*='text-decoration: underline']" 
).replaceWith( function() {
+   return