Search code examples
javascripthtmlxmladobe-indesign

How do I map all objects in Indesign file to XML


END GOAL

Ultimately, I need to export my InDesign file to HTML such that each HTML block-level element has a unique ID of some kind (it doesn't matter what it is as long as it's unique), a unique ID that also stays in the InDesign file and does not change, regardless of user modifications to the InDesign content, and gets exported in the HTML with each element. Something like this:

<p data-id="4j8w53">My first paragraph</p>
<p data-id="k39dh2">My second paragraph</p>

And then when the InDesign user changes the content and re-exports to HTML, the existing IDs remain, like this:

<p data-id="4j8w53">My first paragraph is awesome!</p>
<p data-id="lq09cf">My inserted paragraph</p>
<p data-id="k39dh2">My second paragraph</p>

If someone knows an easy way to do this, I'd love to hear it.

PLAN NUMBER ONE

Trying to figure this out, what I've decided to do is map everything in the InDesign file to XML, then add my ID attributes to the XML items through a JS user script, then export the XML as HTML through another JS user script. Since the XML items are actually mapped to InDesign items, the IDs will stay with them as the text changes.

Here's the problem: I can't seem to get all of my InDesign content mapped to XML using the mapStylesToXMLTags() function. I have a bunch of stories in the file and one of them never shows up in the XML when I export it. It is simply missing.

If I could just get all the content to show up in the exported XML when I use mapStylesToXMLTags(), that would probably solve my problem.

Or, if there is a different mapping mechanism that would actually map all my items to XML and keep the mappings, that might work as well.

PLAN NUMBER TWO

If I recursively loop through allPageItems in app.documents[0] and manually create the XML instead of using mapStylesToXMLTags(), then the missing object shows up just like everything else.

However, then the IDs that I give the XML elements don't attach to the InDesign elements, since those elements are not actually officially "mapped" to XML elements. They don't automatically update when changed. I would have to overwrite all the XML when changes are made to the InDesign file, eliminating the consistency of the data-id values.

Also, when I do it this way, everything is all out of order and disconnected from the way it was laid out in the InDesign file.

Plan number one still seems to have the most promise, if I could just get all the content to map.

PLEASE GO EASY ON ME

I hope this is all clear. FWIW, I am a JS / HTML guy, not an InDesign guy. I am new to InDesign and am just trying to figure out how to make this process happen for the InDesign users at my organization.


Solution

  • Apparently the object that was not mapping to XML was a linked InCopy file, which was locked against any editing. In order to map it to XML, I had to click inside it, then select Edit > InCopy > Check Out. After that, it mapped with no difficulty at all using my "Plan Number One" above.