# document.MarkdownDocument


A Markdown document with source tracking.


Usage

``` python
document.MarkdownDocument(
    content,
    origin=None,
    attributes=None,
)
```


[MarkdownDocument](document.MarkdownDocument.md#raghilda.document.MarkdownDocument) is the everyday document type in raghilda: [read_as_markdown()](read.read_as_markdown.md#raghilda.read.read_as_markdown) returns one, and the crawlers yield them. It has the same fields as [Document](document.Document.md) (`content`, `origin`, `attributes`), with the understanding that `content` is Markdown and `origin` records where that content came from (a URL or file path) for citation and provenance. Chunking a [MarkdownDocument](document.MarkdownDocument.md#raghilda.document.MarkdownDocument) yields a [ChunkedMarkdownDocument](document.ChunkedMarkdownDocument.md#raghilda.document.ChunkedMarkdownDocument).


## Parameters


`content: str`  
The Markdown text of the document.

`origin: str | None = None`  
Where the content came from (a URL or file path), used for citation and provenance. Stores require a populated origin at upsert time.

`attributes: dict[str, Any] | None = None`  
Optional user-defined attributes applied at insertion time. Chunks can inherit them, and they are returned during retrieval for filtering and downstream prompt/context use.


## Examples

You usually get one from [read_as_markdown()](read.read_as_markdown.md#raghilda.read.read_as_markdown), but you can also build one directly from text you already have:


``` python
from raghilda.document import MarkdownDocument

# Create from content directly
doc = MarkdownDocument(
    content="# Hello World\n\nThis is a test document.",
    origin="https://example.com/hello.md",
)
print(f"Document from: {doc.origin}")
print(f"Content length: {len(doc.content)} characters")
```


    Document from: https://example.com/hello.md
    Content length: 39 characters


## Methods

| Name | Description |
|----|----|
| [from_any()](#from_any) | Convert any document-like or IntoDocument object to a MarkdownDocument. |
| [to_chunked()](#to_chunked) | Return a ChunkedMarkdownDocument with the same fields and chunks. |

------------------------------------------------------------------------


### from_any()


Convert any document-like or IntoDocument object to a MarkdownDocument.


Usage

``` python
from_any(doc, origin=None)
```


This conversion only accepts unchunked inputs. If the source object already carries chunks, use [ChunkedMarkdownDocument.from_any()](document.ChunkedMarkdownDocument.md#raghilda.document.ChunkedMarkdownDocument.from_any) instead.


#### Parameters


`doc: DocumentLike | IntoDocument`  
An object that implements the DocumentLike protocol or has a [to_document()](types.IntoDocument.md#raghilda.types.IntoDocument.to_document) method.

`origin: str | None = None`  
Optional origin to set if the source object doesn't have one.


#### Returns


`MarkdownDocument`  
A raghilda MarkdownDocument instance.


------------------------------------------------------------------------


### to_chunked()


Return a ChunkedMarkdownDocument with the same fields and chunks.


Usage

``` python
to_chunked(chunks)
```
