From c0cd55eafca0baed2619ccb8264c277ee014ee9b Mon Sep 17 00:00:00 2001 From: Qrac Date: Sat, 18 Feb 2023 14:25:48 +0900 Subject: [PATCH] Add README --- README.md | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bcce51a..ee35615 100644 --- a/README.md +++ b/README.md @@ -1 +1,133 @@ -# jsxlike \ No newline at end of file +# jsxlike + +## About + +HTML 文字列を React の JSX で使える構文におおよそ変換します。 + +- 依存ライブラリゼロ +- 正規表現の文字列マッチングと replace 関数のみなので軽量で高速 +- 厳密な構文処理ではないので未実装のパターンは処理されない + +## How To Use + +```sh +$ npm i jsxlike +``` + +```js +import jsxlike from "jsxlike" + +const htmlStr = `

bbb

` + +console.log(jsxlike(htmlStr, {} /* options */)) +// =>

bbb

+``` + +## Options + +```ts +const defaultOptions = { + extractTags: [], + mapAttrs: { + class: "className", + charset: "charSet", + for: "htmlFor", + tabindex: "tabIndex", + readonly: "readOnly", + maxlength: "maxLength", + colspan: "colSpan", + rowspan: "rowSpan", + cellspacing: "cellSpacing", + cellpadding: "cellPadding", + usemap: "useMap", + frameborder: "frameBorder", + "xlink:href": "href", + }, + styleAttrs: true, + styleTags: true, + scriptTags: true, + commentTags: true, + voidTags: ["meta", "link", "img", "input", "br", "wbr", "hr"], + shortTags: ["*"], + absolutePath: "", + absoluteAttrs: { + link: ["href"], + script: ["src"], + img: ["src"], + use: ["xlink:href", "href"], + }, +} +``` + +### extractTags + +type: `string[]` + +特定の HTML タグを抽出できます。例えば `["link", "script"]` とすることで `` `