66. SYNOPSIS
77 Generates PSSVG
88. DESCRIPTION
9- Generates PSSVG, a module for creating 2d images with PowerShell.
9+ Generates PSSVG, a module for creating svg images with PowerShell.
1010
1111 PSSVG allows you to create Scalable Vector Graphics using PowerShell commands.
1212
@@ -72,13 +72,17 @@ if (-not $svgElements) {
7272
7373$findSvgElement = [Regex ]::new(" \{\{SVGElement\(['`" ](?<e>[^'`" ]+)" )
7474$findSvgAttr = [Regex ]::new(" \{\{SVGAttr\(['`" ](?<a>[^'`" ]+)" )
75+ $replaceMDNContent = " \{\{\s{0,}(?>$ ( @ (' Glossary' , ' cssxref' , ' domxref' , ' HTTPMethod' , ' htmlelement' , ' svgelement' , ' svgattr' , ' htmlattrxref' , ' cssxref' ) -join ' |' ) [^\)]{0,})\(" +
76+ ' ["'' ](?<s>[^"'' ]+)["'' ]\)\s{0,}\}\}'
77+
7578
7679function ConvertSVGMetadataToParameterAttribute {
7780 param ([Parameter (ValueFromPipeline , Position = 0 )][string ]$EdiValue )
7881 $hadNumbers = $false
7982 $hadUri = $false
8083 $hadColor = $false
8184 $hadUnknown = $false
85+ $tabCompletionRedundant = $false
8286 if ($ediValue -notmatch ' \|' ) {
8387 if ($ediValue -match ' \<(?<t>[^\>])>' ) {
8488 if ($matches.t -as [type ]) {
@@ -87,7 +91,8 @@ function ConvertSVGMetadataToParameterAttribute {
8791 }
8892 return
8993 }
90- $validSet = @ (foreach ($validValue in $ediValue -split ' \|' -replace ' ^\s{0,}' -replace ' \s{0,}$' ) {
94+ $setDescriptors = @ ($ediValue -split ' \|' -replace ' ^\s{0,}' -replace ' \s{0,}$' )
95+ $validSet = @ (foreach ($validValue in $setDescriptors ) {
9196 if ($validValue -as [int ] -or $validValue -match ' number' ) {
9297 $hadNumbers = $true
9398 }
@@ -105,7 +110,7 @@ function ConvertSVGMetadataToParameterAttribute {
105110 }
106111 else {
107112 $validValue
108- }
113+ }
109114 }) -join " ','"
110115 if ($hadNumbers ) {
111116 " [ValidatePattern('(?>$ ( $validSet -split " ','" -join ' |' ) |\d+)')]"
@@ -117,8 +122,26 @@ function ConvertSVGMetadataToParameterAttribute {
117122 " [ValidateScript({`$ _ -in '$validSet ' -or `$ _ -match '\#[0-9a-f]{3}' -or `$ _ -match '\#[0-9a-f]{6}' -or `$ _ -notmatch '\W'})]"
118123 }
119124 elseif ($validSet -and -not $hadUnknown ) {
125+ $tabCompletionRedundant = $true
120126 " [ValidateSet('$validSet ')]"
121- }
127+ }
128+
129+ if ($setDescriptors -and -not $tabCompletionRedundant ) {
130+ $null = $null
131+ ' [ArgumentCompleter({
132+ param ( $commandName,$parameterName,$wordToComplete,$commandAst,$fakeBoundParameters )
133+ ' + "
134+ `$ validSet = '$ ( $setDescriptors -replace $replaceMDNContent , ' <${s}>' -replace " '" , " ''" -join " ','" ) '
135+ " + @'
136+ if ($wordToComplete) {
137+ $toComplete = $wordToComplete -replace "^'" -replace "'$"
138+ return @($validSet -like "$toComplete*" -replace '^', "'" -replace '$',"'")
139+ } else {
140+ return @($validSet -replace '^', "'" -replace '$',"'")
141+ }
142+ })]
143+ '@
144+ }
122145}
123146
124147function ImportSvgAttribute {
@@ -141,9 +164,7 @@ function ImportSvgAttribute {
141164 if (-not $elementMarkdown ) {
142165 Write-Verbose " Did not get content for $elementOrSetName "
143166 return
144- }
145- $replaceMDNContent = " \{\{\s{0,}(?>$ ( @ (' Glossary' , ' domxref' , ' HTTPMethod' , ' htmlelement' , ' svgelement' , ' svgattr' , ' htmlattrxref' , ' cssxref' ) -join ' |' ) [^\)]{0,})\(" +
146- ' ["'' ](?<s>[^"'' ]+)["'' ]\)\s{0,}\}\}'
167+ }
147168
148169 $start , $end = 0 , 0
149170 $globalAttrStart , $globalAttrEnd = 0 , 0
@@ -425,9 +446,7 @@ function InitializeSvgAttributeData {
425446
426447 }
427448
428- $headingList = $savedMarkdown [$attrUri ] | ? < Markdown_Heading> -Split - IncludeMatch
429- $replaceMDNContent = " \{\{\s{0,}(?>$ ( @ (' Glossary' , ' domxref' , ' HTTPMethod' , ' htmlelement' , ' svgelement' , ' svgattr' , ' htmlattrxref' ) -join ' |' ) )\(" +
430- ' ["'' ](?<s>[^"'' ]+)["'' ]\)\s{0,}\}\}'
449+ $headingList = $savedMarkdown [$attrUri ] | ? < Markdown_Heading> -Split - IncludeMatch
431450
432451 $attrMetadata [$attrKv.key ] = [PSCustomObject ]@ {
433452 Name = $attrKv.Key
@@ -492,7 +511,7 @@ foreach ($elementKV in $svgElementData.GetEnumerator()) {
492511 $newPipeScriptSplat = @ {
493512 Synopsis = " Creates SVG $ ( $elementKV.Key ) elements"
494513 Description = $elementKV.Value.Description.Trim ()
495- Link = $docsLink , $mdnLink
514+ Link = $docsLink , $mdnLink , ' Write-SVG '
496515 }
497516 $relevantExampleFiles = Get-ChildItem - Filter * .ps1 - Path $examplesRoot |
498517 Select-String " \<svg.$ ( $elementKv.Key ) \>" |
@@ -521,8 +540,7 @@ foreach ($elementKV in $svgElementData.GetEnumerator()) {
521540 $parameters.Content = @ (
522541 " # The Contents of the $ ( $elementKv.Key ) element"
523542 if ($content.Description -eq ' characterDataElementsInAnyOrder' ) {
524- " [Reflection.AssemblyMetaData('SVG.IsCData', `$ $true )]"
525- " [string]"
543+ " [Reflection.AssemblyMetaData('SVG.IsCData', `$ $true )]"
526544 }
527545 " [Parameter(Position=0,ValueFromPipelineByPropertyName)]"
528546 " [Alias('InputObject','Text', 'InnerText', 'Contents')]"
0 commit comments