1. The customer wants to remove the unerline from spaces AND punctuation at the end of a line of text. See example below:
The raw text.
What the customer wants.
2. Some lines and paragraphs will contain a varaible. Thus those lines will change during the VDP output.
I have used ChatGPT to write JavaScript to get me halfway there (remove underlines from spaces at the end of lines of text) but doesn't work on any punctuation.
Here is the code:
function removeUnderlinesAtEndOfParagraphs() {
var doc = app.activeDocument;
// Check if there is at least one story in the document
if (doc.stories.length > 0) {
for (var i = 0; i < doc.stories.length; i++) {
var curStory = doc.stories[i];
// Iterate through paragraphs in the story
for (var p = 0; p < curStory.paragraphs.length; p++) {
var paragraph = curStory.paragraphs[p];
// Split the paragraph into lines
var lines = paragraph.lines.everyItem().getElements();
// Iterate through lines in the paragraph
for (var l = 0; l < lines.length; l++) {
var line = lines[l];
// Get the last character in the line
var lastCharIndex = line.characters.length - 1;
// Check if lastCharIndex is valid (not negative)
if (lastCharIndex >= 0) {
var lastChar = line.characters[lastCharIndex];
// Check if the last character is underlined and is either a space or a punctuation mark followed by a space
if (lastChar.underline && /^[.,;!? ]+$/.test(lastChar.contents)) {
lastChar.underline = false;
}
}
}
}
}
}
}
removeUnderlinesAtEndOfParagraphs(); // Call the function to remove underlines from spaces and punctuation at the end of lines
First: Is it even possible to do this through scripting?
Second: What do I need to change to get this code to work the way I need it to?
It is built-in behavior of InDesign. I wrote a script to apply a temporary fix to this years ago: http://indesignsecrets.com/topic/removing-end-of-line-underlines-83 (which I didn't remember but actually found by typing in your question into a well-known internet search engine).
The script contains a few characters that did not survive the translation to forum-formatted HTML, so I'll repeat it below for convenience:
//DESCRIPTION: Begone, Ugly End Of Line Underlining! // (c) Jongware 16-Dec-2009
var blankStyle = app.activeDocument.characterStyles.item("NoUnderline");
It's not on the end of the story, it's a paragraph that has multiple lines. I want when the line breaks, the space that is at the end of the line is not underlined. It would be easier to do it through a grep code, than doing it manually.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
Scanne Datei nach Viren
Tut uns leid, wir prüfen noch den Inhalt dieser Datei, um sicherzustellen, dass sie gefahrlos heruntergeladen werden kann. Bitte versuche es in wenigen Minuten erneut.