mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 02:15:01 +00:00
Explore HTML transform for normalizing Winamp forum HTML
This commit is contained in:
parent
4868c0d0b5
commit
e0241f01a9
6 changed files with 2138 additions and 0 deletions
1
packages/winamp-forum-normalizer/.gitignore
vendored
Normal file
1
packages/winamp-forum-normalizer/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
out.html
|
||||
6
packages/winamp-forum-normalizer/README.md
Normal file
6
packages/winamp-forum-normalizer/README.md
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Install and Run
|
||||
|
||||
```bash
|
||||
yarn install
|
||||
node index.js
|
||||
```
|
||||
2086
packages/winamp-forum-normalizer/example.html
Normal file
2086
packages/winamp-forum-normalizer/example.html
Normal file
File diff suppressed because it is too large
Load diff
21
packages/winamp-forum-normalizer/index.js
Normal file
21
packages/winamp-forum-normalizer/index.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import fs from "fs";
|
||||
import Hat from "html-ast-transform";
|
||||
|
||||
const { transform, h, getAttr, hasClass } = Hat;
|
||||
|
||||
const replaceTags = {
|
||||
code: (node) => {
|
||||
return h("h1", [], [h("#text", "Hello")]);
|
||||
},
|
||||
};
|
||||
|
||||
function clean(html) {
|
||||
return transform(html, { replaceTags });
|
||||
}
|
||||
|
||||
function main(fileName, output) {
|
||||
const html = fs.readFileSync(fileName, { encoding: "utf8" });
|
||||
fs.writeFileSync(output, clean(html));
|
||||
}
|
||||
|
||||
main("./example.html", "out.html");
|
||||
11
packages/winamp-forum-normalizer/package.json
Normal file
11
packages/winamp-forum-normalizer/package.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "winamp-forum-normalizer",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"html-ast-transform": "^2.0.1",
|
||||
"parse5": "^6.0.1"
|
||||
}
|
||||
}
|
||||
13
packages/winamp-forum-normalizer/yarn.lock
Normal file
13
packages/winamp-forum-normalizer/yarn.lock
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
html-ast-transform@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/html-ast-transform/-/html-ast-transform-2.0.1.tgz#404f7cac93f8aecd425ee3e381718e5e253eaded"
|
||||
integrity sha512-ryBf1oxFM1s12/lD2qChqrdsG0Y2ajdCZJnNPjY2oeS+UDF3wwYP7ubP0wxM6h72dKxdgtmihAc55x3gtDqM4Q==
|
||||
|
||||
parse5@^6.0.1:
|
||||
version "6.0.1"
|
||||
resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b"
|
||||
integrity sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==
|
||||
Loading…
Add table
Add a link
Reference in a new issue