suggestFilename static method

String suggestFilename(
  1. String content, {
  2. String prefix = 'neom',
})

Detect the best filename from the content (first header or default)

Implementation

static String suggestFilename(String content, {String prefix = 'neom'}) {
  final headerMatch = RegExp(r'^#{1,3}\s+(.+)', multiLine: true).firstMatch(content);
  if (headerMatch != null) {
    final title = headerMatch.group(1)!.trim();
    final clean = title
        .replaceAll(RegExp(r'[^\w\s-]'), '')
        .replaceAll(RegExp(r'\s+'), '_')
        .toLowerCase();
    if (clean.isNotEmpty && clean.length <= 50) {
      return '${prefix}_$clean.pdf';
    }
  }
  return '${prefix}_documento_${_formatDateShort(DateTime.now())}.pdf';
}