unindent function

String unindent(
  1. String multilineString
)

Allows the use of ''' string blocks, without having to unindent them when used within something like markdown's markdownToHtml function.

Replace this:

(Component()
  ..description = markdownToHtml(
'''
Yuck... I'm indented all funky.
'''
  )
)()

With this:

(Component()
  ..description = markdownToHtml(unindent(
      '''
      Proper indentation is yummy...
      '''
  ))
)()

Implementation

String unindent(String multilineString) {
  var indent = RegExp(r'^( *)').firstMatch(multilineString)![1]!;
  assert(indent.isNotEmpty);
  return multilineString.trim().replaceAll('\n$indent', '\n');
}