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

Custom tags and attributes

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

Custom tags and attributes

Postby PACE on Wed May 07, 2008 5:10 pm

Is there a way to prevent the editor from removing some tags/attributes like 'example:attr="123"' from the markup?

I have a CMS which enriches the content with attributes (only in editing mode). There may be even special tags which would be used for plugins later on. The code produced would of course not be valid HTML, but with namespaces being used it would be valid XML.

I suppose I could change this behaviour by modifying the parser, but is there some property/method so I can leave the file as it is?

br,
Ben
PACE
 
Posts: 15
Joined: Fri Oct 12, 2007 10:24 am
Location: Austria

Re: Custom tags and attributes

Postby PACE on Wed May 07, 2008 5:59 pm

Update: I have been able to influence the validation of attributes by adding attributes to the XhtmlValidator object in the parser. Only problem is, it only works with attributes without a namespace declaration. Once the attribute looks like "ns:attribute", it is still stripped of :|
PACE
 
Posts: 15
Joined: Fri Oct 12, 2007 10:24 am
Location: Austria

Re: Custom tags and attributes

Postby PACE on Wed May 07, 2008 6:28 pm

I figured it out by now - the regex in line 1469 is missing a colon, so the namespace portion of every attribute will be ignored. Unfortunately there does not seem to be a way to _overwrite_ regex patterns?

I reckon it would be no harm to integrate a colon into the expression (in the official release), since any invalid attributes are filtered later anyway! I just noticed that Wymeditor will modify the "xml:lang" attribute too (reducing it to "lang" only). So the "xml:lang" entry in XhtmlValidator never really is used.

Code: Select all
// proposed change
this.addSpecialPattern("\\s*[a-z-_0-9]*:?[a-z-_0-9]+\\s*(?=\=)\\s*", scope, 'TagAttributes');


Noticed that there is a ticket related to my needs too: http://trac.wymeditor.org/trac/ticket/94 :D
I just tried to tinker with it and I think it would not be that hard to implement, one would have to provide a method to alter the XhtmlValidator collection and some way to render the tags with a special class. Thinking about a plugin right now........

Any comments?

Sorry for posting like a bot :D

Ben
PACE
 
Posts: 15
Joined: Fri Oct 12, 2007 10:24 am
Location: Austria

Re: Custom tags and attributes

Postby mr_lundis on Thu May 08, 2008 4:02 pm

Take a look at this thread, if you haven't already:
viewtopic.php?f=2&t=308
Jonatan Lundin - designer, developer and forum moderator. You should follow me on Twitter!
mr_lundis
 
Posts: 335
Joined: Sun Dec 02, 2007 10:59 am
Location: Sweden

Re: Custom tags and attributes

Postby PACE on Thu May 15, 2008 9:03 pm

No, thank you for the link (though I searched a bit I didn't see this one).

But it covers namespaced elements only - Attributes are filtered out on lexer level already! I was able to get my namespaced attributes into WYMEditor by overwriting the lexer function addAttributeTokens (sadly there does not seem to be another way simply because the regex does not feature a colon) and by adding the custom attributes to the XhtmlValidator array like this:

Code: Select all
WYMeditor.XhtmlValidator._attributes.core.attributes.push(
   // valid attributes generated by backend
   'flare:content-id',
   'flare:content-type',
   'flare:href',
   
   // attributes generated at runtime
   'flare:changed',
   'flare:locked'
);


This works pretty good - the attributes are copied and left intact.

Nevertheless I think the lack of namespace support on attributes is a (minor) bug, because it will reduce the (valid) "xml:lang" attribute to "lang". I've posted this as an addendum to the change request at http://trac.wymeditor.org/trac/ticket/94

Would be nice to see this in the svn soon because then I could scrap my workaround function! And it's just a single line with no implications :wink:

br,
Benjamin
PACE
 
Posts: 15
Joined: Fri Oct 12, 2007 10:24 am
Location: Austria


Return to Developers

Who is online

Users browsing this forum: No registered users and 1 guest

cron