@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.
- package/README.md +45 -97
- package/index.d.ts +17 -10
- package/index.js +617 -380
- package/package.json +13 -12
package/README.md
CHANGED
|
@@ -1,133 +1,81 @@
|
|
|
1
1
|
# markers
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://dl.circleci.com/status-badge/redirect/circleci/stZqvYiNAK17m5zy7ERCb/5KDDkHQnUroSHKP957pxaW/tree/main) [](https://www.npmjs.com/package/@farhnkrnapratma/markers) [](https://crates.io/crates/markers) [](https://docs.rs/markers) 
|
|
4
4
|
|
|
5
|
-
|
|
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
|
|
7
|
+
> **Alpha.** The API may still change before 1.0.0. On npm, install the `alpha` tag.
|
|
8
8
|
|
|
9
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
|
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
|
-
|
|
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(
|
|
31
|
+
const { convert, convertAsync } = require("@farhnkrnapratma/markers");
|
|
55
32
|
|
|
56
|
-
convert(
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
43
|
+
### Rust
|
|
88
44
|
|
|
89
|
-
|
|
45
|
+
```rust
|
|
46
|
+
use markers::{ConversionOptions, HeadingStyle};
|
|
90
47
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
57
|
+
`convert_with_options` returns an error when an include or exclude selector is not valid CSS.
|
|
101
58
|
|
|
102
|
-
|
|
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
|
-
|
|
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
|
-
|
|
111
|
-
cargo check --target wasm32-unknown-unknown --features wasm
|
|
112
|
-
```
|
|
71
|
+
## WebAssembly
|
|
113
72
|
|
|
114
|
-
|
|
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
|
-
|
|
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:
|
|
10
|
+
export declare const __napiBindingTarget:
|
|
11
|
+
"native" | "wasm32-wasi" | "wasm32-wasip1";
|
|
11
12
|
|
|
12
13
|
export interface ConversionOptions {
|
|
13
|
-
headingStyle?:
|
|
14
|
-
linkStyle?:
|
|
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(
|
|
23
|
+
export declare function convert(
|
|
24
|
+
html: string,
|
|
25
|
+
options?: ConversionOptions | undefined | null,
|
|
26
|
+
): string;
|
|
23
27
|
|
|
24
|
-
export declare function convertAsync(
|
|
28
|
+
export declare function convertAsync(
|
|
29
|
+
html: string,
|
|
30
|
+
options?: ConversionOptions | undefined | null,
|
|
31
|
+
): Promise<string>;
|