FSharp.Data icon indicating copy to clipboard operation
FSharp.Data copied to clipboard

Make HtmlAttribute and HtmlNode accessible

Open nojaf opened this issue 6 years ago • 2 comments

I'm trying to create script that parse some html to another format.

#r "./packages/FSharp.Data/lib/net45/FSharp.Data.dll"

open FSharp.Data
open System

let input = "<h1>Test <strong>one</strong> two</h1><ul><li>one</li><li>two</li><li>three</li>"

let html = HtmlNode.Parse input

let processHtmlNode (node:HtmlNode) =
    match node with
    | HtmlElement(name, attributes, elements) ->
        sprintf "%s [%s] []" name attrs
    | HtmlText content ->
        sprintf "str \"%s\"" content
    | HtmlComment content -> 
        sprintf "comment  \"%s\"" content
    | HtmlCData content ->
        "CData is deprecated in HTML5"

List.head html
|> processHtmlNode

Running this in the repl gives me an error that html.fsx(13,7): error FS1093: The union cases or fields of the type 'HtmlNode' are not accessible from this code location.

I believe this is due to the internal keyword on line 17 and line 31.

Would it be ok if I sent in a PR to remove the internal keyword there? Or do I have other options here?

nojaf avatar Nov 13 '17 14:11 nojaf

Its' internal by design, so if we change the internal representation it's not a breaking change (we had that problem before with JsonValue). Though I guess we could expose an active pattern

ovatsus avatar Dec 03 '17 18:12 ovatsus

@ovatsus I also have a use case for this, where I need to inspect the type of HtmlNode that I'm on.

I made a PR per your comment. Is that what you had in mind?

NatElkins avatar Nov 06 '18 22:11 NatElkins