meld
Version:
Meld: A template language for LLM prompts
150 lines (109 loc) • 3.58 kB
Markdown
**NOTE:** If you're looking for [the old 'meld' package for aspect oriented programming](https://www.npmjs.com/package/meld/v/1.3.2), you'll want to pin your version to `<2.0.0`
---
meld is a prompt scripting language.
```bash
npm install -g meld
```
or just run it with `npx meld`
Process meld files from the command line:
```bash
meld input.mld
meld input.mld --format md
meld input.mld --output output.xml
meld input.mld --stdout
```
- `--format, -f`: Output format (default: md)
- Supported formats: md, xml
- `--output, -o`: Output file path (default: input filename with new extension)
- `--stdout`: Print to stdout instead of file
### Supported File Extensions
- `.mld` is standard `.mld.md` is another option.
- `.md`: Meld can just interpret regular old markdown files with added meld syntax, too.
## JavaScript API
Meld has a fairly extensive js API which give access to its AST, interpreted variables, etc., but it's not documented yet. However, here's meld's simple API for processing content directly:
```javascript
// ES Module import
import runMeld from 'meld';
// Process meld content
const meldContent = `
@text greeting = "Hello"
@text name = "World"
${greeting}, ${name}!
`;
// Simple usage
const result = await runMeld(meldContent);
console.log(result); // "Hello, World!"
// With options
const xmlResult = await runMeld(meldContent, {
format: 'xml',
transformation: true
});
```
Meld is a simple scripting language designed to work within markdown-like documents. It processes special `@directive` lines while preserving all other content as-is.
```meld
@text name = "value"
@data config = { "key": "value" }
@path docs = "$PROJECTPATH/docs"
@embed [file.md]
@embed [file.md
@run [command]
@import [file.mld]
@define cmd = @run [echo "hi"]
```
```meld
{{variable}}
{{datavar.field}}
$pathvar
@text greeting = "Hello {{name}}!"
@run [cat {{file}}]
```
```meld
>> This is a comment
>> Comments must start at line beginning
```python
def hello():
print("Hi") # @text directives here are preserved as-is
```
```
### String Values
- Use single quotes, double quotes, or backticks
- Quotes must match (no mixing)
- Use backticks for template strings with variables:
```meld
@text simple = "Hello"
@text template = `Hello {{name}}!`
@text multiline = [[`
Multi-line
template with {{vars}}
`]]
```
- Must use `$PROJECTPATH` (or `$.`) or `$HOMEPATH` (or `$~`)
- Forward slashes as separators
```meld
@path docs = "$PROJECTPATH/docs"
@path home = "$HOMEPATH/meld"
```
- Store structured data (objects/arrays)
- Support field access
```meld
@data user = { "name": "Alice", "id": 123 }
@text name = "User: {{user.name}}"
```
[](LICENSE)