Skip to content

Commit 08b734e

Browse files
authored
Remove-EscapedMarkdownCode: Fix escaping issues (#141)
1 parent c40598a commit 08b734e

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
### Fixed
9+
10+
- `Remove-EscapedMarkdownCode`
11+
- Add additional escape sequences to remove ([issue #140](https://github.com/dsccommunity/DscResource.DocGenerator/issues/140)).
12+
813
## [0.12.0] - 2024-01-21
914

1015
### Removed

source/Private/Remove-EscapedMarkdownCode.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,40 @@ function Remove-EscapedMarkdownCode
4040

4141
$escapedPatterns = @(
4242
@{
43-
RegularExpression = '\\\`(.+?)\\\`' # Remove escaped inline code-blocks
43+
# Remove escaped inline code-blocks, ingores escaped code-blocks.
44+
RegularExpression = '\\\`(?!\\\`)(?!\`)(.+?)\\\`'
4445
Replacement = '`$1`'
4546
}
4647
@{
47-
RegularExpression = '\\\[(.+?)\\\]' # Remove escaped links
48+
# Remove escaped links.
49+
RegularExpression = '\\\[(.+?)\\\]'
4850
Replacement = '[$1]'
4951
}
50-
5152
@{
52-
RegularExpression = '(?m)^\\\>' # Remove quoted blocks
53+
# Remove quoted blocks, if they start on each line.
54+
RegularExpression = '(?m)^\\\>'
55+
Replacement = '>'
56+
}
57+
@{
58+
# Remove escaped code blocks.
59+
RegularExpression = '\\\`\\\`\\\`'
60+
Replacement = '```'
61+
}
62+
@{
63+
# Remove escaped less than character.
64+
RegularExpression = '\\\<'
65+
Replacement = '<'
66+
}
67+
@{
68+
# Remove escaped greater than character.
69+
RegularExpression = '\\\>'
5370
Replacement = '>'
5471
}
72+
@{
73+
# Remove escaped path separator.
74+
RegularExpression = '\\\\'
75+
Replacement = '\'
76+
}
5577
)
5678

5779
foreach ($pattern in $escapedPatterns)

tests/unit/private/Remove-EscapedMarkdownCode.Tests.ps1

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ This is \`inline code 2\`
3434
3535
Removes escaped links: \[MyLinkName\]
3636
37-
Do not start at the beginning of the line: \> This quote block should be kept
37+
Greater than sign \>
38+
Less than sign \<
3839
3940
Removes quoted blocks:
4041
\> This block should be changed
4142
\> This block should be changed
4243
\> This block should be changed
44+
45+
\`\`\`code block 1\`\`\`e
46+
\`\`\`code block 2\`\`\`
47+
48+
C:\\Path\\To\\File.ps1
4349
"@
4450

4551
Set-Content -Path $testFilePath -Value $contentWithParameter
@@ -62,13 +68,45 @@ Removes quoted blocks:
6268
$content | Should -Not -Match '\\\[MyLinkName\\\]'
6369
}
6470

65-
It 'Should remove quoted blocks from the markdown file' {
71+
It 'Should remove escaped quoted blocks from the markdown file' {
6672
Remove-EscapedMarkdownCode -FilePath $testFilePath
6773

6874
$content = Get-Content -Path $testFilePath -Raw
6975

7076
$content | Should -Not -Match '\\\> This block should be changed'
71-
$content | Should -Match '\\\> This quote block should be kept' -Because 'the quote block does not start at the beginning of the line'
77+
}
78+
79+
It 'Should remove escaped greater than character from the markdown file' {
80+
Remove-EscapedMarkdownCode -FilePath $testFilePath
81+
82+
$content = Get-Content -Path $testFilePath -Raw
83+
84+
$content | Should -Not -Match '\\>'
85+
}
86+
87+
It 'Should remove escaped less than character from the markdown file' {
88+
Remove-EscapedMarkdownCode -FilePath $testFilePath
89+
90+
$content = Get-Content -Path $testFilePath -Raw
91+
92+
$content | Should -Not -Match '\\<'
93+
}
94+
95+
It 'Should remove escaped code blocks from the markdown file' {
96+
Remove-EscapedMarkdownCode -FilePath $testFilePath
97+
98+
$content = Get-Content -Path $testFilePath -Raw
99+
100+
$content | Should -Not -Match '\\\`\\\`\\\`'
101+
$content | Should -Not -Match '\`\`\`'
102+
}
103+
104+
It 'Should remove escaped path separator from the markdown file' {
105+
Remove-EscapedMarkdownCode -FilePath $testFilePath
106+
107+
$content = Get-Content -Path $testFilePath -Raw
108+
109+
$content | Should -Match 'C:\\Path\\To\\File.ps1'
72110
}
73111
}
74112
}

0 commit comments

Comments
 (0)