Skip to content

Commit 03c326a

Browse files
authored
Update build to use Pandoc 2.7.3 (#4795)
* Update build to use Pandoc 2.7.3 * fix tempdir value * rename script file * Turning off the progress display
1 parent c841f61 commit 03c326a

File tree

2 files changed

+155
-7
lines changed

2 files changed

+155
-7
lines changed

build.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ $global:ProgressPreference = 'SilentlyContinue'
88
if ($ShowProgress) { $ProgressPreference = 'Continue' }
99

1010
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
11+
$tempDir = [System.IO.Path]::GetTempPath()
1112

1213
# Pandoc source URL
13-
$panDocVersion = "2.0.6"
14-
$pandocSourceURL = "https://github.com/jgm/pandoc/releases/download/$panDocVersion/pandoc-$panDocVersion-windows.zip"
14+
$panDocVersion = "2.7.3"
15+
$pandocSourceURL = "https://github.com/jgm/pandoc/releases/download/$panDocVersion/pandoc-$panDocVersion-windows-x86_64.zip"
1516

16-
$pandocDestinationPath = New-Item (Join-Path ([System.IO.Path]::GetTempPath()) "PanDoc") -ItemType Directory -Force
17-
$pandocZipPath = Join-Path $pandocDestinationPath "pandoc-$panDocVersion-windows.zip"
17+
$pandocDestinationPath = New-Item (Join-Path $tempDir "pandoc") -ItemType Directory -Force
18+
$pandocZipPath = Join-Path $pandocDestinationPath "pandoc-$panDocVersion-windows-x86_64.zip"
1819
Invoke-WebRequest -Uri $pandocSourceURL -OutFile $pandocZipPath
1920

20-
Expand-Archive -Path (Join-Path $pandocDestinationPath "pandoc-$panDocVersion-windows.zip") -DestinationPath $pandocDestinationPath -Force
21-
$pandocExePath = Join-Path (Join-Path $pandocDestinationPath "pandoc-$panDocVersion") "pandoc.exe"
21+
Expand-Archive -Path $pandocZipPath -DestinationPath $pandocDestinationPath -Force
22+
$pandocExePath = Join-Path (Join-Path $pandocDestinationPath "pandoc-$panDocVersion-windows-x86_64") "pandoc.exe"
2223

2324
# Install ThreadJob if not available
2425
$threadJob = Get-Module ThreadJob -ListAvailable
@@ -112,7 +113,7 @@ Get-ChildItem $ReferenceDocset -Directory -Exclude $excludeList | ForEach-Object
112113

113114
$pandocArgs = @(
114115
"--from=gfm",
115-
"--to=plain+multiline_tables+inline_code_attributes",
116+
"--to=plain+multiline_tables",
116117
"--columns=75",
117118
"--output=$aboutFileOutputFullName",
118119
"--quiet"

tools/build-updatedhelp.ps1

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<#
2+
Usage:
3+
4+
1. Clone the docs respository
5+
cd C:\temp
6+
git clone https://github.com/MicrosoftDocs/PowerShell-Docs.git
7+
8+
2. Run build-updatedhelp.ps1 for the version folder you want to build
9+
10+
.\build-updatedhelp.ps1 -sourceFolder C:\temp\PowerShell-Docs\reference\5.1 -Verbose
11+
12+
3. Run Update-Help to install the newly built help
13+
14+
Update-Help -SourcePath c:\temp\updatablehelp\5.1 -Recurse -Force
15+
#>
16+
17+
18+
param(
19+
[Parameter(Mandatory=$true)]
20+
[ValidateScript({ Test-Path $_ })]
21+
[string]$sourceFolder
22+
)
23+
24+
# Turning off the progress display, by default
25+
$savedProgressPreference = $global:ProgressPreference
26+
$global:ProgressPreference = 'SilentlyContinue'
27+
28+
$tempDir = [System.IO.Path]::GetTempPath()
29+
30+
# Pandoc source URL
31+
$panDocVersion = "2.7.3"
32+
$pandocSourceURL = "https://github.com/jgm/pandoc/releases/download/$panDocVersion/pandoc-$panDocVersion-windows-x86_64.zip"
33+
34+
$docToolsPath = New-Item (Join-Path $tempDir "doctools") -ItemType Directory -Force
35+
$pandocZipPath = Join-Path $docToolsPath "pandoc-$panDocVersion-windows-x86_64.zip"
36+
Write-Verbose "Downloading Pandoc..."
37+
Invoke-WebRequest -Uri $pandocSourceURL -OutFile $pandocZipPath
38+
39+
Expand-Archive -Path $pandocZipPath -DestinationPath $docToolsPath -Force
40+
$pandocExePath = Join-Path $docToolsPath "pandoc-$panDocVersion-windows-x86_64\pandoc.exe"
41+
42+
$platyPSversion = "0.14.0"
43+
Write-Verbose "Downloading platyPS..."
44+
Save-Module -Name platyPS -Repository PSGallery -Force -Path $docToolsPath -RequiredVersion $platyPSversion
45+
Import-Module -FullyQualifiedName $docToolsPath\platyPS\$platyPSversion\platyPS.psd1
46+
47+
$DocSet = Get-Item $sourceFolder
48+
$WorkingDirectory = $PWD
49+
50+
function Get-ContentWithoutHeader {
51+
param(
52+
$path
53+
)
54+
55+
$doc = Get-Content $path -Encoding UTF8
56+
$start = $end = -1
57+
58+
# search the first 30 lines for the Yaml header
59+
# no yaml header in our docset will ever be that long
60+
61+
for ($x = 0; $x -lt 30; $x++) {
62+
if ($doc[$x] -eq '---') {
63+
if ($start -eq -1) {
64+
$start = $x
65+
}
66+
else {
67+
if ($end -eq -1) {
68+
$end = $x + 1
69+
break
70+
}
71+
}
72+
}
73+
}
74+
if ($end -gt $start) {
75+
Write-Output ($doc[$end..$($doc.count)] -join ([Environment]::Newline))
76+
}
77+
else {
78+
Write-Output ($doc -join "`r`n")
79+
}
80+
}
81+
82+
$Version = $DocSet.Name
83+
Write-Verbose "Version = $Version"
84+
85+
$VersionFolder = $DocSet.FullName
86+
Write-Verbose "VersionFolder = $VersionFolder"
87+
88+
# For each of the directories, go through each module folder
89+
Get-ChildItem $VersionFolder -Directory | ForEach-Object -Process {
90+
$ModuleName = $_.Name
91+
Write-Verbose "ModuleName = $ModuleName"
92+
93+
$ModulePath = Join-Path $VersionFolder $ModuleName
94+
Write-Verbose "ModulePath = $ModulePath"
95+
96+
$LandingPage = Join-Path $ModulePath "$ModuleName.md"
97+
Write-Verbose "LandingPage = $LandingPage"
98+
99+
$MamlOutputFolder = Join-Path "$WorkingDirectory\maml" "$Version\$ModuleName"
100+
Write-Verbose "MamlOutputFolder = $MamlOutputFolder"
101+
102+
$CabOutputFolder = Join-Path "$WorkingDirectory\updatablehelp" "$Version\$ModuleName"
103+
Write-Verbose "CabOutputFolder = $CabOutputFolder"
104+
105+
if (-not (Test-Path $MamlOutputFolder)) {
106+
New-Item $MamlOutputFolder -ItemType Directory -Force > $null
107+
}
108+
109+
# Process the about topics if any
110+
$AboutFolder = Join-Path $ModulePath "About"
111+
112+
if (Test-Path $AboutFolder) {
113+
Write-Verbose "AboutFolder = $AboutFolder"
114+
Get-ChildItem "$aboutfolder/about_*.md" | ForEach-Object {
115+
$aboutFileFullName = $_.FullName
116+
$aboutFileOutputName = "$($_.BaseName).help.txt"
117+
$aboutFileOutputFullName = Join-Path $MamlOutputFolder $aboutFileOutputName
118+
119+
$pandocArgs = @(
120+
"--from=gfm",
121+
"--to=plain+multiline_tables",
122+
"--columns=75",
123+
"--output=$aboutFileOutputFullName",
124+
"--quiet"
125+
)
126+
127+
Get-ContentWithoutHeader $aboutFileFullName | & $pandocExePath $pandocArgs
128+
}
129+
}
130+
131+
try {
132+
# For each module, create a single maml help file
133+
# Adding warningaction=stop to throw errors for all warnings, erroraction=stop to make them terminating errors
134+
New-ExternalHelp -Path $ModulePath -OutputPath $MamlOutputFolder -Force -WarningAction Stop -ErrorAction Stop
135+
136+
# For each module, create update-help help files (cab and helpinfo.xml files)
137+
$cabInfo = New-ExternalHelpCab -CabFilesFolder $MamlOutputFolder -LandingPagePath $LandingPage -OutputFolder $CabOutputFolder
138+
139+
# Only output the cab fileinfo object
140+
if ($cabInfo.Count -eq 8) { $cabInfo[-1].FullName }
141+
}
142+
catch {
143+
Write-Error -Message "PlatyPS failure: $ModuleName -- $Version" -Exception $_
144+
}
145+
}
146+
147+
$global:ProgressPreference = $savedProgressPreference

0 commit comments

Comments
 (0)