Reputation: 1623
I have a script, which stores output in txt and I need to convert this output into html.
The format of txt file is following:
This file is generated for commits from: 2018-07-15 to: 2018-07-21 for branch: repositories contains: mineq
=============somerepo=============
Branch is development
1234567 Merge pull request #1227 from qp-10421_service_version_information
1234567 Merge branch 'development' into qp-10421_service_version_information
1234567 merged with development
1234567 QP-2071: update packages
=============Someotherrepo=============
Branch is development
=============MineqConfigApi=============
Branch is development
1234567 QP-10881 Remove WindowsVpnSettings service
1234567 Merge pull request #9 from quarti/QP-10881
1234567 QP-10881 Set SshClient ConnectionTimeout 10 minutes and Change sql query to skip Deleted Assets
To send this text into html, I use following code:
$SourceFile = "$env:WORKSPACE\commits.txt"
$TargetFile = "$env:WORKSPACE\commits.html"
$TextData = Get-Content $SourceFile
$LineData = $TextData -join ''
New-Object psobject -Property @{Text = $LineData} | ConvertTo-HTML | Out-File $TargetFile
But the output is following -
How to rework script, to receive exact output, with linebreaks, as in txt file?
Upvotes: 0
Views: 5488
Reputation: 9143
I know that ConvertTo-Html is cool, but if I want more control over generated HTML I do it manually:
$content = cat File.txt -Raw
$title = 'My HTML'
$html = @"
<html>
<head><title>$title</title></head>
<body>
<pre>$content</pre>
</body>
</html>
"@
$html | Out-File 'file.html'
pre
tag is used in HTML to preserves preformatted element.
Upvotes: 4