summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2011-04-20 00:22:54 +0000
committermurphy <murphy@rubychan.de>2011-04-20 00:22:54 +0000
commitc4b03b3dbd730ae3430a99d96a5d50ce21771836 (patch)
tree0c0ebb2371f1af83f41a199e30913ccc3aca1840
parentb5a99d5823c4701b28684933491d050945967aae (diff)
downloadcoderay-c4b03b3dbd730ae3430a99d96a5d50ce21771836.tar.gz
Improved HTML/JavaScript integration: Check attribute name with list of handlers.
-rw-r--r--lib/coderay/scanners/html.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/coderay/scanners/html.rb b/lib/coderay/scanners/html.rb
index f4dab0e..659ed39 100644
--- a/lib/coderay/scanners/html.rb
+++ b/lib/coderay/scanners/html.rb
@@ -17,6 +17,21 @@ module Scanners
:plain, :entity, :error,
] # :nodoc:
+ JAVASCRIPT_ATTRIBUTES = %w(
+ onabort onblur oncanplay oncanplaythrough onchange onclick oncontextmenu
+ oncuechange ondblclick ondrag ondragdrop ondragend ondragenter
+ ondragleave ondragover ondragstart ondrop ondurationchange onemptied
+ onended onerror onfocus oninput oninvalid onkeydown onkeypress onkeyup
+ onload onloadeddata onloadedmetadata onloadstart onmousedown onmousemove
+ onmouseout onmouseover onmouseup onmousewheel onmove onpause onplay
+ onplaying onprogress onratechange onreadystatechange onreset onresize
+ onseeked onseeking onselect onshow onstalled onsubmit onsuspend
+ ontimeupdate onunload onvolumechange onwaiting
+ )
+
+ IN_ATTRIBUTE = CaseIgnoringWordList.new(nil).
+ add(JAVASCRIPT_ATTRIBUTES, :script)
+
ATTR_NAME = /[\w.:-]+/ # :nodoc:
TAG_END = /\/?>/ # :nodoc:
HEX = /[0-9a-fA-F]/ # :nodoc:
@@ -118,9 +133,7 @@ module Scanners
state = :initial
end
elsif match = scan(/#{ATTR_NAME}/o)
- if match.downcase == 'onclick'
- in_attribute = :script
- end
+ in_attribute = IN_ATTRIBUTE[match]
encoder.text_token match, :attribute_name
state = :attribute_equal
else