@farhnkrnapratma/markers 1.0.0-alpha1 → 1.0.0-alpha2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +45 -97
  2. package/index.d.ts +17 -10
  3. package/index.js +617 -380
  4. package/package.json +13 -12
package/README.md CHANGED
@@ -1,133 +1,81 @@
1
1
  # markers
2
2
 
3
- High-performance HTML to Markdown conversion for LLMs, written in Rust.
3
+ [![CircleCI](https://dl.circleci.com/status-badge/img/circleci/stZqvYiNAK17m5zy7ERCb/5KDDkHQnUroSHKP957pxaW/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/circleci/stZqvYiNAK17m5zy7ERCb/5KDDkHQnUroSHKP957pxaW/tree/main) [![npm](https://img.shields.io/npm/v/@farhnkrnapratma/markers/alpha?label=npm)](https://www.npmjs.com/package/@farhnkrnapratma/markers) [![crates.io](https://img.shields.io/crates/v/markers?label=crates.io)](https://crates.io/crates/markers) [![docs.rs](https://img.shields.io/docsrs/markers)](https://docs.rs/markers) ![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue)
4
4
 
5
- ## Status
5
+ Converts HTML to clean GitHub Flavored Markdown. It is built for turning web pages into text for large language models: page chrome and non-text elements are dropped, unsafe links are removed, and CSS selectors let you keep only the content you want. The converter is written in Rust and is available as a Rust crate and as an npm package for Node.js and Bun.
6
6
 
7
- Alpha (`v1.0.0-alpha1`). The API can still change before the first stable release.
7
+ > **Alpha.** The API may still change before 1.0.0. On npm, install the `alpha` tag.
8
8
 
9
- | Registry | Name |
10
- | --- | --- |
11
- | crates.io | [`markers`](https://crates.io/crates/markers) |
12
- | npm | [`@farhnkrnapratma/markers`](https://www.npmjs.com/package/@farhnkrnapratma/markers) |
9
+ ## Features
13
10
 
14
- One package, one `src/`. The bindings are optional Cargo features:
15
-
16
- | Feature | Source | Purpose |
17
- | --- | --- | --- |
18
- | *(none)* | `src/lib.rs` | Rust library |
19
- | `napi` | `src/bindings/node.rs` | Node.js / Bun bindings, published as `@farhnkrnapratma/markers` |
20
- | `wasm` | `src/bindings/wasm.rs` | WebAssembly bindings |
11
+ - **GitHub Flavored Markdown output**: headings, lists, task lists, tables, blockquotes, code blocks, strikethrough, links and images, plus definition lists, `<details>`, figures and abbreviations.
12
+ - **Clean text for LLMs**: `<head>`, `<script>`, `<style>`, `<noscript>`, `<template>`, `<nav>`, `<svg>`, `<iframe>`, `<object>`, `<canvas>` and `<select>` are dropped, and `javascript:` links are removed while their text is kept.
13
+ - **Selectors**: drop more of a page with CSS selectors, and keep the parts you name even inside dropped ones (for example `includeSelectors: ["nav"]` to keep navigation).
14
+ - **Relative URLs resolved** against a base URL you provide.
15
+ - **Robust on hostile input**: documents nested more than 5,000 levels deep are rejected instead of exhausting the stack.
21
16
 
22
17
  ## Install
23
18
 
24
19
  ```sh
25
- cargo add markers # Rust
26
- bun add @farhnkrnapratma/markers # Node.js / Bun (or: npm install @farhnkrnapratma/markers)
20
+ npm install @farhnkrnapratma/markers@alpha # or: bun add @farhnkrnapratma/markers@alpha
21
+ cargo add markers # Rust
27
22
  ```
28
23
 
29
- The npm package ships prebuilt binaries for Linux (x64 and arm64, glibc and musl), macOS (x64 and arm64) and Windows (x64 and arm64) as optional dependencies, so nothing is compiled on install.
24
+ The npm package ships prebuilt native addons for Linux (x64 and arm64, glibc and musl), macOS (x64 and arm64) and Windows (x64 and arm64), so nothing is compiled on install.
30
25
 
31
26
  ## Usage
32
27
 
33
- Rust:
34
-
35
- ```rust
36
- fn main() -> Result<(), String> {
37
- let _markdown = markers::convert("<h1>Hello</h1>");
38
-
39
- let options = markers::ConversionOptions::new()
40
- .heading_style(markers::HeadingStyle::Setext)
41
- .base_url(Some("https://example.com".to_string()))
42
- .exclude_selectors(vec!["nav".to_string()]);
43
- let markdown = markers::convert_with_options("<h1>Hello</h1>", &options)?;
44
- println!("{markdown}");
45
- Ok(())
46
- }
47
- ```
48
-
49
- `convert_with_options` returns an error when an include or exclude CSS selector is invalid.
50
-
51
- Node.js / Bun:
28
+ ### Node.js and Bun
52
29
 
53
30
  ```js
54
- const { convert, convertAsync } = require('@farhnkrnapratma/markers')
31
+ const { convert, convertAsync } = require("@farhnkrnapratma/markers");
55
32
 
56
- convert('<h1>Hello</h1>')
57
- convert('<h1>Hello</h1>', { headingStyle: 'setext', baseUrl: 'https://example.com' })
58
- await convertAsync('<h1>Hello</h1>')
59
- ```
60
-
61
- ## Options
33
+ convert("<h1>Hello</h1>"); // "# Hello"
62
34
 
63
- | Option (Rust / JS) | Values | Default |
64
- | --- | --- | --- |
65
- | `heading_style` / `headingStyle` | `atx`, `setext` | `atx` |
66
- | `link_style` / `linkStyle` | `inline`, `referenced` | `inline` |
67
- | `code_fence` / `codeFence` | `` ` ``, `~` | `` ` `` |
68
- | `bullet_marker` / `bulletMarker` | `-`, `*`, `+` | `-` |
69
- | `base_url` / `baseUrl` | URL used to resolve relative links and images | none |
70
- | `exclude_selectors` / `excludeSelectors` | CSS selectors to drop | none |
71
- | `include_selectors` / `includeSelectors` | CSS selectors kept even if an exclude selector matches | none |
35
+ convert(html, {
36
+ baseUrl: "https://example.com/blog/",
37
+ excludeSelectors: ["footer", ".ads"],
38
+ });
72
39
 
73
- ## Repository layout
74
-
75
- ```
76
- src/
77
- lib.rs public API: convert, convert_with_options, ConversionOptions
78
- options.rs ConversionOptions, HeadingStyle, LinkStyle
79
- pipeline/ the conversion: input_guard -> parse -> annotate -> render -> cleanup
80
- handlers/ one TagHandler per group of tags (block/ and inline/)
81
- text/ Markdown escaping, URL handling, whitespace
82
- bindings/ Node.js (napi) and WebAssembly (wasm) glue
83
- tests/ integration tests and HTML fixtures
84
- examples/ Rust, Node.js and browser demos
40
+ await convertAsync(html); // runs off the main thread
85
41
  ```
86
42
 
87
- ## Development
43
+ ### Rust
88
44
 
89
- Requirements: Rust (stable) and Cargo, and [Bun](https://bun.sh) for the JavaScript side (`bun.lock` is the only lockfile).
45
+ ```rust
46
+ use markers::{ConversionOptions, HeadingStyle};
90
47
 
91
- ```sh
92
- bun install # JS dependencies and git hooks
93
- bun run build # Node.js / Bun binding for this platform
94
- cargo test --features napi # unit and integration tests, plus the napi module
95
- bun run test # Node.js binding tests (after bun run build)
96
- cargo clippy --all-targets --features napi
97
- cargo bench --bench conversion # set MARKERS_BENCH_ITERATIONS to change the run length
48
+ let markdown = markers::convert("<h1>Hello</h1>");
49
+
50
+ let options = ConversionOptions::new()
51
+ .heading_style(HeadingStyle::Setext)
52
+ .base_url(Some("https://example.com".to_string()))
53
+ .exclude_selectors(vec!["nav".to_string()]);
54
+ let markdown = markers::convert_with_options(html, &options)?;
98
55
  ```
99
56
 
100
- Examples:
57
+ `convert_with_options` returns an error when an include or exclude selector is not valid CSS.
101
58
 
102
- ```sh
103
- cargo run --example basic # default options
104
- cargo run --example options # headings, bullets, links, selectors
105
- bun examples/node.js # Node.js / Bun (after bun run build)
106
- ```
59
+ ## Options
107
60
 
108
- `examples/wasm.html` is a browser demo for the `wasm` build, which needs the `wasm32-unknown-unknown` target (`napi` is compiled out on `wasm32`, so `--all-features` also works there):
61
+ | Option (Rust / JavaScript) | Values | Default |
62
+ | ---------------------------------------- | ------------------------------------------------------- | -------- |
63
+ | `heading_style` / `headingStyle` | `atx` (`# Title`), `setext` (underlined) | `atx` |
64
+ | `link_style` / `linkStyle` | `inline`, `referenced` | `inline` |
65
+ | `code_fence` / `codeFence` | `` ` ``, `~` | `` ` `` |
66
+ | `bullet_marker` / `bulletMarker` | `-`, `*`, `+` | `-` |
67
+ | `base_url` / `baseUrl` | URL used to resolve relative links and images | none |
68
+ | `exclude_selectors` / `excludeSelectors` | CSS selectors to drop | none |
69
+ | `include_selectors` / `includeSelectors` | CSS selectors kept even if an exclude selector matches | none |
109
70
 
110
- ```sh
111
- cargo check --target wasm32-unknown-unknown --features wasm
112
- ```
71
+ ## WebAssembly
113
72
 
114
- Releases are cut with git-flow (`git-flow release start/finish`). Pushing a `v*` tag makes CircleCI build the bindings for every platform and publish them to npm; the crate is published with `cargo publish`.
73
+ The crate's `wasm` feature builds WebAssembly bindings with the same API; [`examples/wasm.html`](https://github.com/farhnkrnapratma/markers/blob/main/examples/wasm.html) shows them in a browser. The npm package does not include a WebAssembly build yet.
115
74
 
116
75
  ## Contributing
117
76
 
118
- This repository uses [git-flow-next](https://git-flow.sh/) (classic preset): `main` is release-only, work happens on `feature/*` and `bugfix/*` branches off `develop`. Commits are signed off (`git commit -s`) and follow [Conventional Commits](https://www.conventionalcommits.org), enforced by commitlint in a `commit-msg` hook and in CI. Install the hooks with `bash .githooks/install.sh` (`bun install` does it through the `prepare` script). CI runs on CircleCI: `reuse lint`, format and lint, tests, `cargo deny`, a TruffleHog secret scan and commitlint on every push. The branch rules are written out in [`CLAUDE.md`](CLAUDE.md).
77
+ Bug reports and pull requests are welcome. [`CONTRIBUTING.md`](https://github.com/farhnkrnapratma/markers/blob/main/CONTRIBUTING.md) explains how to build, test and submit changes.
119
78
 
120
79
  ## License
121
80
 
122
- Licensed under either of
123
-
124
- - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
125
- - MIT License ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
126
-
127
- at your option.
128
-
129
- Unless you explicitly state otherwise, any contribution intentionally submitted
130
- for inclusion in this project by you, as defined in the Apache-2.0 license,
131
- shall be dual licensed as above, without any additional terms or conditions.
132
-
133
- Copyright © 2026 Farhan Kurnia Pratama
81
+ Licensed under either of the [Apache License, Version 2.0](https://github.com/farhnkrnapratma/markers/blob/main/LICENSE-APACHE) or the [MIT License](https://github.com/farhnkrnapratma/markers/blob/main/LICENSE-MIT), at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
package/index.d.ts CHANGED
@@ -7,18 +7,25 @@
7
7
  * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
8
  * can point the loader at a WASI artifact this package does not build itself.
9
9
  */
10
- export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
10
+ export declare const __napiBindingTarget:
11
+ "native" | "wasm32-wasi" | "wasm32-wasip1";
11
12
 
12
13
  export interface ConversionOptions {
13
- headingStyle?: 'atx' | 'setext'
14
- linkStyle?: 'inline' | 'referenced'
15
- codeFence?: '`' | '~'
16
- bulletMarker?: '-' | '*' | '+'
17
- baseUrl?: string
18
- excludeSelectors?: Array<string>
19
- includeSelectors?: Array<string>
14
+ headingStyle?: "atx" | "setext";
15
+ linkStyle?: "inline" | "referenced";
16
+ codeFence?: "`" | "~";
17
+ bulletMarker?: "-" | "*" | "+";
18
+ baseUrl?: string;
19
+ excludeSelectors?: Array<string>;
20
+ includeSelectors?: Array<string>;
20
21
  }
21
22
 
22
- export declare function convert(html: string, options?: ConversionOptions | undefined | null): string
23
+ export declare function convert(
24
+ html: string,
25
+ options?: ConversionOptions | undefined | null,
26
+ ): string;
23
27
 
24
- export declare function convertAsync(html: string, options?: ConversionOptions | undefined | null): Promise<string>
28
+ export declare function convertAsync(
29
+ html: string,
30
+ options?: ConversionOptions | undefined | null,
31
+ ): Promise<string>;