meld
Version:
Meld: A template language for LLM prompts
111 lines (80 loc) • 2.54 kB
Markdown
# @embed Directive
The `@embed` directive includes content from external files into your Meld document.
## Syntax
```meld
# section_text]
###
# section_text] as ###
```
Where:
- `path` is the path to the file to embed (can use path variables)
- `section_text` is optional text that identifies a specific section to extract
- `###` is an optional heading level (number of # characters) for the embedded content
- `header_text` is optional text to use as a header for the embedded content
## Path Specification
The path can be:
- An absolute path using `$HOMEPATH` or `$PROJECTPATH`
- A path variable: `@embed [$docs/guide.md]`
## Section Extraction
You can extract specific sections from Markdown files using the `#` symbol:
```meld
# Getting Started]
```
This will extract only the section titled "Getting Started" from guide.md.
## Heading Level Adjustment
You can adjust the heading level of embedded content using the `as` keyword:
```meld
###
```
This will increase all headings by the specified number of `#` characters.
## Adding Headers
You can add a header to embedded content using the `under` keyword:
```meld
```
This will add a header "Example Code" above the embedded content.
## Variable Support
Path, section, and header parameters can all contain variables:
```meld
# {{section}}] under {{header}}
```
## Error Handling
The implementation handles these error scenarios:
- Missing/empty path parameter
- File not found
- Section not found in target file
- Invalid heading level (must be 1-6)
- Invalid parameter types
- Circular file inclusions
## Examples
Basic file embedding:
```meld
```
Embedding with path variables:
```meld
```
Embedding specific sections:
```meld
# Authentication]
```
Adjusting heading levels:
```meld
##
```
Adding headers:
```meld
```
## Notes
- Missing files will generate fatal errors
- The `#` section identifier looks for heading text matching exactly
- For non-markdown files, the entire file content is embedded
- If the section is not found, a warning will be generated
- The implementation protects against circular file inclusions