Text style class names in HTML
Request for HTML publish to retain hyphens and underscores in custom text style names.
For example; currently "my-style" publishes to HTML as class name "my-45style"
and "my_style" publishes to HTML as class name "my-95style"
It looks like it does this for all non-alphanumeric characters but hyphens and underscores are common in HTML class names so maybe they could export as-is?
My use-case is to apply a custom class name eg. product-price-456789 to some text by using a text style name and then dynamically replace the text contained within the HTML span. I can put product-price-456789 as the actual text instead and replace it that way but being able to use the span class name would be nice.
Re: Text style class names in HTML
Quote:
Originally Posted by
xtom
Request for HTML publish to retain hyphens and underscores in custom text style names.
For example; currently "my-style" publishes to HTML as class name "my-45style" and "my_style" publishes to HTML as class name "my-95style"
It looks like it does this for all non-alphanumeric characters but hyphens and underscores are common in HTML class names so maybe they could export as-is?
My use-case is to apply a custom class name eg. product-price-456789 to some text by using a text style name and then dynamically replace the text contained within the HTML span. I can put product-price-456789 as the actual text instead and replace it that way but being able to use the span class name would be nice.
xtom, if it helps, change 'my_style' to 'my style' and the end-result is my_style - the space is changed to an underscore. A leading space returns x-_.
Generally can you not work with Styles as Pascal case, 'ProductPrice 456789' or camelCase, 'productPrice 456789'? [ProductPrice_456789, productPrice_456789]
The alternative would be to iterate through all class lists and replace the offending substitutions.
Acorn
Re: Text style class names in HTML
Ah thanks Acorn, I did not try using a space, that is good to know.
The naming convention I'm using for tags/class names is eg. cms-product-price-456789 , cms-page-content etc. any character can be upper or lower case but the words are separated with hyphens. I figured it was easiest to read no matter what case is used, although it does make them a bit longer.
With your find I would have to add support to work with underscores too, which is doable. However I noticed afterwards that the class name is used twice, once in the span and again in a wrapping div, and it got a bit messier to pursue.
I ended up adding find-and-replace support so any custom text or class name etc. can be set to be changed to whatever, much like your last suggestion. So in a theme config file you can set for example 'mystyle' => 'my-tag' or whatever and so it's stored and used automatically going forward. None of this was needed for standard placeholders with tags in the body but I was trying to get a bit more fine grain control over the text spans. ie. keep the text styling but just change the text and now this way allows for that too.