Copy link to clipboard
Copied
Hi there,
In inDesign, you can right click on textframes and edit with Story Editor, which shows you a view into not just the contents but the tags and styling for that particular textframe. I'm wondering how that data can be extracted from a TextFrame object in a script. Looking over the API docs, one thing I've found is item.ObjectExportOption.actualText() which I expected to be the XML text, but that returns a blank for me. Is this the correct place to look, and if so, why might I be getting blanks?
If the Story Editor data is not accessible in the API, then what is another way you would suggest to extract styling and format info from textFrames?
Thanks!
Copy link to clipboard
Copied
Not sure what other tags you're after but you can get an array of all the paragraph styles used in a frame with:
frame.paragraphs.everyItem().appliedParagraphStyle.name;
You can also iterate through each paragraph with:
var pars = frame.paragraphs;
for (var i = 0; i < pars.length; i++) {
alert(pars[i].appliedParagraphStyle.name);
}
Take a look at the TextFrame DOM to see all the ways you can dig into it: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#TextFrame.html
Copy link to clipboard
Copied
Thanks for your response,
This allows me to grab the style associated with a paragraph which is great, but what I also need to do is grab the HTML code for the paragraph. When exporting to HTML in InDesign everything is bundled into one giant file, but I'm wondering if theres a way to grab HTML chunks for sub-sections (by page, paragraph... anything deeper than the whole document).
For context, I'm trying to write a modified (hopefully better) version of the built-in, undocumented InDesign to HTMLFXL exporter. That exporter generates HTML files for each page. I'm wondering if my script will have to manually check each pageItem's page, cross reference the single-document exported HTML and split it accordingly. Hopefully the API lets users grab HTML subsections directly, but thats what I've been unable to find information on.
Thanks!
Copy link to clipboard
Copied
I'm not doing much with InCopy, but just tested - the XML Structure works the same way as in InDesign.
E.g. to get the tag name of the first story:
app.documents.item(0).stories.item(0).associatedXMLElement.markupTag.name
Copy link to clipboard
Copied
Thanks for your response,
If possible check out my reply to brianp311 and let me know your thoughts 🙂
Copy link to clipboard
Copied
What you see in the story editor is also accessible in the plain, normal, text. The story editor is just a different view of the document. It's a bit like Reveal Codes in WordPerfect. Codes are visible in a different way: in the main text, XML tags are brackets, in the story editor they're 'proper' tags with a name; footnotes are shown where they are cued; etc. Therefore there is no separate API for the story editor.
Copy link to clipboard
Copied
Thanks for your response,
If possible check out my reply to brianp311 and let me know your thoughts! 🙂
Copy link to clipboard
Copied
You can copy any stretch of text into a new text frame (or a new document) and export that to HTML. And if you don't like InDesign's HTML code you could write your own converter.
Copy link to clipboard
Copied
Is it possible to export InDesign's HTML code from a single textFrame? Your response suggests that it is, but I've not been able to find a way to do that unfortunately
Copy link to clipboard
Copied
Ah, no. HTML export is a document property. So you copy a text frame to another document and export that.
Copy link to clipboard
Copied
Hi peter-g,
to answer your question about the Story Editor Window in ExtendScript ( JavaScript ) code:
var doc = app.documents[0];
var allOpenStoryWindows = doc.storyWindows.everyItem().getElements();
for( var n=0; n<allOpenStoryWindows.length; n++ )
{
// Select all text in the story window:
allOpenStoryWindows[n].select( SelectAll.ALL );
// Add a new document:
var newDoc = app.documents.add();
// Add a new text frame:
var newTextFrame = newDoc.textFrames.add({ geometricBounds : newDoc.pages[0].bounds });
// Duplicate the selected text to the new document's text frame:
allOpenStoryWindows[n].selection[0].duplicate
(
LocationOptions.AFTER ,
newTextFrame.parentStory.insertionPoints[0]
);
/*
THEN:
Export to HTML or do something else.
Then close the temp doc without saving.
*/
newDoc.close( SaveOptions.NO );
};
Regards,
Uwe Laubender
( ACP )