Memory issues on a loop over all characters of a document
Hi all,
I'm trying to implement a custom export to HTML of some of the contents of a document.
I have a loop that checks if any character has a particular style (bold, italic...) and apply the correspondent inline tag (<strong>, <i>).
This loop takes too long and makes inDesign to stop working. If i'm not mistaken, it's a memory leak issue. I've searched these forums and other places and found no solution to my problem.
From what I read here, it looks like each one of those memory problems always needs it's particular solution. Hopefully you will be able to help me with this one.
This is my code:
main();
function main() {
//Some code
var txtFrames = //an array containing all TextFrame objects in the document
var txtFramesLength = txtFrames.length;
for (i = 0; i<txtFramesLength; i++) {
var parLength = txtFrames.paragraphs.length;
for (j = 0; j<parLength; j++) {
var contentsWithCharStyle = applyCharStyle(txtFrames.paragraphs
); file.writeln('<p>' + contentsWithCharStyle + '</p>');
}
}
var charStyleName = '';
var charContents = '';
function applyCharStyle(paragraph) {
var chars = paragraph.characters;
var result = '';
for (k = 0, kLength = chars.length; k<kLength; k++) {
charStyleName = chars
.appliedCharacterStyle.name; charContents = chars
.contents; if (charStyleName == '_03-Bold') {
result += '<strong>' + charContents + '</strong>';
} else if (charStyleName == '_02-Regular-Italic') {
result += '<i>' + charContents + '</i>';
} else if (charStyleName == '_04-Bold-Italic') {
result += '<strong><i>' + charContents + '</i></strong>';
} else {
result += charContents;
}
}
result = result.replace(/<\/strong><strong>/g, '');
result = result.replace(/<\/i><i>/g, '');
return result;
}
}
So the issue comes from the repeated calls to applyCharStyle. Retrieving chars
I guess those properties are staying somewhere in memory every time.
Thanks in advance for your help and time. .appliedCharacterStyle appl dfdwyCharStyleapplyCharStyleapplyCharStyle