diff --git a/1224/parse5.md b/1224/parse5.md new file mode 100644 index 0000000000000000000000000000000000000000..ee7d04381460314bb74ebcab846518c53c2b3863 --- /dev/null +++ b/1224/parse5.md @@ -0,0 +1,93 @@ +> 模板版本:v0.1.2 + +

+

parse5

+

+

+ + License + +

+ +>[!tip] [Github 地址](https://github.com/inikulin/parse5) + + +## 安装与使用 + +进入到工程目录并输入以下命令: + +#### **yarn** + +```bash +yarn add parse5@7.1.2 +``` + + +#### **npm** + +```bash +npm install parse5@7.1.2 +``` + + + +下面的代码展示了这个库的基本使用场景: + +```js +const parse5 = require('parse5'); + +// parse +const document = parse5.parse('Hi there!'); +console.log(document.childNodes[1].tagName); //> 'html' + +// parseFragment +const documentFragment = parse5.parseFragment('
'); +console.log(documentFragment.childNodes[0].tagName); //> 'table' +const trFragment = parse5.parseFragment(documentFragment.childNodes[0], 'Shake it, baby'); +console.log(trFragment.childNodes[0].childNodes[0].tagName); //> 'td' + +// serialize +const document = parse5.parse('Hi there!'); +// Serializes a document. +const html = parse5.serialize(document); +// Serializes the element content. +const str = parse5.serialize(document.childNodes[1]); +console.log(str); //> 'Hi there!' + +// serializeOuter +const document = parse5.parseFragment('
Hello, world!
'); +// Serializes the
element. +const str = parse5.serializeOuter(document.childNodes[0]); +console.log(str); //> '
Hello, world!
' +``` + +## 约束与限制 + +### 兼容性 + + 在下述版本验证通过: + + 1. IDE:DevEco Studio 4.1.3.313;SDK:OpenHarmony(api11) 4.1.0.52;测试设备:Mate40 Pro(NOH-AN00);ROM:204.1.0.52(C00E52R1P17log);RNOH:0.72.11 + +## API + +> [!tip] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 + +详情见 [parse5文档地址](https://parse5.js.org/index.html) + +| Name | Description | Type | Required | HarmonyOS Support | +| ---------------------------------------------- | ----------------------------------------------------------------------------- | -------- | -------- | ----------------- | +| parse(html, options?) | Parses an HTML string. | function | no | yes | +| parseFragment(fragmentContext, html, options?) | Parses an HTML fragment. | function | no | yes | +| serialize(node, options?) | Serializes an AST node to an HTML string. | function | no | yes | +| serializeOuter(node, options?) | Serializes an AST element node to an HTML string, including the element node. | function | no | yes | + +## 遗留问题 + +## 其他 + +## 开源协议 + +本项目基于 [The MIT License (MIT)](https://github.com/inikulin/parse5/blob/master/LICENSE) ,请自由地享受和参与开源。