//------------------------------------------------------------------------------ // Cleanup the InDesign text by removing unnecessary characters //------------------------------------------------------------------------------ function cleantext(s) { // get rid of character we don't need: // paragraph breaks, column break, frame break, page break (\r) // disc line break (\u200B) // page numbers, variables (\u0018) // section marker (\u0019) // discretionary hyphen (\u00AD) // indent to here (\u0007) // end nested style here (\u0003) // xml tag (\uFEFF) // inline (\uFFFC) // footnote number (\u0004) // sing glyph (\u001A) // table (\u0016) var result = s.replace(/[\r\u200B\u0018\u0019\u00AD\u0007\u0003\u0004\uFEFF\uFFFC\u001A\u0016]/g,''); // replace non-breaking hyphen (8209 -> \u2011) with a regular hyphen result = result.replace(/\u2011/g,'-'); // replace non-standard whitespace with single spaces // right indent tab (\u0008) result = result.replace(/[\u0008]/g,' '); // misc result = result.replace(/\n/g,' '); // forced line break durch Leerzeichen ersetzen // replace all consecutive whitespace with a single space // tab // space // flush-space (\u2001) // n-space (\u2002) // m-space (\u2003) // third-space (\u2004) // quarter-space (\u2005) // sixth-space (\u2006) // figure space (\u2007) // punctuation space (\u2008) // thin space (\u2009) // hair-space (\u200A) result = result.replace(/[\s]+/g,' '); return result; } var myFrame = app.selection[0]; var myContents = myFrame.contents; myFrame.contents = cleantext (myContents);