Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.2.2

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Run tests
run: bun run test
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,31 @@ Converts a YAHTML array to an HTML string.
- `TypeError`: If yahtmlContent is not an array
- `Error`: If element structure is malformed

#### `parseElementKey(key)`

Parses a YAHTML element declaration key (selector + attrs) into structured metadata.

**Parameters:**
- `key` (string): Element key like `div#main.card data-id=42`

**Returns:**
- Parsed selector object with:
- `tag`, `id`, `classes`, `attributes`
- `ranges` for tag/id/class offsets within the key

#### `parseYahtmlAst(yahtmlContent)`

Builds an AST from YAHTML input without rendering HTML.

**Parameters:**
- `yahtmlContent` (Array): YAHTML content array

**Returns:**
- Root AST node:
- `{ type: "root", children: [...] }`
- Child node kinds:
- `element`, `text`, `rawHtml`, `doctype`, `fragment`

**Throws:**
- `TypeError`: If `yahtmlContent` is not an array
- `Error`: If an element declaration is malformed
12 changes: 10 additions & 2 deletions index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ module.exports = {
convertToHtml: (...args) => {
throw new Error('yahtml requires async initialization in CommonJS. Use: const yahtml = await require("yahtml")');
},
SELF_CLOSING_TAGS: []
SELF_CLOSING_TAGS: [],
parseElementKey: (...args) => {
throw new Error('yahtml requires async initialization in CommonJS. Use: const yahtml = await require("yahtml")');
},
parseYahtmlAst: (...args) => {
throw new Error('yahtml requires async initialization in CommonJS. Use: const yahtml = await require("yahtml")');
}
};

// Async initialization for CommonJS
Expand All @@ -18,6 +24,8 @@ module.exports = (async () => {
return {
convertToHtml: mod.convertToHtml,
SELF_CLOSING_TAGS: mod.SELF_CLOSING_TAGS,
parseElementKey: mod.parseElementKey,
parseYahtmlAst: mod.parseYahtmlAst,
default: mod.convertToHtml
};
})();
})();
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { convertToHtml, SELF_CLOSING_TAGS } from "./src/yahtml";
export { convertToHtml, SELF_CLOSING_TAGS, parseElementKey, parseYahtmlAst } from "./src/yahtml";
export default convertToHtml;
declare const convertToHtml: typeof import("./src/yahtml").convertToHtml;
declare const convertToHtml: typeof import("./src/yahtml").convertToHtml;
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @module yahtml
* @description YAHTML (YAML HTML) - Write HTML as valid YAML
* @version 0.0.1
* @version 0.0.5
* @license MIT
*/

export { convertToHtml, SELF_CLOSING_TAGS } from './src/yahtml.js';
export { convertToHtml, SELF_CLOSING_TAGS, parseElementKey, parseYahtmlAst } from './src/yahtml.js';
import { convertToHtml } from './src/yahtml.js';
export default convertToHtml;
export default convertToHtml;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yahtml",
"version": "0.0.4",
"version": "0.0.5",
"description": "YAHTML (YAML HTML) - Write HTML as valid YAML with clean, concise syntax",
"keywords": [
"html",
Expand Down
Loading