简体   繁体   English

在Powershell中从txt正确导出到html

[英]Proper export from txt to html in Powershell

I have a script, which stores output in txt and I need to convert this output into html. 我有一个脚本,该脚本将输出存储在txt中,我需要将此输出转换为html。

The format of txt file is following: txt文件的格式如下:

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: 要将文本发送到html中,请使用以下代码:

$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? 如何重做脚本,以接收确切的输出以及换行符,如txt文件中所示?

I know that ConvertTo-Html is cool, but if I want more control over generated HTML I do it manually: 我知道ConvertTo-Html很酷,但是如果我想对生成的HTML进行更多控制,可以手动执行:

$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. HTML中的pre标签用于保留预格式化的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM