An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# HSharp

[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://gitlab.aiursoft.cn/anduin/hsharp/-/blob/master/LICENSE)
[![Pipeline stat](https://gitlab.aiursoft.cn/anduin/hsharp/badges/master/pipeline.svg)](https://gitlab.aiursoft.cn/anduin/hsharp/-/pipelines)
[![Test Coverage](https://gitlab.aiursoft.cn/anduin/hsharp/badges/master/coverage.svg)](https://gitlab.aiursoft.cn/anduin/hsharp/-/pipelines)
[![NuGet version)](https://img.shields.io/nuget/v/Anduin.HSharp.svg)](https://www.nuget.org/packages/Anduin.HSharp/)
[![ManHours](https://manhours.aiursoft.cn/r/gitlab.aiursoft.cn/anduin/hsharp.svg)](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