-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLMac.ps1
More file actions
115 lines (105 loc) · 6.37 KB
/
Copy pathHTMLMac.ps1
File metadata and controls
115 lines (105 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
Function WriteHTML([string]$text)
{
$Global:result += $text
}
Function WriteLineHTML([string]$text)
{
$Global:result += ("{0}`r`n" -f $text)
}
Function IncludeCR([string]$file)
{
$c=("{0}`r`n" -f ((Get-Content $file) -join "`r`n"))
$Global:result += $c
}
Function Include([string]$file)
{
$c=((Get-Content $file) -join "`r`n")
$Global:result += $c
}
Function IncludeUTF8([string]$file)
{
$tmp = New-TemporaryFile
$c=((Get-Content $file) -join "`r`n")
Out-File $tmp -inputobject $c -encoding Unicode
$c=("{0}`r`n" -f ((Get-Content $file) -join "`r`n"))
del $tmp
$Global:result += $c
}
Function PygmentizeFile([string]$file)
{
$tmp = New-TemporaryFile
C:\Python\Python36-32\Scripts\pygmentize.exe -f html -o $tmp $file
$c = (Get-Content $tmp.FullName) -join "`r`n"
del $tmp.FullName
$Global:result += $c
}
Function Pygmentize([string]$lexer, [string]$text)
{
$tmp1 = New-TemporaryFile
$tmp2 = New-TemporaryFile
Out-File $tmp1 -inputobject $text -encoding UTF8;
C:\Python\Python36-32\Scripts\pygmentize.exe -l $lexer -f html -o $tmp2 $tmp1
$c = (Get-Content $tmp2.FullName) -join "`r`n"
del $tmp1.FullName
del $tmp2.FullName
$Global:result += $c
}
Function ExpandMacros([string]$text)
{
$Global:num = 0
$Global:err = ""
$c= [regex]::Replace($text,"<!\-\-PS(.*?)(PS|)\-\->", {
param($word)
$Global:num++
$Global:code += "try {"
$Global:code += "`$Global:result=`"`";`r`n"
$Global:code += $word.Groups[1].Value
$Global:code += "`r`n"
$Global:code +="`$Global:ResultList.Add(`$Global:result) | Out-Null;`r`n"
$Global:code += "}`r`ncatch {`$Global:err = `$error[0].Exception.GetType().FullName;}"
if ($word.Groups[2].Value -ne "PS") {
"<!--PS{0}--><!--+Begin+-->{1}<!--+End+-->" -f $word.Groups[1].Value, $Global:num
} else {
"<!--PS{0}PS-->`r`n<!--+Begin+-->{1}<!--+End+-->" -f $word.Groups[1].Value, $Global:num
}
}, "SingleLine")
$Global:ResultList = [System.Collections.ArrayList]@()
$script = $ExecutionContext.InvokeCommand.NewScriptBlock($Global:code)
& $script | Out-Null
$Global:num = 0
$c= [regex]::Replace($c,"<!\-\-\+Begin\+\-\->(.*?)<!\-\-\+End\+\-\->", {
param($word)
"<!--+Begin+-->{0}<!--+End+-->" -f ($Global:ResultList[$Global:num++])
}, "SingleLine")
if ($Global:err -ne "") {
return $text
} else {
return $c
}
}
Function ReduceMacros([string]$text)
{
$c= [regex]::Replace($text,"\r\n<!\-\-\+Begin\+\-\->(.*?)<!\-\-\+End\+\-\->", {
param($word)
""
}, "SingleLine")
$c= [regex]::Replace($c,"<!\-\-\+Begin\+\-\->(.*?)<!\-\-\+End\+\-\->", {
param($word)
""
}, "SingleLine")
return $c
}
$htm_dir="./"
$Global:encoding = "UTF8"
$files = get-childitem $htm_dir | where {$_.extension -eq ".aspx"}
foreach ($file in $files)
{
$c=(Get-Content $file) -join "`r`n"
$c=ReduceMacros $c
$Global:code = ""
$c=ExpandMacros $c
if ($Global:err -ne "") {
echo $Global:err
}
Out-File $file -inputobject $c -encoding $Global:encoding;
}