@m1b I was thinking of one more thing. Now that this line comparing version is working, can we check word by word using grep in script ? New line and spaces need to be ignored. e.g if there are two spaces in between the word in indesign, current script will treat this as an error. Is there a way out of this ?
Thanks
Hi @Bedazzled532, here is a version that checks word by word:
function main() {
var masterContentFile = File("d:/readid.txt");
var badCharacterStyleName = 'Bad';
if (!masterContentFile.exists) {
alert('Could not find master content file "' + masterContentFile + '".');
return;
}
var doc = app.activeDocument,
badCharacterStyle = doc.characterStyles.itemByName(badCharacterStyleName);
if (!badCharacterStyle.isValid) {
alert('Could not find character style "' + badCharacterStyleName + '".');
return;
}
if (
doc.selection[0] == undefined
|| !doc.selection[0].hasOwnProperty('parentStory')
) {
alert('Please put cursor in the story you want to check and try again.');
return;
}
masterContentFile.open('r')
var masterContent = masterContentFile.read().split("\n"),
userParagraphs = doc.selection[0].parentStory.paragraphs,
userContent = userParagraphs.everyItem().contents,
leadingTrailingSpace = /(^\s|\s$)/g,
whitespace = /\s+/g,
contentCount = Math.min(userContent.length, masterContent.length),
differenceCount = 0;
for (var i = 0; i < contentCount; i++) {
var m = masterContent[i].replace(leadingTrailingSpace, ''),
u = userContent[i].replace(leadingTrailingSpace, '');
if (u == m) continue;
var mWordContent = m.split(whitespace),
uWords = userParagraphs[i].words,
uWordContent = uWords.everyItem().contents,
wordCount = Math.min(mWordContent.length, uWordContent.length);
for (var j = 0; j < wordCount; j++) {
if (uWordContent[j] != mWordContent[j]) {
uWords[j].applyCharacterStyle(badCharacterStyle);
differenceCount++
}
}
}
alert('Found ' differenceCount + ' different words.');
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Check Story Against Master Content');