Skip to content

Commit f846915

Browse files
committed
Clean_WikiContent_For_GitHub_Publish: Fix parsing top level header
1 parent 02e340b commit f846915

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
defaults to `$true`.
2323
- `Clean_WikiContent_For_GitHub_Publish` - This task will remove the top
2424
level header from any markdown file where the top level header equals the
25-
filename (converting Unicode hyphen to ASCII hyphen before comparison).
26-
It can be controlled by parameter `RemoveTopLevelHeader` in the task, which
27-
defaults to `$true`.
25+
filename. The task will convert standard hyphens to spaces and Unicode
26+
hyphens to standard hyphens before comparison. The task can be controlled
27+
by parameter `RemoveTopLevelHeader` in the task, which defaults to `$true`.
2828

2929
### Changed
3030

source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1

+3-2
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ Task Clean_WikiContent_For_GitHub_Publish {
113113

114114
$hasTopHeader = $content -match '(?m)^#\s+([^\r\n]+)'
115115

116-
$baseNameWithoutNonBreakingHyphen = $_.BaseName -replace [System.Char]::ConvertFromUtf32(0x2011), '-'
116+
$convertedBaseName = $_.BaseName -replace '-', ' '
117+
$convertedBaseName = $convertedBaseName -replace [System.Char]::ConvertFromUtf32(0x2011), '-'
117118

118-
if ($hasTopHeader -and $Matches[1] -eq $baseNameWithoutNonBreakingHyphen)
119+
if ($hasTopHeader -and $Matches[1] -eq $convertedBaseName)
119120
{
120121
Write-Build -Color DarkGray -Text ('Top level header is the same as the filename. Removing top level header from: {0}' -f $_.Name)
121122

tests/unit/tasks/Clean_WikiContent_For_GitHub_Publish.Tests.ps1

+15-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,18 @@ Describe 'Clean_WikiContent_For_GitHub_Publish' {
3535

3636
New-Item -Path "$($TestDrive.FullName)/WikiContent" -ItemType 'Directory' -Force | Out-Null
3737

38-
Set-Content -Path "$($TestDrive.FullName)/WikiContent/Get-Something.md" -Value 'Mock markdown file 1'
38+
# Will not be modified
39+
Set-Content -Path "$($TestDrive.FullName)/WikiContent/Get-Something.md" -Value '# Get-Something`nMock markdown file 1'
3940

40-
Set-Content -Path "$($TestDrive.FullName)/WikiContent/home.md" -Value 'Mock markdown file 1'
41+
# Will be modified
42+
Set-Content -Path "$($TestDrive.FullName)/WikiContent/Credential-overview.md" -Value "# Credential overview`nMock markdown file 3"
43+
44+
# Will not be modified
45+
Set-Content -Path "$($TestDrive.FullName)/WikiContent/Home.md" -Value "# My Module Name`nMock markdown file 4"
46+
47+
Mock -CommandName Set-Content -MockWith {
48+
Write-Verbose -Message ('Setting content of: {0}' -f $Path) -Verbose
49+
}
4150
}
4251

4352
It 'Should export the build script alias' {
@@ -67,5 +76,9 @@ Describe 'Clean_WikiContent_For_GitHub_Publish' {
6776

6877
Invoke-Build -Task $buildTaskName -File $script:buildScript.Definition @taskParameters
6978
} | Should -Not -Throw
79+
80+
Assert-MockCalled -CommandName Set-Content -ParameterFilter {
81+
$Path -eq "$($TestDrive.FullName)/WikiContent/Credential-overview.md"
82+
} -Exactly -Times 1 -Scope It
7083
}
7184
}

0 commit comments

Comments
 (0)