Skip to content

Instantly share code, notes, and snippets.

@blackspike
Created April 22, 2026 09:40
Show Gist options
  • Select an option

  • Save blackspike/3aec4db8c2629b05218e5498d4b1b848 to your computer and use it in GitHub Desktop.

Select an option

Save blackspike/3aec4db8c2629b05218e5498d4b1b848 to your computer and use it in GitHub Desktop.
/**
{
"api":1,
"name":"Unwrap Paragraphs",
"description":"Joins soft-wrapped lines into single lines, keeping paragraph breaks.",
"author":"felix",
"icon":"collapse",
"tags":"unwrap,join,lines,paragraph,reflow,wrap"
}
**/
function main(input) {
input.text = input.text
.replace(/\r\n?/g, '\n')
.split(/\n[ \t]*\n+/)
.map(p => p.replace(/[ \t]*\n[ \t]*/g, ' ').trim())
.filter(p => p.length > 0)
.join('\n\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment