Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean_WikiContent_For_GitHub_Publish: Fix parsing top level header #164

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ 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"
}

It 'Should export the build script alias' {
Expand Down
Loading