Forum Replies Created
-
AuthorPosts
-
Peter KahrelParticipantI was never aware of Dave’s script. It’s a very clever solution, but for me the sidebearing showing up at the start of a line is a kerning problem, and my kerning script deals with it:
September 23, 2023 at 3:21 pm in reply to: GREP to search all end of paragraph without a full stop and add it automatically #14396037
Peter KahrelParticipantBad sport!
September 23, 2023 at 1:32 pm in reply to: GREP to search all end of paragraph without a full stop and add it automatically #14396033
Peter KahrelParticipantDid you check whether there are any paragraphs that end in a space (or more spaces even)? If there are any they would trip up the solutions suggested above. To delete any trailing spaces, use this query:
Find: +$
Replace with: <leave empty>And for sport here’s yet another query to find paragraphs that don’t end in a period and insert a period:
Find: (?<!\.)$
Replace with: .
Peter KahrelParticipantAh — sorry. The script was meant to search whole-word-only, but I made a mistake in that line. Below is the corrected version. It also first removes any highlighting so that you can run the script again against a document with a risk list with some words removed: the highlights on those words is then removed.
(function () { var condition; var riskWords; // Remove and recreate the condition if it exists // so that words removed from the list are // 'unrisked' in the text function getCondition () { var c = app.documents[0].conditions.item('Risk word'); if (c.isValid) { var p = c.properties; // This is quicker than removing the highlights in the text c.remove(); c = app.documents[0].conditions.add(p); } else { app.documents[0].conditionalTextPreferences.showConditionIndicators = ConditionIndicatorMode.SHOW_INDICATORS; c = app.documents[0].conditions.add ({ name: 'Risk word', indicatorColor: UIColors.YELLOW, indicatorMethod: ConditionIndicatorMethod.useHighlight, }); } return c; } function highlight (word) { app.findTextPreferences.findWhat = word; var w = app.documents[0].findText(); for (var i = w.length-1; i >= 0; i--) { w[i].applyConditions (condition); } } function getWords () { var f = File (app.documents[0].filePath + '/risk-words.txt'); if (f.exists) { f.encoding = ('utf-8'); f.open('r'); var w = f.read().split(/[\r]/); f.close(); return w; } return null; } app.findTextPreferences = app.findChangeTextOptions = null; app.findChangeTextOptions.properties = { caseSensitive: false, wholeWord: true, includeLockedStoriesForFind: false, } condition = getCondition(); riskWords = getWords(); if (!riskWords) { alert ('Risk words not found'); exit(); } for (var i = riskWords.length-1; i >= 0; i--) { highlight (riskWords[i]); } }()); -
AuthorPosts
