summaryrefslogtreecommitdiff
path: root/lib/coderay
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2010-03-26 03:25:35 +0000
committermurphy <murphy@rubychan.de>2010-03-26 03:25:35 +0000
commit68d5c2a2d1ed252d8d4314089f57a1878b1a6e32 (patch)
tree19ecbec991fda3d393298a68c7a340f65644a9f8 /lib/coderay
parent7a143d76326e8edcd3b5a33986dea817e4869ddd (diff)
downloadcoderay-68d5c2a2d1ed252d8d4314089f57a1878b1a6e32.tar.gz
Cleanup and simplify HTML scanner.
Diffstat (limited to 'lib/coderay')
-rw-r--r--lib/coderay/scanners/html.rb37
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/coderay/scanners/html.rb b/lib/coderay/scanners/html.rb
index d59fa69..52c7520 100644
--- a/lib/coderay/scanners/html.rb
+++ b/lib/coderay/scanners/html.rb
@@ -2,6 +2,10 @@ module CodeRay
module Scanners
# HTML Scanner
+ #
+ # Alias: +xhtml+
+ #
+ # See also: Scanners::XML
class HTML < Scanner
include Streamable
@@ -11,13 +15,12 @@ module Scanners
:comment, :doctype, :preprocessor,
:tag, :attribute_name, :operator,
:attribute_value, :delimiter, :content,
- :plain, :entity, :error
- ]
-
- ATTR_NAME = /[\w.:-]+/
- ATTR_VALUE_UNQUOTED = ATTR_NAME
- TAG_END = /\/?>/
- HEX = /[0-9a-fA-F]/
+ :plain, :entity, :error,
+ ] # :nodoc:
+
+ ATTR_NAME = /[\w.:-]+/ # :nodoc:
+ TAG_END = /\/?>/ # :nodoc:
+ HEX = /[0-9a-fA-F]/ # :nodoc:
ENTITY = /
&
(?:
@@ -31,19 +34,21 @@ module Scanners
)
)
;
- /ox
-
+ /ox # :nodoc:
+
PLAIN_STRING_CONTENT = {
"'" => /[^&'>\n]+/,
'"' => /[^&">\n]+/,
- }
-
- def reset
+ } # :nodoc:
+
+ def reset # :nodoc:
+ # FIXME: why not overwrite reset_instance?
super
@state = :initial
end
-
- private
+
+ protected
+
def setup
@state = :initial
@plain_string_content = nil
@@ -117,7 +122,7 @@ module Scanners
end
when :attribute_value
- if scan(/#{ATTR_VALUE_UNQUOTED}/o)
+ if scan(/#{ATTR_NAME}/o)
kind = :attribute_value
state = :attribute
elsif match = scan(/["']/)
@@ -159,7 +164,7 @@ module Scanners
end
match ||= matched
- if $DEBUG and not kind
+ if $CODERAY_DEBUG and not kind
raise_inspect 'Error token %p in line %d' %
[[match, kind], line], tokens, state
end