PSWriteHTML icon indicating copy to clipboard operation
PSWriteHTML copied to clipboard

Option for HTML Fragment generation?

Open RobCannon opened this issue 4 years ago • 1 comments

Is there an option to generate HTML as a fragment that can be inserted into another HTML document? The scenario I am trying to solve is generation of HTML content to go into a Confluence page, so I need HTML that is just a fragment and doesn't include the tags and could probably all be contained within a

tag.

I didn't see an option on New-Html for that kind of generation. I looked for a New-Html* function that might server as a parent, but I didn't see anything. I tried using New-HtmlContainer as the root object and it does generate some HTML, but it also throws some errors.

Does this capability exist?

InvalidOperation: C:\Users\rob\src\GitHub\PSWriteHTML\Public\New-HTMLContainer.ps1:10:5 Line | 10 | $Script:HTMLSchema.Features.MainFlex = $true | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | The property 'MainFlex' cannot be found on this object. Verify that the property exists and can be set.

InvalidOperation: C:\Users\rob\src\GitHub\PSWriteHTML\Public\New-HTMLContainer.ps1:23:9 Line | 23 | $Script:HTMLSchema.CustomHeaderCSS[$AnchorName] = $Css | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Cannot index into a null array.

InvalidOperation: C:\Users\rob\src\GitHub\PSWriteHTML\Public\New-HTMLHeading.ps1:9:5 Line | 9 | $Script:HTMLSchema.Features.DefaultHeadings = $true | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | The property 'DefaultHeadings' cannot be found on this object. Verify that the property exists and can be set.

RobCannon avatar Apr 04 '21 16:04 RobCannon

It's more complicated. What you're seeing in the errors is tracking which libraries are used (aka JavaScript / CSS code) and are required for functionality to function. This means while it probably could be done to skip generating Header/Footer and just give you the body it would miss a large portion of code required for PSWriteHTML to give you what you need.

I guess confluence doesn't like the top-level tags right?

<!-- saved from url=(0014)about:internet -->
 <!DOCTYPE html>
 <html><head>

What happens if you remove those top tags, and remove /HTML /head closing ones as well? For this to work we would need to figure out what makes confluence and other similar use cases freak out - and how to figure it out.

I can see the need and usefulness for this - just not sure how to address it.

Also keep in mind that there could be library conflicts - for example, if confluence uses JQuery and I attach Jquery in my HTML it will conflict.

PrzemyslawKlys avatar Apr 04 '21 16:04 PrzemyslawKlys