https://github.com/anduin2017/hsharp
HSharp is a library used to analyse markup language like HTML easily and fastly.
https://github.com/anduin2017/hsharp
Last synced: about 1 year ago
JSON representation
HSharp is a library used to analyse markup language like HTML easily and fastly.
- Host: GitHub
- URL: https://github.com/anduin2017/hsharp
- Owner: Anduin2017
- License: other
- Created: 2017-03-20T17:19:46.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2025-03-18T07:02:25.000Z (about 1 year ago)
- Last Synced: 2025-04-01T23:35:53.052Z (about 1 year ago)
- Language: HTML
- Homepage:
- Size: 159 KB
- Stars: 66
- Watchers: 8
- Forks: 20
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# HSharp
[](https://gitlab.aiursoft.cn/anduin/hsharp/-/blob/master/LICENSE)
[](https://gitlab.aiursoft.cn/anduin/hsharp/-/pipelines)
[](https://gitlab.aiursoft.cn/anduin/hsharp/-/pipelines)
[](https://www.nuget.org/packages/Anduin.HSharp/)
[](https://gitlab.aiursoft.cn/anduin/hsharp/-/commits/master?ref_type=heads)
HSharp is a library used to analyze markup language like HTML easily.
## Only Two Functions
* Deserialize and analyze HTML
* Build HTML using C#
## How to install
### Using Nuget
To install Anduin.HSharp, run the following command in the [Package Manager Console](https://docs.nuget.org/docs/start-here/using-the-package-manager-console)
```bash
PM> Install-Package Anduin.HSharp
```
### Using .NET CLI tool
To install Anduin.HSharp, run the following command in any console:
```bash
dotnet add package Anduin.HSharp
```
## Examples
### Deserialize HTML
Input some HTML and get the DOM of it.
```csharp
string exampleHtml = $@"
Example
Some Text
OneLine
TwoLine
ThreeLine
Other Text
";
var doc = HtmlConvert.DeserializeHtml(exampleHtml);
Console.WriteLine(doc["html"]["head"]["meta",0].Properties["charset"]);
Console.WriteLine(doc["html"]["head"]["meta",1].Properties["name"]);
foreach (var line in doc["html"]["body"]["table"])
{
Console.WriteLine(line.Son);
}
```
Output:
```html
utf-8
viewport
OneLine
TwoLine
ThreeLine
```
### Build HTML
Create a simple HDoc and add some children to its body.
````CSharp
var document = new HDoc(DocumentOptions.BasicHTML);
document["html"]["body"].AddChild("div");
document["html"]["body"]["div"].AddChild("a", new HProp("href", "/#"));
var result = document.GenerateHTML();
````
Output:
````html
Example
````
HSharp **can** also operate other Markup languages like XML and XAML