簡體   English   中英

在Powershell中從txt正確導出到html

[英]Proper export from txt to html in Powershell

我有一個腳本,該腳本將輸出存儲在txt中,我需要將此輸出轉換為html。

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

要將文本發送到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

但是輸出如下-

如何重做腳本,以接收確切的輸出以及換行符,如txt文件中所示?

我知道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'

HTML中的pre標簽用於保留預格式化的元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM