forked from tomasr/vsthemes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvstomd.ps1
143 lines (129 loc) · 4.02 KB
/
vstomd.ps1
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#
# extract colors used in a vs colorscheme into a monodevelop one
#
param([string]$vsfile, [string]$mdfile)
function get-color($color) {
if ( $color.StartsWith('0x02') ) {
return $null
} else {
$rgb = $color.substring(4,6)
$red = $rgb.substring(4,2)
$green = $rgb.substring(2,2)
$blue = $rgb.substring(0,2)
return "#$red$green$blue"
}
}
function write-colorDef($writer, $name, $value) {
$writer.WriteStartElement('Color')
$writer.WriteAttributeString('name', $name)
$writer.WriteAttributeString('value', $value)
$writer.WriteEndElement()
}
function fgname($name) {
"$name.fg"
}
function bgname($name) {
"$name.bg"
}
function find($items, $name) {
foreach ( $item in $items ) {
if ( $item.Name -eq $name ) {
return $item
break
}
}
}
function write-style($writer, $name, $fg, $bg) {
$writer.WriteStartElement('Style')
$writer.WriteAttributeString('name', $name)
$writer.WriteAttributeString('color', $(if ( $fg ) { $fg } else { '' }) )
if ( $bg ) {
$writer.WriteAttributeString('bgColor', $bg)
}
$writer.WriteEndElement()
}
function add-style($writer, $fgcols, $bgcols, $items, $vsname, $mdname) {
$item = find $items $vsname
if ( -not $item ) {
"$vsname doesn't exist. You sure you got it right?"
} else {
$fg = (get-color $item.Foreground)
$bg = (get-color $item.Background)
if ( $fg ) {
write-colorDef $writer (fgname $mdname) $fg
$fgcols.$mdname = (fgname $mdname)
} else {
$fgcols.$mdname = ''
}
if ( $bg ) {
write-colorDef $writer (bgname $mdname) $bg
$bgcols.$mdname = (bgname $mdname)
} else {
$bgcols.$mdname = ''
}
}
}
$xml = [xml](gc $vsfile);
$schemeName = [io.Path]::GetFileNameWithoutExtension($vsfile)
$cat = $xml.SelectSingleNode("//Category[@GUID='{A27B4E24-A735-4D1D-B8E7-9716E1E3D8E0}']")
$items = $cat.SelectNodes("Items/Item")
$wset = new-object xml.xmlwritersettings
$wset.Indent = $true
$writer = [xml.xmlwriter]::Create($mdfile, $wset);
trap {
if ( $writer -ne $null ) {
$writer.Close()
throw $error
}
}
$writer.WriteStartElement('EditorStyle')
$writer.WriteAttributeString('name', $schemeName)
$writer.WriteAttributeString('_description', '')
$fgcols = @{}
$bgcols = @{}
$mapping = @{
'Identifier' = 'text';
'Selected Text' = 'text.selection';
'ViEmu hlsearch' = 'text.background.searchresult';
#'' = 'text.link'; ??
'Visible White Space' = 'marker.whitespace';
'Brace Matching (Rectangle)' = 'marker.bracket';
'Line Numbers' = 'linenumber';
'Collapsible Text' = 'fold.togglemarker';
'Indicator Margin' = 'iconbar';
'Comment' = 'comment';
'XML Doc Tag' = 'comment.keyword';
#'' = 'comment.tag'; ???
'Plain Text' = 'text.punctuation';
'Preprocessor Keyword' = @('text.preprocessor', 'text.preprocessor.keyword');
#'XML Delimiter' = 'text.markup';
'XML Name' = @('text.markup', 'text.markup.tag');
'Number' = @('constant', 'constant.digit', 'constant.language', 'constant.language.void');
'String' = @('string', 'string.single', 'string.double', 'string.other');
'Operator' = 'keyword.operator';
'Keyword' = @('keyword.access', 'keyword.iteration', 'keyword.jump',
'keyword.context', 'keyword.exceptions', 'keyword.modifier',
'keyword.namespace', 'keyword.type', 'keyword.property',
'keyword.selection', 'keyword.operator.declaration', 'keyword.declaration'
);
}
# bit of a hack, but I want to use the bg for Plain Text for all text
# so force it
$defbg = get-color (find $items 'Plain Text').Background
write-colorDef $writer (bgname 'text') $defbg
$mapping.Keys | sort | %{
$k = $_
$mapping.$_ | %{
add-style $writer $fgcols $bgcols $items $k $_
}
$k
}
$fgcols.Keys | sort | %{
if ( $_ -eq 'text' ) {
write-style $writer $_ $fgcols.$_ (bgname 'text')
} else {
write-style $writer $_ $fgcols.$_ $bgcols.$_
}
}
$writer.WriteEndElement()
$writer.Close()