textImagePaths function

List<String> textImagePaths(
  1. String text
)

Implementation

List<String> textImagePaths(String text) {
  final paths = <String>[];
  final seen = <String>{};
  for (final match in _textImageMarkerPattern.allMatches(text)) {
    final source = match.group(1)?.trim();
    if (source == null || source.isEmpty) continue;
    final uri = Uri.tryParse(source);
    final path = uri?.scheme == 'file'
        ? uri!.toFilePath()
        : uri?.scheme.isEmpty == true && source.startsWith('/')
        ? source
        : null;
    if (path == null || !_looksLikeImagePath(path) || !seen.add(path)) {
      continue;
    }
    paths.add(path);
  }
  return List<String>.unmodifiable(paths);
}