Element sorting
The formatter reads the pasted text and assigns each line to one of three elements: scene heading, action, or dialogue. Screenplay conventions are the signal: sluglines name a location and time of day, a speaker's name precedes the lines they say, everything else reads as action. Input that follows those conventions maps cleanly; blended input (a name inside a sentence, a slugline missing its location) is where misplacement shows up.