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
143
144
145
146
147
148
149
150
#!/usr/bin/env ruby
#
# Lookup current word as a CSS property on w3c.org
#
# The mapping below was generated using:
# echo '$props = {'; curl -s http://www.w3.org/TR/CSS2/propidx.html|egrep "(^|<tr><td>)<a href=\".*\" class=\"noxref\"><span class=\".*\">'.*'</span></a>"|perl -pe "s|(?:<tr><td>)?<a href=\"(.*)\" class=\"noxref\"><span class=\".*\">'(.*)'</span></a>|\t\"\$2\"\t=> \"\$1\",|"; echo '}'

$props = {
  "azimuth" => "aural.html#propdef-azimuth",
  "background"  => "colors.html#propdef-background",
  "background-attachment" => "colors.html#propdef-background-attachment",
  "background-color"  => "colors.html#propdef-background-color",
  "background-image"  => "colors.html#propdef-background-image",
  "background-position" => "colors.html#propdef-background-position",
  "background-repeat" => "colors.html#propdef-background-repeat",
  "border"  => "box.html#propdef-border",
  "border-collapse" => "tables.html#propdef-border-collapse",
  "border-color"  => "box.html#propdef-border-color",
  "border-spacing"  => "tables.html#propdef-border-spacing",
  "border-style"  => "box.html#propdef-border-style",
  "border-top"  => "box.html#propdef-border-top",
  "border-right"  => "box.html#propdef-border-right",
  "border-bottom" => "box.html#propdef-border-bottom",
  "border-left" => "box.html#propdef-border-left",
  "border-top-color"  => "box.html#propdef-border-top-color",
  "border-right-color"  => "box.html#propdef-border-right-color",
  "border-bottom-color" => "box.html#propdef-border-bottom-color",
  "border-left-color" => "box.html#propdef-border-left-color",
  "border-top-style"  => "box.html#propdef-border-top-style",
  "border-right-style"  => "box.html#propdef-border-right-style",
  "border-bottom-style" => "box.html#propdef-border-bottom-style",
  "border-left-style" => "box.html#propdef-border-left-style",
  "border-top-width"  => "box.html#propdef-border-top-width",
  "border-right-width"  => "box.html#propdef-border-right-width",
  "border-bottom-width" => "box.html#propdef-border-bottom-width",
  "border-left-width" => "box.html#propdef-border-left-width",
  "border-width"  => "box.html#propdef-border-width",
  "bottom"  => "visuren.html#propdef-bottom",
  "caption-side"  => "tables.html#propdef-caption-side",
  "clear" => "visuren.html#propdef-clear",
  "clip"  => "visufx.html#propdef-clip",
  "color" => "colors.html#propdef-color",
  "content" => "generate.html#propdef-content",
  "counter-increment" => "generate.html#propdef-counter-increment",
  "counter-reset" => "generate.html#propdef-counter-reset",
  "cue" => "aural.html#propdef-cue",
  "cue-after" => "aural.html#propdef-cue-after",
  "cue-before"  => "aural.html#propdef-cue-before",
  "cursor"  => "ui.html#propdef-cursor",
  "direction" => "visuren.html#propdef-direction",
  "display" => "visuren.html#propdef-display",
  "elevation" => "aural.html#propdef-elevation",
  "empty-cells" => "tables.html#propdef-empty-cells",
  "float" => "visuren.html#propdef-float",
  "font"  => "fonts.html#propdef-font",
  "font-family" => "fonts.html#propdef-font-family",
  "font-size" => "fonts.html#propdef-font-size",
  "font-size-adjust"  => "fonts.html#propdef-font-size-adjust",
  "font-stretch"  => "fonts.html#propdef-font-stretch",
  "font-style"  => "fonts.html#propdef-font-style",
  "font-variant"  => "fonts.html#propdef-font-variant",
  "font-weight" => "fonts.html#propdef-font-weight",
  "height"  => "visudet.html#propdef-height",
  "left"  => "visuren.html#propdef-left",
  "letter-spacing"  => "text.html#propdef-letter-spacing",
  "line-height" => "visudet.html#propdef-line-height",
  "list-style"  => "generate.html#propdef-list-style",
  "list-style-image"  => "generate.html#propdef-list-style-image",
  "list-style-position" => "generate.html#propdef-list-style-position",
  "list-style-type" => "generate.html#propdef-list-style-type",
  "margin"  => "box.html#propdef-margin",
  "margin-top"  => "box.html#propdef-margin-top",
  "margin-right"  => "box.html#propdef-margin-right",
  "margin-bottom" => "box.html#propdef-margin-bottom",
  "margin-left" => "box.html#propdef-margin-left",
  "marker-offset" => "generate.html#propdef-marker-offset",
  "marks" => "page.html#propdef-marks",
  "max-height"  => "visudet.html#propdef-max-height",
  "max-width" => "visudet.html#propdef-max-width",
  "min-height"  => "visudet.html#propdef-min-height",
  "min-width" => "visudet.html#propdef-min-width",
  "orphans" => "page.html#propdef-orphans",
  "outline" => "ui.html#propdef-outline",
  "outline-color" => "ui.html#propdef-outline-color",
  "outline-style" => "ui.html#propdef-outline-style",
  "outline-width" => "ui.html#propdef-outline-width",
  "overflow"  => "visufx.html#propdef-overflow",
  "padding" => "box.html#propdef-padding",
  "padding-top" => "box.html#propdef-padding-top",
  "padding-right" => "box.html#propdef-padding-right",
  "padding-bottom"  => "box.html#propdef-padding-bottom",
  "padding-left"  => "box.html#propdef-padding-left",
  "page"  => "page.html#propdef-page",
  "page-break-after"  => "page.html#propdef-page-break-after",
  "page-break-before" => "page.html#propdef-page-break-before",
  "page-break-inside" => "page.html#propdef-page-break-inside",
  "pause" => "aural.html#propdef-pause",
  "pause-after" => "aural.html#propdef-pause-after",
  "pause-before"  => "aural.html#propdef-pause-before",
  "pitch" => "aural.html#propdef-pitch",
  "pitch-range" => "aural.html#propdef-pitch-range",
  "play-during" => "aural.html#propdef-play-during",
  "position"  => "visuren.html#propdef-position",
  "quotes"  => "generate.html#propdef-quotes",
  "richness"  => "aural.html#propdef-richness",
  "right" => "visuren.html#propdef-right",
  "size"  => "page.html#propdef-size",
  "speak" => "aural.html#propdef-speak",
  "speak-header"  => "tables.html#propdef-speak-header",
  "speak-numeral" => "aural.html#propdef-speak-numeral",
  "speak-punctuation" => "aural.html#propdef-speak-punctuation",
  "speech-rate" => "aural.html#propdef-speech-rate",
  "stress"  => "aural.html#propdef-stress",
  "table-layout"  => "tables.html#propdef-table-layout",
  "text-align"  => "text.html#propdef-text-align",
  "text-decoration" => "text.html#propdef-text-decoration",
  "text-indent" => "text.html#propdef-text-indent",
  "text-shadow" => "text.html#propdef-text-shadow",
  "text-transform"  => "text.html#propdef-text-transform",
  "top" => "visuren.html#propdef-top",
  "unicode-bidi"  => "visuren.html#propdef-unicode-bidi",
  "vertical-align"  => "visudet.html#propdef-vertical-align",
  "visibility"  => "visufx.html#propdef-visibility",
  "voice-family"  => "aural.html#propdef-voice-family",
  "volume"  => "aural.html#propdef-volume",
  "white-space" => "text.html#propdef-white-space",
  "widows"  => "page.html#propdef-widows",
  "width" => "visudet.html#propdef-width",
  "word-spacing"  => "text.html#propdef-word-spacing",
  "z-index" => "visuren.html#propdef-z-index",
}

cur_line = ENV['TM_CURRENT_LINE']
cur_word = ENV['TM_CURRENT_WORD']

# since dash (‘-’) is not a word character, extend current word to neighboring word and dash characters
$prop_name = /[-\w]*#{cur_word}[-\w]*/.match(cur_line)[0]

def request_prop_name
  s = `\"#{ENV['TM_SUPPORT_PATH']}/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog\" inputbox --title 'Documentation for Property' --informative-text 'What property would you like to lookup?' --text '#{$prop_name}' --button1 'Lookup' --button2 'Cancel' --button3 'Show All Properties'`
  case (a = s.split("\n"))[0].to_i
    when 1 then $props[a[1].to_s] || "propidx.html"
    when 2 then abort "<script>window.close()</script>"
    when 3 then "propidx.html"
  end
end

prop_url = $props[$prop_name] || request_prop_name
url = "http://www.w3.org/TR/CSS2/" + prop_url
puts "<meta http-equiv='Refresh' content='0;URL=#{url}'>"