Class: MarkdownLoader
Defined in: packages/agentos/src/memory/ingestion/MarkdownLoader.ts:114
Document loader for Markdown (.md) and MDX (.mdx) files.
Front-matter handling
YAML front-matter delimited by --- is parsed via gray-matter. All
key-value pairs are merged into DocumentMetadata as-is, with a
handful of well-known keys (title, author, createdAt, modifiedAt,
language) mapped to the corresponding typed metadata fields.
Title extraction fallback
When the front-matter does not contain a title field the loader
searches the document body for the first level-1 ATX heading (# Title)
and uses that as the title.
Returned content
The content field in the returned LoadedDocument contains the
Markdown body without the front-matter block.
Implements
Example
const loader = new MarkdownLoader();
const doc = await loader.load('/docs/architecture.md');
console.log(doc.metadata.title); // from front-matter or first # heading
Implements
Constructors
Constructor
new MarkdownLoader():
MarkdownLoader
Returns
MarkdownLoader
Properties
supportedExtensions
readonlysupportedExtensions:string[]
Defined in: packages/agentos/src/memory/ingestion/MarkdownLoader.ts:116
File extensions this loader handles, each with a leading dot.
Used by LoaderRegistry to route file paths to the correct loader.
Example
['.md', '.mdx']
Implementation of
IDocumentLoader.supportedExtensions
Methods
canLoad()
canLoad(
source):boolean
Defined in: packages/agentos/src/memory/ingestion/MarkdownLoader.ts:123
Returns true when this loader is capable of handling source.
For string sources the check is purely extension-based. For Buffer
sources the loader may inspect magic bytes when relevant.
Parameters
source
Absolute file path or raw bytes.
string | Buffer
Returns
boolean
Implementation of
load()
load(
source,_options?):Promise<LoadedDocument>
Defined in: packages/agentos/src/memory/ingestion/MarkdownLoader.ts:137
Parses source and returns a normalised LoadedDocument.
When source is a string the loader treats it as an absolute (or
resolvable) file path and reads the file from disk. When source is a
Buffer the loader parses the bytes directly and derives as much
metadata as possible from the buffer content alone.
Parameters
source
Absolute file path OR raw document bytes.
string | Buffer
_options?
Optional hints such as a format override.
Returns
Promise<LoadedDocument>
A promise resolving to the fully-populated LoadedDocument.
Throws
When the file cannot be read or the format is not parsable.