Support for classnames as parameters for formatBlock and formatInline?
It would seriously rock if there could be a way to specify non only the element but also the class[es] to add to it.
Something like
<li data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="blockquote" data-wysihtml5-command-class="pullquote pull-left" >
I'm currently looking into this but my JS skills are obviously lacking :S
Thanks for the amazing work anyway!
Have you checked the "foreColor" command? It essentially wraps the content in a span-tag with the class name defined in the data-wysihtml5-command-value attribute.
That doesn't help with things like twitter bootstrap. For example I want a toolbar item that sets
<p class="lead">
Guess I wasn't entirely clear in my first message :) What I meant was that you could take the "foreColor" command and modify it to fit your usage scenario.
However, it might be more meaningful to generalize the "foreColor" command in WYSIHTML5 altogether so that it's simply a command that sets a class and then developers can use it for whatever they like: colors, text highlights, lead-ins, etc. In that case you'd probably need two versions, one for inline elements and one for block elements.
I imagine there's some trickery involved with regards to class exclusivity. For example, when dealing with colors, assigning "blue" should remove any other color classes since it isn't meaningful to define both "blue" and "red" on the same element (of course this is not always true, sometimes being able to define multiple colors (think: candy stripes) might be exactly what you want). However, in other cases you'd want to be able to add multiple custom classes to the same element. (One solution that comes to mind is being able to define a "scope" name for the classes in which case all classes in that scope would be mutually exclusive – replacing any class in that scope if already present on the element.)
I'm not a developer or maintainer of this plugin so the above is really just ideas and suppositions, @tiff can probably provide a more comprehensive answer and may be able to explain the design decisions behind the current implementation.
So I was working a bit more with WYSIHTML5 today and was browsing the source code. You can essentially do something like this:
Toolbar buttons (HTML):
<a data-wysihtml5-command="customClassBlock" data-wysihtml5-command-value="wysiwyg-lead">Block lead</a>
<a data-wysihtml5-command="customClassInline" data-wysihtml5-command-value="wysiwyg-lead">Inline lead</a>
Extending WYSIHTML5 commands (JavaScript):
wysihtml5.commands.customClassBlock = {
exec: function(composer, command, className) {
return wysihtml5.commands.formatBlock.exec(composer, command, "p", className, new RegExp(className, "g"));
},
state: function(composer, command, className) {
return wysihtml5.commands.formatBlock.state(composer, command, "p", className, new RegExp(className, "g"));
}
};
wysihtml5.commands.customClassInline = {
exec: function(composer, command, className) {
return wysihtml5.commands.formatInline.exec(composer, command, "span", className, new RegExp(className, "g"));
},
state: function(composer, command, className) {
return wysihtml5.commands.formatInline.state(composer, command, "span", className, new RegExp(className, "g"));
}
};
This will add any class defined in the data-wysihtml5-command-value, as long as that class (e.g. "wysiwyg-lead") is in the classes whitelist (see the wysihtml5ParserRules variable).