Skip to content

Commit

Permalink
Clean_WikiContent_For_GitHub_Publish: Fix parsing top level header
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Oct 26, 2024
1 parent 02e340b commit f846915
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
defaults to `$true`.
- `Clean_WikiContent_For_GitHub_Publish` - This task will remove the top
level header from any markdown file where the top level header equals the
filename (converting Unicode hyphen to ASCII hyphen before comparison).
It can be controlled by parameter `RemoveTopLevelHeader` in the task, which
defaults to `$true`.
filename. The task will convert standard hyphens to spaces and Unicode
hyphens to standard hyphens before comparison. The task can be controlled
by parameter `RemoveTopLevelHeader` in the task, which defaults to `$true`.

### Changed

Expand Down
5 changes: 3 additions & 2 deletions source/tasks/Clean_WikiContent_For_GitHub_Publish.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ Task Clean_WikiContent_For_GitHub_Publish {

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

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

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

Expand Down
17 changes: 15 additions & 2 deletions tests/unit/tasks/Clean_WikiContent_For_GitHub_Publish.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ Describe 'Clean_WikiContent_For_GitHub_Publish' {

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

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

Set-Content -Path "$($TestDrive.FullName)/WikiContent/home.md" -Value 'Mock markdown file 1'
# Will be modified
Set-Content -Path "$($TestDrive.FullName)/WikiContent/Credential-overview.md" -Value "# Credential overview`nMock markdown file 3"

# Will not be modified
Set-Content -Path "$($TestDrive.FullName)/WikiContent/Home.md" -Value "# My Module Name`nMock markdown file 4"

Mock -CommandName Set-Content -MockWith {
Write-Verbose -Message ('Setting content of: {0}' -f $Path) -Verbose
}
}

It 'Should export the build script alias' {
Expand Down Expand Up @@ -67,5 +76,9 @@ Describe 'Clean_WikiContent_For_GitHub_Publish' {

Invoke-Build -Task $buildTaskName -File $script:buildScript.Definition @taskParameters
} | Should -Not -Throw

Assert-MockCalled -CommandName Set-Content -ParameterFilter {
$Path -eq "$($TestDrive.FullName)/WikiContent/Credential-overview.md"
} -Exactly -Times 1 -Scope It
}
}

0 comments on commit f846915

Please sign in to comment.