reverseHangingIndent method

String reverseHangingIndent(
  1. String indentation
)

Adds indentation to only the first line (reverse hanging indent).

Less common, but useful for drop caps, initial emphasis, or custom formatting where the first line stands out.

Example:

'line1\nline2\nline3'.reverseHangingIndent('  ')
// '  line1\nline2\nline3'

'First line\nRest'.reverseHangingIndent('>>> ')
// '>>> First line\nRest'

Implementation

String reverseHangingIndent(String indentation) {
  if (isEmpty) return this;
  final lines = split('\n');
  if (lines.length == 1) return indentation + this;
  return [indentation + lines.first, ...lines.skip(1)].join('\n');
}