Forum closed. New forum available at http://community.wymeditor.org/

stylesheet CSS setting (parsing) rules are wrong

Discuss features, code, contributions, ideas, suggestions, ...
For bugs, patches and feature requests, please post on the Trac:
http://trac.wymeditor.org/

stylesheet CSS setting (parsing) rules are wrong

Postby ono on Fri Jan 02, 2009 4:47 pm

First of all, I'm very glad that WYMeditor does exists, it is superior by its design to all other WYSIWYG components. However I'm little disappointed by some bits and bites, especially by what does stylesheet API customization setting does.

As docs say WYM expects for class date for p tag something like:
Code: Select all
/* PARA: Date */
.date p{
  color: #ccf;
  /* background-color: #ff9; border: 2px solid #ee9; */
}


However if you look closely this definition is by all matter against CSS, actually the selector is wrong. It does not select para with class date, but the para that has ancestor of date class.
The proper one is p.date, but if I try use something like:
Code: Select all
/* PARA: Date */
p.date{
  color: #ccf;
  /* background-color: #ff9; border: 2px solid #ee9; */
}

this doesn't work at all. Moreover I get JS errors (so the parser is not even error proof).

I dunno how it was possible to overlook such thing or what were original intentions of the author, but IMHO something is wrong.
Can we except a fix that will let CSS parser to parse proper CSS class definitions such as above and also ones that does not contain line breaks, i.e.:

Code: Select all
/* LI: Icon */ li.icon { background-image: url(icon.png) no-reapeat top left; }


Now I'm really stuck because I'm forced to define available classes in 2 places in the site CSS and in the WYM startup scripts, just because WYM doesn't understand proper CSS definitions.

BTW. I tried to register myself at TRAC to submit bug report, however the registration page seems to be disabled.
User avatar
ono
 
Posts: 3
Joined: Wed Dec 31, 2008 4:15 pm

Re: stylesheet CSS setting (parsing) rules are wrong

Postby ono on Wed Jan 07, 2009 3:57 pm

Attaching SVN patch that fixes CSS parsing, so the proper rules are parsed in the form of tag.class { css-definition }, (WymCssStyleDeclaration regexp was changed from \\\x2e[a-z-_0-9]+[\\sa-z1-6]* to [a-z1-6]*\\.[a-z-_0-9]+ and WymCssStyleDeclaration function was fixed to split style by dot character not space. This patch changes also RegExp hexadecimal coded characters (why the hell it was made so obscure) /\\\x2a into /\\*.

This patch works for me like a charm and now I can reuse my CSS also to define wymeditor rules.
Code: Select all
Index: src/wymeditor/jquery.wymeditor.js
===================================================================
--- src/wymeditor/jquery.wymeditor.js   (wersja 575)
+++ src/wymeditor/jquery.wymeditor.js   (kopia robocza)
@@ -3576,20 +3576,20 @@
   this.mapHandler('WymCss', 'Ignore');

   if(only_wym_blocks == true){
-    this.addEntryPattern("/\\\x2a[<\\s]*WYMeditor[>\\s]*\\\x2a/", 'Ignore', 'WymCss');
-    this.addExitPattern("/\\\x2a[<\/\\s]*WYMeditor[>\\s]*\\\x2a/", 'WymCss');
+    this.addEntryPattern("/\\*[<\\s]*WYMeditor[>\\s]*\\*/", 'Ignore', 'WymCss');
+    this.addExitPattern("/\\*[<\/\\s]*WYMeditor[>\\s]*\\*/", 'WymCss');
   }

-  this.addSpecialPattern("\\\x2e[a-z-_0-9]+[\\sa-z1-6]*", 'WymCss', 'WymCssStyleDeclaration');
+  this.addSpecialPattern("[a-z1-6]*\\.[a-z-_0-9]+", 'WymCss', 'WymCssStyleDeclaration');

-  this.addEntryPattern("/\\\x2a", 'WymCss', 'WymCssComment');
-  this.addExitPattern("\\\x2a/", 'WymCssComment');
+  this.addEntryPattern("/\\*", 'WymCss', 'WymCssComment');
+  this.addExitPattern("\\*/", 'WymCssComment');

-  this.addEntryPattern("\x7b", 'WymCss', 'WymCssStyle');
-  this.addExitPattern("\x7d", 'WymCssStyle');
+  this.addEntryPattern("{", 'WymCss', 'WymCssStyle');
+  this.addExitPattern("}", 'WymCssStyle');

-  this.addEntryPattern("/\\\x2a", 'WymCssStyle', 'WymCssFeddbackStyle');
-  this.addExitPattern("\\\x2a/", 'WymCssFeddbackStyle');
+  this.addEntryPattern("/\\*", 'WymCssStyle', 'WymCssFeddbackStyle');
+  this.addExitPattern("\\*/", 'WymCssFeddbackStyle');

   return this;
};
@@ -3663,17 +3663,10 @@

WYMeditor.WymCssParser.prototype.WymCssStyleDeclaration = function(match)
{
-  match = match.replace(/^([\s\.]*)|([\s\.*]*)$/gm, '');
+  var parts = match.split('.');
+  var tag = parts[0];
+  this._current_element = parts[1];

-  var tag = '';
-  if(match.indexOf(' ') > 0){
-    var parts = match.split(' ');
-    this._current_element = parts[0];
-    var tag = parts[1];
-  }else{
-    this._current_element = match;
-  }
-
   if(!this._has_title){
     this._current_item = {'title':(!tag?'':tag.toUpperCase()+': ')+this._current_element};
     this._has_title = true;
User avatar
ono
 
Posts: 3
Joined: Wed Dec 31, 2008 4:15 pm

Re: stylesheet CSS setting (parsing) rules are wrong

Postby beermad on Thu Apr 09, 2009 2:15 pm

I'm glad you posted this as I was beginning to think I was doing something seriously wrong with my CSS.

This is certainly a bug that needs to be fixed. I'm wondering if there's a problem with the patch as published though, when I try to patch the script with it, it's failing:
Code: Select all
$ patch -p2 < /tmp/w.patch
patching file jquery.wymeditor.js
patch: **** malformed patch at line 34: };

Is it me or the patch? Unfortunately I'm not sufficiently well acquainted with patching to be sure...
beermad
 
Posts: 1
Joined: Thu Apr 09, 2009 2:09 pm


Return to Developers

Who is online

Users browsing this forum: No registered users and 6 guests