Extension to remove new lines and hyphens at the end of the line

This extension removes new lines and hyphens at the end of the line. It is especially helpful for processing text from pdfs.

# popclip
name: remove newlines and end-of-line hyphens
icon: strike symbol:return
javascript: |
    const text = popclip.input.text;
    popclip.pasteText(text.replace(/-\r?\n/g, '').replace(/\r?\n/g, ' '));

(The above block is an extension snippet – select it to install the extension with PopClip)

Before:

Though an oft-repeated zom-
bie statistic posits that as many as 10% of
children are fathered outside of marriage,
he has found that over the past 500 years,
the rate in Europe is much closer to 1%.

(Source: pdf version of https://www.science.org/content/article/how-often-are-children-genetically-unrelated-their-presumed-fathers)

After:

Though an oft-repeated zombie statistic posits that as many as 10% of children are fathered outside of marriage, he has found that over the past 500 years, the rate in Europe is much closer to 1%.

The icon from Apple’s SF symbols requires macOS Ventura or later. You can replace it with a return icon from Iconify by using e.g. icon: iconify:material-symbols:keyboard-return-rounded.

1 Like

Awesome! Thanks for sharing as well as including educational details

1 Like