I need to automate the way URLs are broken at the end of a line (see CMOS 14.18, "URLs and line breaks"):
Applying a No Language character style to the URL does not prevent it from being broken:
Is this a bug? – Of course I could use a Forced Line Break and accept that the URL won't be clickable in the PDF; in my current project this would be acceptable but I was wondering whether I'm missing something.
Try inserting a discretionary line break character where you want the URL to break. To be certain it is clickable in the PDF you should probably create a hyperlink for the URL in the document.
Copy link to clipboard
Thank you both, Rob and Peter. Using the Discretionary Line Break does indeed the trick (good idea!) with full stops.
However, it doesn't seem to work with single slashes since ID chooses to break after the slash, not before it, even if there is a Discretionary Line Break. So I'll have to use the Forced Line Break in the (rare) cases a line should break there.
Hi Samuel, note that in my example I’m using a Discretionary Line Break along with No Break. Try setting the text of the URL up to the slash as No Break then add the discretionary line break after the slash.
Oh, I realise I used [No Language] instead of No Break … Applying the latter to the text up to the slash works, thank you!
Since you're asking for a way to automate this, check out https://www.id-extras.com/products/hyperlinkpro/
It's not a free add-on, but it specifically uses CMOS rules to break URLs correctly at the end of lines.
One click and your document is done!
It uses the same system suggested above: discretionary line breaks. But it finds the best place to put them within the URL for the smoothest spacing.
If the URL is long, it doesn't always work to break the line after www, or before .com, etc., because it would leave too large a gap between the words on the previous line.
Something like this is probably the only real solution, and it would be nice to see it integrated into ID someday. URLs are both common and, if longer than a few elements, a real PITA to manage in text, notes, etc.
Maybe just a "language" that can be applied via a character style, with the break rules etc. embedded in the rules.