parseMemoryFileContent static method
({List<String> includePaths, MemoryFileInfo? info})
parseMemoryFileContent(
- String rawContent,
- String filePath,
- MemoryType type, {
- String? includeBasePath,
Parses raw memory file content into a MemoryFileInfo. Pure function -- no I/O.
Implementation
static ({MemoryFileInfo? info, List<String> includePaths})
parseMemoryFileContent(
String rawContent,
String filePath,
MemoryType type, {
String? includeBasePath,
}) {
// Skip non-text files
final ext = _getFileExtension(filePath);
if (ext.isNotEmpty && !_textFileExtensions.contains(ext)) {
return (info: null, includePaths: <String>[]);
}
final parsed = _parseFrontmatterPaths(rawContent);
// Strip HTML comments
final strippedResult = stripHtmlComments(parsed.content);
final strippedContent = strippedResult.content;
// Extract include paths
final includePaths = includeBasePath != null
? _extractIncludePaths(parsed.content, includeBasePath)
: <String>[];
final finalContent = strippedContent;
final contentDiffersFromDisk = finalContent != rawContent;
return (
info: MemoryFileInfo(
path: filePath,
type: type,
content: finalContent,
globs: parsed.paths,
contentDiffersFromDisk: contentDiffersFromDisk,
rawContent: contentDiffersFromDisk ? rawContent : null,
),
includePaths: includePaths,
);
}