Skip to content

Submitting ConvertFrom-Html RFC - #137

Merged
Joey Aiello (joeyaiello) merged 9 commits into
PowerShell:masterfrom
MSAdministrator:master
Mar 10, 2020
Merged

Joey Aiello (joeyaiello) merged 9 commits into
PowerShell:masterfrom
MSAdministrator:master

Conversation

@MSAdministrator

Copy link
Copy Markdown
Contributor

Submitting ConvertFrom-Html RFC for consideration.

Comment thread 1-Draft/RFCNNNN-ConvertFrom-Html.md Outdated
Method = 'Post'
}

$dnsDumpsterObject = (Invoke-WebRequest @props).Content | ConvertFrom-Html

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acturally, this will work:

$dnsDumpsterObject = Invoke-WebRequest @props | ConvertFrom-Html

Paramater binding will convert BasicHtmlWebResponseObject to a string which will be the contents of Content.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark Kraus (@markekraus) Thanks for this, and this makes sense. I'll update the RFC.

Comment thread 1-Draft/RFCNNNN-ConvertFrom-Html.md Outdated

As a PowerShell Core user, I can convert HTML content to objects so that I can easily work with downloaded or local HTML content.

As a IT Administrator, I can call `Invoke-WebRequest` and then use `ConvertFrom-Html` to convert the `RawContent` of my Web Request to an object so that I can easily work with HTML strings/content.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm RawContent? Would that be supported by AngelSharp?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually meant Content in this one. Originally I thought RawContent should be supported but after further looking I think it should support Content instead.

@markekraus

Copy link
Copy Markdown

What happens when more than one string is piped to the command?

$Html1, $Html2 | ConvertFrom-Html

Will parity be ensured such that

@([pscustomobject]@{a=1},[pscustomobject]@{a=2}) | ConvertTo-Html | ConvertFrom-Html

works as expected?


# ConvertFrom-Html

Currently the PowerShell Core Web CmdLets do not have access to the `HtmlWebResponseObject` and currently only contains the `BasicHtmlWebResponseObject` type. Because of this, the capability to parse HTML using the `ParsedHtml` property of the `HtmlWebResponseObject` type does not exist within PowerShell Core.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add "The state of affairs" sub-title.

Comment thread 1-Draft/RFCNNNN-ConvertFrom-Html.md Outdated
RelationLink Property System.Collections.Generic.Dictionary[string,string] RelationLink {get;}
StatusCode Property int StatusCode {get;}
StatusDescription Property string StatusDescription {get;}
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is distracting. I think we should remove the block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove this. Thanks!

Comment thread 1-Draft/RFCNNNN-ConvertFrom-Html.md Outdated
StatusDescription Property string StatusDescription {get;}
```

This RFC proposes that the creation of a new CmdLet named `ConvertFrom-Html`. This CmdLet is to be implemented into PowerShell Core and should utilize the [AngelSharp](https://github.com/AngleSharp/AngleSharp) framework for converting strings into a PSCustomObject.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add sub-title "Proposition".

"for converting strings into ..." -> "for converting HTML strings into ...".

Here and below - what is output object type or types? We mention - "objects", "PSCustomObject" ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the RFC guidelines, i'm not sure if this is needed.

Comment thread 1-Draft/RFCNNNN-ConvertFrom-Html.md Outdated
#### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can remove this - we haven't requiriments for them in the RFC.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove this.

Comment thread 1-Draft/RFCNNNN-ConvertFrom-Html.md Outdated

## Specification

The proposal is to create a new 'ConvertFrom-Html' cmdlet that will convert Html content using PowerShell core.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposal was already above.

### OUTPUTS

#### PSCustomObject

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What inputs and outputs we expect? Only strings and PSCustomObject ? I think it's useful to think about it now.

Can output be XML? Dom?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that ConvertFrom-Html would output PSCustomObject. If we want to covert it after that, we can use ConvertTo CmdLets to the appropriate types.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to see something closer to the HTML standard like that was in .ParsedHtml and .AllElements.
Mark Kraus (@markekraus) Thoughts?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the proposed cmdlet is ConvertFrom-Html and there is already a ConvertTo-Html the highest priority for the cmdlet is that it maintain parity with the existing cmdlet. Lack of conversion parity in converter cmdlets is something that constantly causes pain and frustration in the community. Whatever object is output by the new cmdlet, it needs to support

$html | ConvertFrom-Html | ConvertTo-Html

and

$obj | ConvertTo-Html | ConvertFrom-Html

in a manner that is expected by the user.

That object could contain methods and such which allow access to an object like 5.1's ParesdHtml.

An alternative is to use a different cmdlet name that way it is not associated with ConvertTo-Html. This could allow for returning a feature-rich object directly from AngleSharp. I'm starting to think this is the better idea. I'm not a huge fan of how the current ConvertTo-Html works and I'm no a fan of how limited ConvertFrom-Html would need to be as a result of how ConvertTo-Html works.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this just output a AngleSharp.Dom.Html.HtmlDocument object? ConvertTo-Html can be modified to accept this type and serialize back to html.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That would satisfy the issue. So long as users can convert back and forth reliably.

Comment thread 1-Draft/RFCNNNN-ConvertFrom-Html.md Outdated
Some considerations to keep in mind:

- Converted Html may be piped to any number of CmdLets. For example, ConverTo-Json, ConverTo-Csv, ConvertTo-Xml, and ConvertTo-Html
- Based on conversations in #3267 and #2867, this CmdLet should use AngleSharp to parse Html

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first alternative about which we remember is .Net Core - here we should mention why we don't use it.

@MSAdministrator

Copy link
Copy Markdown
Contributor Author

Mark Kraus (@markekraus) Regarding your post above (I cannot seem to reply to it) but I think that each HTML String should be passed along independently through the pipeline. This would work similarly to how ConvertFrom-Json works now (i believe).

@bviktor

bviktor commented Aug 28, 2018

Copy link
Copy Markdown

Ah, this looks like a must have one, subscribing :)


Additionally, Windows PowerShell Web CmdLets utilize Internet Explorer to parse HTML content. Since non-Windows systems do not have Internet Explorer, PowerShell Core utilizes the `BasicHtmlWebResponseObject` which does not contain this property.

This RFC proposes that the creation of a new CmdLet named `ConvertFrom-Html`. This CmdLet is to be implemented into PowerShell Core and should utilize the [AngelSharp](https://github.com/AngleSharp/AngleSharp) framework for converting HTML strings into a PSCustomObject.

@bviktor bviktor Aug 28, 2018 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Angle vs Angel :)

@SteveL-MSFT

Copy link
Copy Markdown
Member

If there are no other major concerns and we are past the feedback deadline, I can have @PowerShell/powershell-committee review this

@bviktor

bviktor commented Jun 3, 2019

Copy link
Copy Markdown

Any news? Or not making it into 7 either?

@fgimian

Copy link
Copy Markdown

This functionality would be quite essential if PowerShell 7 is to be a true replacement for Windows PowerShell 5. Any chance this can be moved forward and included as part of the v7 release? 🙏

@vexx32

Copy link
Copy Markdown
Contributor

Sorry, how is this essential as a replacement for PS 5? PS 5 never had a ConvertFrom-Html cmdlet. 😕

@fgimian

Copy link
Copy Markdown

Sorry, how is this essential as a replacement for PS 5? PS 5 never had a ConvertFrom-Html cmdlet. 😕

Because Invoke-WebRequest in PowerShell 5 provided full capabilities for manipulating the returned HTML due to the fact it was using the IE engine. PowerShell Core does not and returns only a basic HTTP response.

Some more info can be found here.

@joeyaiello

Copy link
Copy Markdown
Contributor

This inspired a meta-conversation with James Truher (@JamesWTruher) and Steve Lee (@SteveL-MSFT) about when and how we decide to take modules into PowerShell itself. At face value, this seems like the right approach, but we'd really prefer to see an implementation of this on the Gallery first so we can get some community usage that drives the quality and gives us an impression of how useful/popular this would be inbox. (See this comment on an AccountManagement module for similar reasoning.)

I recognize that this is to replace Windows PS 5 behavior in Invoke-WebRequest, and we're not dismissing the idea of shipping this in 7, but it's probably unlikely given the velocity we've been working at. But a working implementation would make it a lot more likely. 😄

@fgimian

Fotis Gimian (fgimian) commented Jul 9, 2019 •

Copy link
Copy Markdown

Thanks so much Joey Aiello (@joeyaiello), totally respect that. In case it helps, I've been using PowerHTML to perform this function and it works flawlessly.

@iSazonov

Copy link
Copy Markdown
Contributor

we'd really prefer to see an implementation of this on the Gallery first so we can get some community usage

This again demonstrates the benefits of corefxlab model. MSFT team could create PowerShellLab repo (with prepared infrastructure to automatically publish nugets) and collect some new and experimental modules there. (I am ready to maintain it too :-) )

@akhilthomas011

Copy link
Copy Markdown

Any progress on this?

@joeyaiello

Copy link
Copy Markdown
Contributor

Given the relatively low number of downloads of PowerHTML, as well as the requirement of adding HtmlAgilityPack (or some equivalent), increasing both size and surface area of potential vulnerabilities, we feel that this is best served by the Gallery today.

In general, we're also raising the bar in terms of what we feel comfortable bringing into the PowerShell release. Module experimentation can and should continue in the Gallery.

@joeyaiello

Copy link
Copy Markdown
Contributor

Rejecting due to existing community implementation of PowerHTML and rationale above.

If there is significantly more demand for this cmdlet in the future, an issue should be opened in PowerShell/PowerShell to discuss inclusion in the PowerShell release itself.

@joeyaiello
Joey Aiello (joeyaiello) merged commit 26ca1f2 into PowerShell:master Mar 10, 2020
@iSazonov

Copy link
Copy Markdown
Contributor

Steve Lee (@SteveL-MSFT) mentioned that MSFT team is going to work on coloring in next milestone. In the case we need a color rendering. We already have simple rendering for MarkDown and we could consider to have more power rendering engine to support coloring and HTML look very attractive as color rendering language.

@majkinetor

Copy link
Copy Markdown

Rejecting due to existing community implementation of PowerHTML and rationale above.

This should work OTB, we live in HTML world. There is no good rationale for rejecting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.