Collapse identical adjacent non-blank lines that appear two-or-more times in a row. Defensive cleaning for the common AI-authored failure mode where a classification row, ISMS footer or metadata sentinel is pasted twice into the same artifact body.
Lines inside fenced code blocks are preserved verbatim โ duplication inside a code block may be intentional (e.g. config snippets). Blank lines are not deduplicated; they participate as paragraph separators and are handled later by the \n{3,} collapse step.
Stable on already-deduped inputs: the function is idempotent โ applying it twice yields the same result.
Collapse identical adjacent non-blank lines that appear two-or-more times in a row. Defensive cleaning for the common AI-authored failure mode where a classification row, ISMS footer or metadata sentinel is pasted twice into the same artifact body.
Lines inside fenced code blocks are preserved verbatim โ duplication inside a code block may be intentional (e.g. config snippets). Blank lines are not deduplicated; they participate as paragraph separators and are handled later by the
\n{3,}collapse step.Stable on already-deduped inputs: the function is idempotent โ applying it twice yields the same result.