newsdev / ai2html

A script for Adobe Illustrator that converts your Illustrator artwork into an html page.
http://ai2html.org
Other
898 stars 146 forks source link

Allow class name compilation on the basis of character styles (applied in Illustrator) #66

Open blzzz opened 7 years ago

blzzz commented 7 years ago

From a perspective of updatability, it makes more sense to use class names referring to "external" style definitions and not being part of the ai2html output. Another benefit doing so is that the HTML output of a ai2html project will generate less CSS code if no more "project specific" paragraph definitions are needed in it.

At the moment, it's already possible to define custom class names for divs containing text. Naming a layer that contains text in Illustrator results in a div with a class name consisting of the "slugged" parent layer name and prefixed by the nameSpace variable. However the class names generated for paragraph elements (wrapped into those divs) are not customizable. Even if a div's class name is customized, it's hard to access/overwrite paragraph style definitions like color or font-family. The reason for this are the generated style blocks making usage of selectors like #g-project-mobile .g-aiPstyle0. For that reason, it's nearly impossible to set paragraph style definitions like color, font-family, font-size or line-height by custom classes.

In this PR we propose the setting property characterstyles_to_classnames that – if set to yes – will..

Character Styles in Illustrator work really well. As spaces are allowed in Character Style names (which won't get "slugged"), it's also possible set multiple classes per text element, i.e.: s-font-text s-font-text--strong

blzzz commented 7 years ago

I just updated and tested this PR to work with the latest version of ai2html.js.

These are the updates I've done:

These updates now support multiple character styles in a text field. As mentioned above Character Styles work really well in Illustrator. As spaces are allowed in Character Style names (and won't get "slugged"), it's also possible set multiple classes per paragraph range, i.e.: s-font-text s-font-text--strong.

mbloch commented 6 years ago

Thanks for sharing this code

I wasn't familiar with Character Styles -- we don't use them in our graphics department -- but I can see how they could be useful.

I'm not going to accept this PR in it's current form. My main objection is that the "characterstyles_to_classnames" option doesn't capture all the relevant information about text style. In particular:

This PR has given me some ideas for improving ai2html's default CSS generation: