newsdev / ai2html

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

Use docName in id so multiple embeds are unique #80

Closed kevinschaul closed 5 years ago

kevinschaul commented 6 years ago

Currently including multiple ai2html embeds on a single web page causes ids of elements to be duplicated, but they should be unique.

For example, each ai2html embed includes an image <img id="g-ai0-0" ...>. The first text element appears as <div id="g-ai0-1" ...>.

This PR avoids that issue by including the docName (.ai filename) in these ids.

e.g. <img id="g-ai-filename-0-0" ...>

Browsers are pretty forgiving on id uniqueness, but this is causing an issue for us in some of our internal tools. :|

Thanks for open sourcing such a useful tool.

mbloch commented 6 years ago

Hi Kevin,

Thanks for reporting the duplicate id problem.

Your PR fixes the ids of artboard images and text objects.

The current version of ai2html is already adding the document name to image ids, so duplicate image ids should no longer be a problem.

That leaves the text ids. How would you feel about assigning ids to text blocks only if they come from named text frames in the Illustrator document? Archie originally added ids to all text blocks, thinking we might want to target any text block for a quick fix without re-running ai2html, but we've never actually needed to use the ids this way, and we don't see a good reason to keep generating them.

One option is to handle text ids the same way that we're handling inline SVG ids (a new, experimental feature -- see issue #87). For inline SVG, we're adding ids only for objects that are named in the AI document. We're adding numbered suffixes to resolve collisions within a graphic, adding an optional prefix to resolve collisions between graphics, and also adding a 'data-name=' attribute containing the original AI name.

kevinschaul commented 5 years ago

Closing this since multiple embeds no longer have an id collision