@plurnk/plurnk-mimetypes-text-html 0.1.0
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/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/TextHtml.d.ts +5 -0
- package/dist/TextHtml.d.ts.map +1 -0
- package/dist/TextHtml.js +44 -0
- package/dist/TextHtml.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PossumTech Laboratories, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @plurnk/plurnk-mimetypes-text-html
|
|
2
|
+
|
|
3
|
+
`text/html` AND `application/xhtml+xml` mimetype handler for the [plurnk](https://github.com/plurnk) ecosystem. Converts HTML to markdown for LLM consumption via [turndown](https://www.npmjs.com/package/turndown).
|
|
4
|
+
|
|
5
|
+
## install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm i @plurnk/plurnk-mimetypes-text-html
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## what it does
|
|
12
|
+
|
|
13
|
+
HTML's value for an LLM lives in its rendered content, not in a separate symbol outline. So this handler overrides `preview()` to return the markdown-converted content directly, budgeted via the framework's `fitContent`:
|
|
14
|
+
|
|
15
|
+
- `preview(content, budget)` — turndown-converts to markdown, fit to budget tokens.
|
|
16
|
+
- `symbols(content)` — empty (the preview *is* the structural signal).
|
|
17
|
+
- `validate(content)` — no-op (HTML is forgiving).
|
|
18
|
+
|
|
19
|
+
Custom turndown rule (`safe-links`) salvaged from rummy.web: encodes parens in hrefs as `%28`/`%29` so URLs with literal parens don't break markdown's link syntax.
|
|
20
|
+
|
|
21
|
+
## not in scope
|
|
22
|
+
|
|
23
|
+
Web-page denoising (Readability-style filtering of nav/ads/comments) belongs in the fetcher layer (`plurnk-schemes-http` when it lands), not in a mimetype handler. This handler does pure HTML→markdown on whatever HTML it receives.
|
|
24
|
+
|
|
25
|
+
## license
|
|
26
|
+
|
|
27
|
+
MIT.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextHtml.d.ts","sourceRoot":"","sources":["../src/TextHtml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAc,MAAM,0BAA0B,CAAC;AAmCnE,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,WAAW;IACvC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAO/E"}
|
package/dist/TextHtml.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BaseHandler, fitContent } from "@plurnk/plurnk-mimetypes";
|
|
2
|
+
import TurndownService from "turndown";
|
|
3
|
+
// text/html + application/xhtml+xml handler. Converts HTML to markdown via
|
|
4
|
+
// turndown for LLM consumption. The structural value of HTML lives in its
|
|
5
|
+
// rendered content, not in a separate symbol outline — so this handler
|
|
6
|
+
// overrides preview() to return the markdown-converted content directly,
|
|
7
|
+
// budgeted via the framework's fitContent. symbols() stays empty (the
|
|
8
|
+
// BaseHandler default).
|
|
9
|
+
//
|
|
10
|
+
// Web-page denoising (Readability-style filtering of nav/ads/comments) is
|
|
11
|
+
// intentionally out of scope here — that's a fetcher concern (plurnk-schemes-http
|
|
12
|
+
// when it lands), not a mimetype concern. This handler does pure HTML→md.
|
|
13
|
+
//
|
|
14
|
+
// Custom turndown rule (`safe-links`) is salvaged from rummy.web/WebFetcher:
|
|
15
|
+
// encode parens in hrefs as %28/%29 so URLs with literal parens don't break
|
|
16
|
+
// markdown's link syntax.
|
|
17
|
+
const turndown = new TurndownService({
|
|
18
|
+
headingStyle: "atx",
|
|
19
|
+
codeBlockStyle: "fenced",
|
|
20
|
+
});
|
|
21
|
+
turndown.addRule("safe-links", {
|
|
22
|
+
filter: "a",
|
|
23
|
+
replacement(content, node) {
|
|
24
|
+
const el = node;
|
|
25
|
+
const href = el.getAttribute("href");
|
|
26
|
+
if (href === null)
|
|
27
|
+
return content;
|
|
28
|
+
const safeHref = href.replace(/\(/g, "%28").replace(/\)/g, "%29");
|
|
29
|
+
const title = el.getAttribute("title");
|
|
30
|
+
if (title !== null)
|
|
31
|
+
return `[${content}](${safeHref} "${title}")`;
|
|
32
|
+
return `[${content}](${safeHref})`;
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
export default class TextHtml extends BaseHandler {
|
|
36
|
+
async preview(content, budget) {
|
|
37
|
+
const html = typeof content === "string"
|
|
38
|
+
? content
|
|
39
|
+
: new TextDecoder("utf-8").decode(content);
|
|
40
|
+
const markdown = turndown.turndown(html);
|
|
41
|
+
return fitContent(markdown, budget, this.tokenize);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=TextHtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextHtml.js","sourceRoot":"","sources":["../src/TextHtml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,eAAe,MAAM,UAAU,CAAC;AAEvC,2EAA2E;AAC3E,0EAA0E;AAC1E,uEAAuE;AACvE,yEAAyE;AACzE,sEAAsE;AACtE,wBAAwB;AACxB,EAAE;AACF,0EAA0E;AAC1E,kFAAkF;AAClF,0EAA0E;AAC1E,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,0BAA0B;AAC1B,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC;IACjC,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,QAAQ;CAC3B,CAAC,CAAC;AAEH,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE;IAC3B,MAAM,EAAE,GAAG;IACX,WAAW,CAAC,OAAe,EAAE,IAAa;QACtC,MAAM,EAAE,GAAG,IAAqD,CAAC;QACjE,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,OAAO,CAAC;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,OAAO,KAAK,QAAQ,KAAK,KAAK,IAAI,CAAC;QAClE,OAAO,IAAI,OAAO,KAAK,QAAQ,GAAG,CAAC;IACvC,CAAC;CACJ,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,WAAW;IAC7C,KAAK,CAAC,OAAO,CAAC,OAA4B,EAAE,MAAc;QACtD,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ;YACpC,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/C,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvD,CAAC;CACJ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plurnk/plurnk-mimetypes-text-html",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "text/html and application/xhtml+xml mimetype handler for plurnk-service. Converts to markdown via turndown.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=25"
|
|
12
|
+
},
|
|
13
|
+
"plurnk": {
|
|
14
|
+
"kind": "mimetype",
|
|
15
|
+
"handlers": [
|
|
16
|
+
{ "name": "text/html", "glyph": "🌐", "extensions": [".html", ".htm"] },
|
|
17
|
+
{ "name": "application/xhtml+xml", "glyph": "🌐", "extensions": [".xhtml"] }
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist/**/*",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test:lint": "tsc --noEmit",
|
|
33
|
+
"test:unit": "node --test src/**/*.test.ts",
|
|
34
|
+
"test": "npm run test:lint && npm run test:unit",
|
|
35
|
+
"build:dist": "tsc -p tsconfig.build.json",
|
|
36
|
+
"build": "npm run build:dist",
|
|
37
|
+
"prepare": "npm run build"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@plurnk/plurnk-mimetypes": "^0.3.0",
|
|
41
|
+
"turndown": "^7.2.0",
|
|
42
|
+
"@types/turndown": "^5.0.5"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^25.8.0",
|
|
46
|
+
"typescript": "^6.0.3"
|
|
47
|
+
}
|
|
48
|
+
}
|