Skip to content

Commit 496eece

Browse files
author
James Brundage
committed
Switching Inline Markdown Transpiler to use -ReplacePattern (#84)
1 parent dd22797 commit 496eece

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

Transpilers/Inline/Inline.Markdown.psx.ps1

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,27 @@ begin {
6464
# * EndRegex ```$whitespace + '}' + $EndComment```
6565
$endRegex = "(?<PSEnd>${endComment})"
6666

67+
$ReplacablePattern = [Regex]::New("
68+
# Match the PipeScript Start
69+
$startRegex
70+
# Match until the PipeScript end. This will be PipeScript
71+
(?<PipeScript>
72+
(?:.|\s){0,}?(?=\z|$endRegex)
73+
)
74+
# Then Match the PipeScript End
75+
$endRegex
76+
", 'IgnoreCase, IgnorePatternWhitespace', '00:00:05')
77+
6778
$sourcePattern = [Regex]::New("(?>$(
6879
$startRegex, $endRegex -join ([Environment]::NewLine + '|' + [Environment]::NewLine)
6980
))", "IgnoreCase, IgnorePatternWhitespace", "00:00:05")
81+
82+
7083
}
7184

7285
process {
7386

74-
$fileInfo = $commandInfo.Source -as [IO.FileInfo]
75-
$fileText = [IO.File]::ReadAllText($fileInfo.Fullname)
76-
77-
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -SourcePattern $sourcePattern -ForeachObject {
87+
$foreachMarkdownOutput = {
7888
process {
7989
if ($_ -is [string]) {
8090
$_
@@ -88,4 +98,13 @@ process {
8898
}
8999
}
90100
}
101+
102+
$fileInfo = $commandInfo.Source -as [IO.FileInfo]
103+
$fileText = [IO.File]::ReadAllText($fileInfo.Fullname)
104+
105+
if ($ReplacablePattern) {
106+
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -Replace $ReplacablePattern -ForeachObject $foreachMarkdownOutput
107+
} else {
108+
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -SourcePattern $sourcePattern -ForeachObject $foreachMarkdownOutput
109+
}
91110
}

0 commit comments

Comments
 (0)