@farhnkrnapratma/markers 1.0.0-alpha1 → 1.0.0-alpha3
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 +51 -97
- package/index.d.ts +17 -10
- package/index.js +617 -380
- package/package.json +27 -16
package/README.md
CHANGED
|
@@ -1,133 +1,87 @@
|
|
|
1
1
|
# markers
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://dl.circleci.com/status-badge/redirect/circleci/stZqvYiNAK17m5zy7ERCb/5KDDkHQnUroSHKP957pxaW/tree/main) [](https://codecov.io/gh/farhnkrnapratma/markers) [](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
|
|
30
|
-
|
|
31
|
-
## Usage
|
|
32
|
-
|
|
33
|
-
Rust:
|
|
24
|
+
The npm package ships prebuilt native addons as optional dependencies, so nothing is compiled on install:
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
```
|
|
26
|
+
| OS | Architectures |
|
|
27
|
+
| ------- | --------------------------------------------------------------- |
|
|
28
|
+
| Linux | x64 and arm64 (glibc and musl), armv7, ppc64le, s390x, riscv64 |
|
|
29
|
+
| macOS | arm64, x64 |
|
|
30
|
+
| Windows | x64, arm64, ia32 |
|
|
48
31
|
|
|
49
|
-
|
|
32
|
+
## Usage
|
|
50
33
|
|
|
51
|
-
Node.js
|
|
34
|
+
### Node.js and Bun
|
|
52
35
|
|
|
53
36
|
```js
|
|
54
|
-
const { convert, convertAsync } = require(
|
|
55
|
-
|
|
56
|
-
convert('<h1>Hello</h1>')
|
|
57
|
-
convert('<h1>Hello</h1>', { headingStyle: 'setext', baseUrl: 'https://example.com' })
|
|
58
|
-
await convertAsync('<h1>Hello</h1>')
|
|
59
|
-
```
|
|
37
|
+
const { convert, convertAsync } = require("@farhnkrnapratma/markers");
|
|
60
38
|
|
|
61
|
-
|
|
62
|
-
|
|
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 |
|
|
39
|
+
convert("<h1>Hello</h1>"); // "# Hello"
|
|
72
40
|
|
|
73
|
-
|
|
41
|
+
convert(html, {
|
|
42
|
+
baseUrl: "https://example.com/blog/",
|
|
43
|
+
excludeSelectors: ["footer", ".ads"],
|
|
44
|
+
});
|
|
74
45
|
|
|
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
|
|
46
|
+
await convertAsync(html); // runs off the main thread
|
|
85
47
|
```
|
|
86
48
|
|
|
87
|
-
|
|
49
|
+
### Rust
|
|
88
50
|
|
|
89
|
-
|
|
51
|
+
```rust
|
|
52
|
+
use markers::{ConversionOptions, HeadingStyle};
|
|
90
53
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
54
|
+
let markdown = markers::convert("<h1>Hello</h1>");
|
|
55
|
+
|
|
56
|
+
let options = ConversionOptions::new()
|
|
57
|
+
.heading_style(HeadingStyle::Setext)
|
|
58
|
+
.base_url(Some("https://example.com".to_string()))
|
|
59
|
+
.exclude_selectors(vec!["nav".to_string()]);
|
|
60
|
+
let markdown = markers::convert_with_options(html, &options)?;
|
|
98
61
|
```
|
|
99
62
|
|
|
100
|
-
|
|
63
|
+
`convert_with_options` returns an error when an include or exclude selector is not valid CSS.
|
|
101
64
|
|
|
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
|
-
```
|
|
65
|
+
## Options
|
|
107
66
|
|
|
108
|
-
|
|
67
|
+
| Option (Rust / JavaScript) | Values | Default |
|
|
68
|
+
| ---------------------------------------- | ------------------------------------------------------- | -------- |
|
|
69
|
+
| `heading_style` / `headingStyle` | `atx` (`# Title`), `setext` (underlined) | `atx` |
|
|
70
|
+
| `link_style` / `linkStyle` | `inline`, `referenced` | `inline` |
|
|
71
|
+
| `code_fence` / `codeFence` | `` ` ``, `~` | `` ` `` |
|
|
72
|
+
| `bullet_marker` / `bulletMarker` | `-`, `*`, `+` | `-` |
|
|
73
|
+
| `base_url` / `baseUrl` | URL used to resolve relative links and images | none |
|
|
74
|
+
| `exclude_selectors` / `excludeSelectors` | CSS selectors to drop | none |
|
|
75
|
+
| `include_selectors` / `includeSelectors` | CSS selectors kept even if an exclude selector matches | none |
|
|
109
76
|
|
|
110
|
-
|
|
111
|
-
cargo check --target wasm32-unknown-unknown --features wasm
|
|
112
|
-
```
|
|
77
|
+
## WebAssembly
|
|
113
78
|
|
|
114
|
-
|
|
79
|
+
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
80
|
|
|
116
81
|
## Contributing
|
|
117
82
|
|
|
118
|
-
|
|
83
|
+
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
84
|
|
|
120
85
|
## License
|
|
121
86
|
|
|
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
|
|
87
|
+
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>;
|