Skip to content

Commit

Permalink
feat: Porting XML Template to Language Function (Fixes #632)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Nov 12, 2023
1 parent 6035245 commit 0e918e2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 86 deletions.
42 changes: 42 additions & 0 deletions Commands/Languages/XML/XML-Language.ps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Language function XML {
<#
.SYNOPSIS
XML Template Transpiler.
.DESCRIPTION
Allows PipeScript to generate XML.
Multiline comments blocks like this ```<!--{}-->``` will be treated as blocks of PipeScript.
#>
[ValidatePattern('\.xml$')]
param()

# We start off by declaring a number of regular expressions:
$startComment = '<\!--' # * Start Comments ```<!--```
$endComment = '-->' # * End Comments ```-->```
$Whitespace = '[\s\n\r]{0,}'
# * StartPattern ```$StartComment + '{' + $Whitespace```
$startPattern = "(?<PSStart>${startComment}\{$Whitespace)"
# * EndPattern ```$whitespace + '}' + $EndComment```
$endPattern = "(?<PSEnd>$Whitespace\}${endComment}\s{0,})"

$ForeachObject = {
$in = $_
if (($in -is [string]) -or
($in.GetType -and $in.GetType().IsPrimitive)) {
$in
} elseif ($in.ChildNodes) {
foreach ($inChildNode in $in.ChildNodes) {
if ($inChildNode.NodeType -ne 'XmlDeclaration') {
$inChildNode.OuterXml
}
}
} else {
$inXml = (ConvertTo-Xml -Depth 100 -InputObject $in)
foreach ($inChildNode in $inXml.ChildNodes) {
if ($inChildNode.NodeType -ne 'XmlDeclaration') {
$inChildNode.OuterXml
}
}
}
}
}
86 changes: 0 additions & 86 deletions Transpilers/Templates/XML.Template.psx.ps1

This file was deleted.

0 comments on commit 0e918e2

Please sign in to comment.