You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

FSharp.HTML

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

FSharp.HTML

a parse for HTML5 based on the official W3C specification.

1.0.17
Source
nugetNuGet
Version published
Maintainers
1
Created
Source

FSharp.HTML

A parse for HTML5 based on the official W3C specification.

Usage

the html source text is:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My test page</title>
  </head>
  <body>
    <img src="images/firefox-icon.png" alt="My test image">
  </body>
</html>

we can use this code to parse html source to HtmlNode list:

let sourceText = ...
let doctype,nodes = HtmlUtils.parseDoc sourceText

doctype is a string that is extracted from doctype tag. and nodes is a HtmlNode list.

All parsing processes in a package are public, and you are free to compose them to implement your functional requirements. Parser is highly configurable, see source code HtmlUtils

Parse only html structures without changing the content. Please use HtmldocCompiler.compile. In fact, the HtmlUtils.parseDoc is defined as follows:

let parseDoc (txt:string) = 
    let doctype,nodes =
        txt
        |> HtmldocCompiler.compile
    let nodes =
        nodes
        |> List.map Whitespace.removeWS
        |> Whitespace.trimWhitespace
        |> List.map HtmlCharRefs.unescapseNode
    doctype,nodes

Knowing the above code, you can determine the parsing result as your needs.

generate html source text:

Render.stringifyNode
Render.stringifyDoc

HtmlUtils.stringifyNode
HtmlUtils.stringifyDoc

some transform:

BrRemover.splitByBr
HrRemover.splitByHr

API

The user can parse the string through the functions in the HtmlUtils module.

HtmlUtils

You can also use a tokenizer to get a token sequence.

let tokens = HtmlTokenizer.tokenize txt 

The main structure types are defined as follows:

  • The type HtmlNode see to HtmlNode.

  • The type HtmlToken see to HtmlToken.

Keywords

html

FAQs

Package last updated on 09 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts