Repository navigation
Submitting ConvertFrom-Html RFC - #137
Conversation
| Method = 'Post' | ||
| } | ||
|
|
||
| $dnsDumpsterObject = (Invoke-WebRequest @props).Content | ConvertFrom-Html |
There was a problem hiding this comment.
Acturally, this will work:
$dnsDumpsterObject = Invoke-WebRequest @props | ConvertFrom-HtmlParamater binding will convert BasicHtmlWebResponseObject to a string which will be the contents of Content.
There was a problem hiding this comment.
Mark Kraus (@markekraus) Thanks for this, and this makes sense. I'll update the RFC.
|
|
||
| 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. |
There was a problem hiding this comment.
Hmm RawContent? Would that be supported by AngelSharp?
There was a problem hiding this comment.
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.
|
What happens when more than one string is piped to the command? $Html1, $Html2 | ConvertFrom-HtmlWill parity be ensured such that @([pscustomobject]@{a=1},[pscustomobject]@{a=2}) | ConvertTo-Html | ConvertFrom-Htmlworks 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. |
There was a problem hiding this comment.
We could add "The state of affairs" sub-title.
| RelationLink Property System.Collections.Generic.Dictionary[string,string] RelationLink {get;} | ||
| StatusCode Property int StatusCode {get;} | ||
| StatusDescription Property string StatusDescription {get;} | ||
| ``` |
There was a problem hiding this comment.
This is distracting. I think we should remove the block.
There was a problem hiding this comment.
I will remove this. Thanks!
| 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. |
There was a problem hiding this comment.
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" ...
There was a problem hiding this comment.
Based on the RFC guidelines, i'm not sure if this is needed.
| #### 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). | ||
|
|
There was a problem hiding this comment.
I believe we can remove this - we haven't requiriments for them in the RFC.
There was a problem hiding this comment.
I will remove this.
|
|
||
| ## Specification | ||
|
|
||
| The proposal is to create a new 'ConvertFrom-Html' cmdlet that will convert Html content using PowerShell core. |
There was a problem hiding this comment.
Proposal was already above.
| ### OUTPUTS | ||
|
|
||
| #### PSCustomObject | ||
|
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I would prefer to see something closer to the HTML standard like that was in .ParsedHtml and .AllElements.
Mark Kraus (@markekraus) Thoughts?
There was a problem hiding this comment.
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-Htmland
$obj | ConvertTo-Html | ConvertFrom-Htmlin 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes. That would satisfy the issue. So long as users can convert back and forth reliably.
| 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 |
There was a problem hiding this comment.
The first alternative about which we remember is .Net Core - here we should mention why we don't use it.
|
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 |
|
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. |
|
If there are no other major concerns and we are past the feedback deadline, I can have @PowerShell/powershell-committee review this |
|
Any news? Or not making it into 7 either? |
|
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? 🙏 |
|
Sorry, how is this essential as a replacement for PS 5? PS 5 never had a |
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. |
|
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 |
|
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. |
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 :-) ) |
|
Any progress on this? |
|
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. |
|
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. |
|
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. |
This should work OTB, we live in HTML world. There is no good rationale for rejecting this. |
Submitting ConvertFrom-Html RFC for consideration.