File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ <#
2+ . SYNOPSIS
3+ XML Inline PipeScript Transpiler.
4+ . DESCRIPTION
5+ Transpiles XML with Inline PipeScript into XML.
6+
7+ Multiline comments blocks like this ```<!--{}-->``` will be treated as blocks of PipeScript.
8+ #>
9+ [ValidateScript ({
10+ $cmdInfo = $_
11+ if ($cmdInfo.Source -match ' \.(?>xml|xaml)$' ) {
12+ return $true
13+ }
14+ return $false
15+ })]
16+ param (
17+ # The command information. This will include the path to the file.
18+ [Parameter (Mandatory , ValueFromPipeline )]
19+ $CommandInfo
20+ )
21+
22+ begin {
23+ # We start off by declaring a number of regular expressions:
24+ $startComment = ' <\!--' # * Start Comments ```<!--```
25+ $endComment = ' -->' # * End Comments ```-->```
26+ $Whitespace = ' [\s\n\r]{0,}'
27+ # * StartRegex ```$StartComment + '{' + $Whitespace```
28+ $startRegex = " (?<PSStart>${startComment} \{$Whitespace )"
29+ # * EndRegex ```$whitespace + '}' + $EndComment```
30+ $endRegex = " (?<PSEnd>$Whitespace \}${endComment} \s{0,})"
31+
32+ $sourcePattern = [Regex ]::New(" (?>$ (
33+ $startRegex , $endRegex -join ([Environment ]::NewLine + ' |' + [Environment ]::NewLine)
34+ ) )" , " IgnoreCase, IgnorePatternWhitespace" , " 00:00:05" )
35+ }
36+
37+ process {
38+
39+ $fileInfo = $commandInfo.Source -as [IO.FileInfo ]
40+ $fileText = [IO.File ]::ReadAllText($fileInfo.Fullname )
41+
42+ .> PipeScript.Inline - SourceFile $CommandInfo.Source - SourceText $fileText - SourcePattern $sourcePattern
43+ }
You can’t perform that action at this time.
0 commit comments