4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/minisyntax/highlighter/html.rb', line 4
def self.highlight(code)
code = "#{code}"
code.gsub! %r((<script( [a-z\-]+(=("|'|\w).*?\4)?)*>)(.*?)(</script>))m do
%Q(#{$1}#{MiniSyntax.highlight($5, :javascript)}#{$6})
end
code.gsub! %r(<([a-z\-]+[1-6]?)(( [a-z\-]+(=("|").*?("|"))?)*)( /)?>)m do
tag = $1
xml_close_tag = $7
attributes = $2.gsub %r( ([a-z\-]+)(=("|")(.*?)("|"))?)m do
if %(onload onclick onmouseover onmousemove onmouseout onfocus onblur onkeyup onkeydown onkeypress).include?($1)
%Q( <b>#{$1}</b>=#{$3}#{MiniSyntax.highlight($4, :javascript)}#{$3})
else
%Q( <b>#{$1}</b>#{$2})
end
end if $2
%Q(<b><<em>#{tag}</em></b>#{attributes}<b>#{xml_close_tag}></b>)
end
code.gsub! %r(</([a-z\-]+[1-6]?)>) do
tag = $1
%Q(<b></<em>#{tag}</em>></b>)
end
code
end
|