# lml

> Light Meta Language. A simple-yet-powerful HTML syntax alternative

Latest version **0.8.1** (published 2019-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install lml
pnpm add lml
yarn add lml
bun add lml
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.1 |
| Published | 2019-01-08 |
| First published | 2018-12-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 112.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Greg Varsanyi |
| Maintainers | gvarsanyi |
| Keywords | lml, html, alternative, ast, compiler, translate, simple, hierarchy, dom, xml, parser |

## Links

- npm: https://www.npmjs.com/package/lml
- Repository: https://github.com/lml-dom/lml-js
- Homepage: https://lml-dom.org/
- Issues: https://github.com/lml-dom/lml-js/issues
- npm.io page: https://npm.io/package/lml

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.8.1 (latest) — 2019-01-08
- 0.8.0 — 2019-01-08
- 0.7.0 — 2019-01-03
- 0.6.1 — 2018-12-31
- 0.6.0 — 2018-12-31
- 0.5.1 — 2018-12-20
- 0.5.0 — 2018-12-20
- 0.4.1 — 2018-12-18
- 0.4.0 — 2018-12-16
- 0.3.2 — 2018-12-13
- 0.3.1 — 2018-12-13
- 0.3.0 — 2018-12-12
- 0.2.0 — 2018-12-10
- 0.1.2 — 2018-12-10
- 0.1.1 — 2018-12-07
- … 1 more at https://npm.io/package/lml/versions

## README

# LML
Light Meta Language - an HTML alternative

## Concept
- Indentation-based hierarchy - obvious hierarchy
- Enforced one-statement-per-line with reasonable multiline attributes option
- No `<`, `>` character, and no closing tag
- Simple directives for text (`;`), comment (`#`), cdata (`$`)
- No templating trickery - as static as HTML
- Maintained attribute string compatibility with HTML
  - It works well with stuff like Angular event handler attributes (e.g. `(click)="x = 'nah'"`) unlike Pug/Jade

## Example
```lml
!DOCTYPE html
html
  head
    title ; My Title
    script type="text/javascript" src="ext.js"
    script type="text/javascript"
      alert('Hello');
    style
      body { color: #333; }
  body
    # A comment
    div id="wrapper"
      ; My Site!
```
Translates to
```html
<!DOCTYPE html>
<html>
  <head>
    <title>
      My Title
    </title>
    <script type="text/javascript" src="ext.js"></script>
    <script type="text/javascript">
      alert('Hello');
    </script>
    <style>
      body { color: #333; }
    </style>
  </head>
  <body>
    <!-- A comment -->
    <div id="wrapper">
      My Site!
    </div>
  </body>
</html>
```

## Programmatical use
### Install for your project
`npm install lml --save`
### Parsers produce AST and convert

#### JavaScript example
```javascript
// convert LML to HTML
const parseLML = require('lml').parseLML;

parseLML(lmlString).toHTML();
```

#### Parsers
Parser functions are exposed with the same signiture, and the returned object has the same interface:
`parseAST(source: string | ASTModel[], parseConfig?: ParseConfig) => ParserInterface`
`parseJSON(source: string | JSONModel[], parseConfig?: ParseConfig) => ParserInterface`
`parseLML(source: string, parseConfig?: ParseConfig) => ParserInterface`

##### Parsing HTML
1. install [html-lml](https://github.com/lml-dom/html-lml):
`npm install html-lml --save`
2. use the the indentical parser from that package:
`parseHTML(source: string, parseConfig?: ParseConfig) => ParserInterface`

Parser interface:
```typescript
interface ParserInterface {
  errors: ParseError[];
  toAST(config?: OutputConfig): ASTModel[];
  toHTML(config?: OutputConfig): string;
  toJSON(config?: OutputConfig): JSONModel[];
  toLML(config?: OutputConfig): string;
}
```

#### Configurations
```typescript
interface ParseConfig {
  indentation?: string; // for parsing LML, if autodetection is not adequate
  url?: string; // path to source file
}

interface OutputConfig {
  indentation?: string;
  lineWrap?: number;
  minify?: boolean;
  orderAttributes?: 'ascii' | 'natural' | 'angular'; // angular order means: <tag *ngXxx="x" any="x" [other]="x" prop="x" [(banana)]="box" (event)="e()" (handler)="e()" >
}
```

#### AST Model
AST model is used by a variety of DOM parsers, like https://astexplorer.net/
```typescript
interface ASTModel {
  type: 'cdata' | 'comment' | 'directive' | 'script' | 'style' | 'tag' | 'text';
  name?: string; // element (e.g. tag) name
  data?: string; // value of comment, directive, and text
  attribs?: {[name: string]: string};
  children?: ASTModel[];
  startIndex?: number;
  endIndex?: number;
}
```

#### JSON Model
The native structure used by these libraries
```typescript
interface JSONModel {
  type: 'cdata' | 'comment' | 'directive' | 'element' | 'text';
  name?: string; // element name
  data?: string; // value of comment, directive, and text
  attributes?: {name: string; value?: string}[];
  children?: JSONModel[];
}
```

## CLI
There is a dedicated command line tool: [lml-cli](https://github.com/lml-dom/lml-cli)

---
_Source: https://npm.io/package/lml · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
