Skip to content

Commit 0e918e2

Browse files
author
James Brundage
committed
feat: Porting XML Template to Language Function (Fixes #632)
1 parent 6035245 commit 0e918e2

File tree

2 files changed

+42
-86
lines changed

2 files changed

+42
-86
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Language function XML {
2+
<#
3+
.SYNOPSIS
4+
XML Template Transpiler.
5+
.DESCRIPTION
6+
Allows PipeScript to generate XML.
7+
8+
Multiline comments blocks like this ```<!--{}-->``` will be treated as blocks of PipeScript.
9+
#>
10+
[ValidatePattern('\.xml$')]
11+
param()
12+
13+
# We start off by declaring a number of regular expressions:
14+
$startComment = '<\!--' # * Start Comments ```<!--```
15+
$endComment = '-->' # * End Comments ```-->```
16+
$Whitespace = '[\s\n\r]{0,}'
17+
# * StartPattern ```$StartComment + '{' + $Whitespace```
18+
$startPattern = "(?<PSStart>${startComment}\{$Whitespace)"
19+
# * EndPattern ```$whitespace + '}' + $EndComment```
20+
$endPattern = "(?<PSEnd>$Whitespace\}${endComment}\s{0,})"
21+
22+
$ForeachObject = {
23+
$in = $_
24+
if (($in -is [string]) -or
25+
($in.GetType -and $in.GetType().IsPrimitive)) {
26+
$in
27+
} elseif ($in.ChildNodes) {
28+
foreach ($inChildNode in $in.ChildNodes) {
29+
if ($inChildNode.NodeType -ne 'XmlDeclaration') {
30+
$inChildNode.OuterXml
31+
}
32+
}
33+
} else {
34+
$inXml = (ConvertTo-Xml -Depth 100 -InputObject $in)
35+
foreach ($inChildNode in $inXml.ChildNodes) {
36+
if ($inChildNode.NodeType -ne 'XmlDeclaration') {
37+
$inChildNode.OuterXml
38+
}
39+
}
40+
}
41+
}
42+
}

Transpilers/Templates/XML.Template.psx.ps1

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)