Skip to content

Commit 10f93b3

Browse files
authored
Clean_WikiContent_For_GitHub_Publish: Fix parsing top level header (#164)
1 parent 02e340b commit 10f93b3

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-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

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ 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"
4146
}
4247

4348
It 'Should export the build script alias' {

0 commit comments

Comments
 (0)