# Nova

<p align="center">
  <img src="logos/logo.png" alt="Nova" width="200">
</p>

**N**ested **O**rdered **V**ersatile **A**rchitecture — a programmable markup language.

<p>
  <a href="https://www.npmjs.com/package/@nova-lang/cli"><img src="https://img.shields.io/npm/v/@nova-lang/cli.svg?style=flat-square&logo=npm" alt="npm version"></a>
  <a href="https://github.com/nova-markup-lang/cli/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@nova-lang/cli.svg?style=flat-square" alt="MIT license"></a>
  <a href="https://github.com/nova-markup-lang/cli/actions"><img src="https://img.shields.io/github/actions/workflow/status/nova-lang/cli/ci.yml?style=flat-square&logo=github" alt="CI status"></a>
  <a href="https://nodejs.org"><img src="https://img.shields.io/node/v/@nova-lang/cli?style=flat-square&logo=node.js" alt="Node version"></a>
</p>

---

Nova is not a simple mashup of HTML, YAML, and TeX. It abstracts their strengths into a **unified node model** — everything is a **functional Block** with attributes and children.

**What problem does Nova solve?** Traditional markup languages force you to pick a single paradigm: HTML for structure, YAML for data, TeX for typesetting, Markdown for simplicity. Nova unifies them all into one consistent syntax — write documents, schemas, data models, math, and code with the same grammar. Use it for technical writing, API documentation, code generation, data reports, and literate programming.

---

## Installation

### npm (recommended)

```bash
npm install -g @nova-lang/cli
```

### From source

```bash
git clone https://github.com/nova-markup-lang/cli.git
cd cli
npm install
npm link
```

---

## Quick Start

Create a file `hello.nv`:

```nova
@meta {
    title: "Hello Nova"
}

@page {
    @h1 "Welcome to Nova"
    @p "This is a @em{programmable} markup language."
    @p "Inline math: $E = mc^2$"
}
```

Render to HTML:

```bash
nova build hello.nv -o hello.html
```

Open `hello.html` in your browser.

---

## CLI Usage

```bash
nova <file>                # Render .nv file to HTML (stdout)
nova build <file>          # Render to .html file
nova build <file> -o out   # Specify output path
nova lex <file>            # Show token stream (debug)
nova ast <file>            # Show AST structure (debug)
nova watch <file>          # Watch file and auto-rebuild
nova init [dir]            # Scaffold new Nova project
nova help                  # Show full usage
nova -i                    # Read from stdin
```

### Options

| Flag               | Description                        |
|--------------------|------------------------------------|
| `-i, --input <file>`   | Input `.nv` file                |
| `-o, --output <file>`  | Output file path (build)       |
| `-p, --pretty`         | Pretty-print HTML              |
| `--css <file>`         | Inject custom CSS file         |
| `--template <file>`    | Use custom HTML template       |
| `--latex`              | Render to LaTeX instead of HTML |
| `-h, --help`           | Show help                      |
| `-v, --version`        | Show version                   |

---

## Syntax Overview

### Blocks

Everything is a block: `@BlockName(attrs) { children }`.

```nova
@section(id: "intro") {
    @p "This is a paragraph."
    @ul {
        - Item one
        - Item two
    }
}
```

- No children → omit braces: `@image(src: "photo.png")`
- Anonymous block → unnamed container like `<div>`
- Attributes in `()`, comma-separated, `:` or `=` for key-value pairs
- Children indented 2 spaces

### Inline Elements

```nova
Text with @em{emphasis}, @strong{bold},
a @a(href: "https://nova-lang.org"){link} and @code{print(x)}.
```

### Interpolations

```nova
@p "Hello, #{name}! You have #{count} messages."
```

### Conditionals

```nova
@if(condition) {
    ...
}
@else @if(other) {
    ...
}
@else {
    ...
}
```

### Loops

```nova
@for(item in list) {
    - #{item}
}

@for(i in 5) {
    @p "Iteration #{i}"
}
```

### Macros

```nova
@def greet(name) {
    @p "Hello, #{name}!"
}

@def button(label: String = "Click", @content) {
    @div(style: "border:1px solid #ccc; padding:8px") {
        @strong "#{label}"
        @content
    }
}

@greet("World")
@button(label: "Submit") { @p "Click me" }
```

### Schemas & Services

```nova
@schema(Person) {
    id: Int32 @1
    name: String @2 = ""
    email: String? @3
    tags: List<String> @4
}

@service(UserAPI) {
    getUser(id: Int64) -> Person
    listUsers() -> List<Person>
}
```

### Tables

```nova
@table(caption: "Languages") {
    @header { Name, Type, Paradigm }
    @row { Nova, Markup, Multi-paradigm }
    @row { HTML, Markup, Declarative }
}
```

Or CSV-style arrays:

```nova
@table {
    [["Name", "Age"], ["Alice", 30], ["Bob", 25]]
}
```

### Lists

```nova
@ul {
    - Apple
    - Banana
}

@ol {
    + First
    + Second
}
```

### Math

```nova
Inline: $E = mc^2$
Display: $$ \sum_{i=1}^n i = \frac{n(n+1)}{2} $$
Block: @equation { x = \frac{-b \pm \sqrt{b^2-4ac}}{2a} }
```

---

## API Reference

```js
const nova = require("@nova-lang/cli");
```

### `tokenize(source)`

Tokenize a Nova source string into a stream of tokens.

```js
const tokens = nova.tokenize('@p "Hello"');
```

### `parse(tokens)`

Parse a token stream into an AST.

```js
const ast = nova.parse(tokens);
```

### `interpret(ast, env)`

Evaluate macros, conditionals, loops, and interpolations in the AST.

```js
const { Env } = require("@nova-lang/cli");
const env = new Env();
const interpreted = nova.interpret(ast, env);
```

### `render(doc, options)`

Render an interpreted document to HTML.

```js
const html = nova.render(doc, { pretty: true });
```

### `renderLatex(doc, options)`

Render an interpreted document to LaTeX.

```js
const latex = nova.renderLatex(doc);
```

---

## Configuration

### Custom CSS

```bash
nova build doc.nv --css style.css
```

### Custom HTML Template

Create `template.html`:

```html
<!DOCTYPE html>
<html>
<head>
  <title>{{title}}</title>
  <style>{{styles}}</style>
  {{mathjax}}
</head>
<body class="nova-document">{{content}}</body>
</html>
```

```bash
nova build doc.nv --template template.html
```

### LaTeX Preamble

When using `--latex`, Nova generates a complete LaTeX document. Pass `@meta` fields for document-level configuration.

---

## Standard Library

Nova ships with a rich standard library. Load with `@use "nova/std"`:

| Package               | Description                              |
|-----------------------|------------------------------------------|
| `std/sugar`           | Truthiness, comparison, string helpers   |
| `std/functional`      | `pipe`, `compose`, `map`, `filter`, etc. |
| `std/control`         | `when`, `unless`, `switch`, `cond`       |
| `std/types`           | Type checking, conversion, JSON, clone   |
| `std/strings`         | String manipulation utilities            |
| `std/math`            | Math helpers                             |
| `std/lists`           | List operations                          |
| `std/datetime`        | Date/time formatting, math, ranges       |
| `std/encoding`        | Base64, URL, hex encoding                |
| `std/colors`          | Named colors utility                     |
| `std/random`          | Random generation                        |
| `std/json`            | JSON read/write utilities                |
| `std/io`              | File I/O helpers                         |
| `std/plot`            | Plotting primitives                      |
| `std/components`      | Reusable UI components                   |
| `data/csv`            | CSV parsing and generation               |
| `data/json`           | JSON processing                          |
| `data/yaml`           | YAML processing                          |
| `data/sql`            | SQL query generation                     |
| `data/excel`          | Excel file support                       |
| `data/stats`          | Statistics functions                     |
| `data/transform`      | Data transformation pipelines            |
| `schema/types`        | Type system definitions                  |
| `schema/api`          | API specification                        |
| `schema/openapi`      | OpenAPI code generation                  |
| `schema/grpc`         | gRPC/Protobuf code generation            |
| `schema/graphql`      | GraphQL schema generation                |
| `schema/db`           | Database schema generation               |
| `schema/codegen`      | Multi-language code generation           |
| `schema/validation`   | Validation rule generation               |
| `ui/layout`           | Layout components                        |
| `ui/typography`       | Typography components                    |
| `ui/form`             | Form components                          |
| `ui/navigation`       | Navigation components                    |
| `ui/surface`          | Surface/card components                  |
| `ui/media`            | Media components                         |
| `ui/feedback`         | Feedback/alert components                |
| `nova/http`           | HTTP client                              |
| `nova/crypto`         | Cryptography (hash, HMAC, AES, UUID)     |
| `nova/html`           | HTML rendering utilities                 |
| `nova/markdown`       | Markdown conversion                      |
| `nova/fs`             | Filesystem operations                    |

---

## Examples

The `examples/` directory contains many sample `.nv` files:

| Example            | Demo                                      |
|--------------------|-------------------------------------------|
| `basics.nv`        | Comments, strings, numbers, attributes    |
| `blocks.nv`        | Block types and nesting                   |
| `flow.nv`          | `@if`/`@else`, `@for` loops              |
| `macros.nv`        | `@def` macro definitions and calls       |
| `schemas.nv`       | `@schema` and `@service` type definitions |
| `tables.nv`        | Table variants (array, header+row, mixed) |
| `math.nv`          | Inline and display math                  |
| `paper.nv`         | Complete academic paper example           |

---

## License

[MIT](LICENSE)
