diff --git a/Examples/Example-TableWithTags/Example-TableWithTags.ps1 b/Examples/Example-TableWithTags/Example-TableWithTags.ps1 new file mode 100644 index 00000000..8569d1ee --- /dev/null +++ b/Examples/Example-TableWithTags/Example-TableWithTags.ps1 @@ -0,0 +1,12 @@ +Import-Module .\PSWriteHTML.psd1 -Force + +$test = "" +New-HTML { + New-HTMLTableOption -DataStore JavaScript -BoolAsString -ArrayJoinString '
' -ArrayJoin + + New-HTMLTab -Name 'Forest' { + New-HTMLSection -HeaderText 'Summary' { + New-HTMLTable -DataTable $test + } + } +} -ShowHTML -FilePath "$PSScriptRoot\Example-TableWithTags.html" -Online diff --git a/Public/New-HTMLTable.ps1 b/Public/New-HTMLTable.ps1 index ec64681f..84dce713 100644 --- a/Public/New-HTMLTable.ps1 +++ b/Public/New-HTMLTable.ps1 @@ -1308,6 +1308,12 @@ ArrayJoinString = $Script:HTMLSchema['TableOptions']['DataStoreOptions'].ArrayJoinString } $DataToInsert = $Table | ConvertTo-PrettyObject @convertToPrettyObjectSplat | ConvertTo-Json + if (-not $InvokeHTMLTags) { + # If InvokeHTMLTags is not set, we need to escape HTML characters + # By default HTML tags are escaped when using DataStore HTML, but not when using JavaScript + # So we need to escape them here, so they don't break the JavaScript code + $DataToInsert = $DataToInsert -replace "<", "<" -replace ">" + } if ($DataToInsert.StartsWith('[')) { $Script:HTMLSchema.CustomFooterJS[$DataStoreID] = "var $DataStoreID = $DataToInsert;" } else { @@ -1328,6 +1334,12 @@ ArrayJoinString = $Script:HTMLSchema['TableOptions']['DataStoreOptions'].ArrayJoinString } $DataToInsert = $Table | ConvertTo-PrettyObject @convertToPrettyObjectSplat | ConvertTo-Json + if (-not $InvokeHTMLTags) { + # If InvokeHTMLTags is not set, we need to escape HTML characters + # By default HTML tags are escaped when using DataStore HTML, but not when using JavaScript + # So we need to escape them here, so they don't break the JavaScript code + $DataToInsert = $DataToInsert -replace "<", "<" -replace ">", ">" + } if ($DataToInsert.StartsWith('[')) { $Options = $Options.Replace('"markerForDataReplacement"', $DataToInsert) } else {