From e796a247e5bf2395ec72b0ae98d68bcb648f5368 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Tue, 3 Jul 2012 18:19:05 -0700 Subject: use "id" instead of "constant" for css ids --- lib/coderay/scanners/css.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/coderay/scanners/css.rb') diff --git a/lib/coderay/scanners/css.rb b/lib/coderay/scanners/css.rb index 7b731ef..c473574 100644 --- a/lib/coderay/scanners/css.rb +++ b/lib/coderay/scanners/css.rb @@ -8,7 +8,7 @@ module Scanners KINDS_NOT_LOC = [ :comment, :class, :pseudo_class, :type, - :constant, :directive, + :id, :directive, :key, :value, :operator, :color, :float, :string, :error, :important, ] # :nodoc: @@ -73,7 +73,7 @@ module Scanners encoder.text_token match, :class next elsif match = scan(RE::Id) - encoder.text_token match, :constant + encoder.text_token match, :id next elsif match = scan(RE::PseudoClass) encoder.text_token match, :pseudo_class -- cgit v1.2.1 From 4eb4324c6fb20b9b5e7f73f17bc21e4a17fd3073 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Tue, 24 Jul 2012 10:59:50 -0700 Subject: use :tag instead of :type for identifiers --- lib/coderay/scanners/css.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/coderay/scanners/css.rb') diff --git a/lib/coderay/scanners/css.rb b/lib/coderay/scanners/css.rb index c473574..503e14e 100644 --- a/lib/coderay/scanners/css.rb +++ b/lib/coderay/scanners/css.rb @@ -7,7 +7,7 @@ module Scanners KINDS_NOT_LOC = [ :comment, - :class, :pseudo_class, :type, + :class, :pseudo_class, :tag, :id, :directive, :key, :value, :operator, :color, :float, :string, :error, :important, @@ -67,7 +67,7 @@ module Scanners elsif case states.last when :initial, :media if match = scan(/(?>#{RE::Ident})(?!\()|\*/ox) - encoder.text_token match, :type + encoder.text_token match, :tag next elsif match = scan(RE::Class) encoder.text_token match, :class @@ -102,7 +102,7 @@ module Scanners when :media_before_name if match = scan(RE::Ident) - encoder.text_token match, :type + encoder.text_token match, :tag states[-1] = :media_after_name next end -- cgit v1.2.1 From 469dba8c6378fb62ebf12c4a2f32b6be433bb16e Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Mon, 11 Mar 2013 02:23:22 +0100 Subject: added Sass scanner (work in progress) --- lib/coderay/scanners/css.rb | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'lib/coderay/scanners/css.rb') diff --git a/lib/coderay/scanners/css.rb b/lib/coderay/scanners/css.rb index 7b731ef..003eed6 100644 --- a/lib/coderay/scanners/css.rb +++ b/lib/coderay/scanners/css.rb @@ -15,19 +15,17 @@ module Scanners module RE # :nodoc: Hex = /[0-9a-fA-F]/ - Unicode = /\\#{Hex}{1,6}(?:\r\n|\s)?/ # differs from standard because it allows uppercase hex too - Escape = /#{Unicode}|\\[^\r\n\f0-9a-fA-F]/ - NMChar = /[-_a-zA-Z0-9]|#{Escape}/ - NMStart = /[_a-zA-Z]|#{Escape}/ - NL = /\r\n|\r|\n|\f/ - String1 = /"(?:[^\n\r\f\\"]|\\#{NL}|#{Escape})*"?/ # TODO: buggy regexp - String2 = /'(?:[^\n\r\f\\']|\\#{NL}|#{Escape})*'?/ # TODO: buggy regexp + Unicode = /\\#{Hex}{1,6}\b/ # differs from standard because it allows uppercase hex too + Escape = /#{Unicode}|\\[^\n0-9a-fA-F]/ + NMChar = /[-_a-zA-Z0-9]/ + NMStart = /[_a-zA-Z]/ + String1 = /"(?:[^\n\\"]+|\\\n|#{Escape})*"?/ # TODO: buggy regexp + String2 = /'(?:[^\n\\']+|\\\n|#{Escape})*'?/ # TODO: buggy regexp String = /#{String1}|#{String2}/ HexColor = /#(?:#{Hex}{6}|#{Hex}{3})/ - Color = /#{HexColor}/ - Num = /-?(?:[0-9]+|[0-9]*\.[0-9]+)/ + Num = /-?(?:[0-9]*\.[0-9]+|[0-9]+)/ Name = /#{NMChar}+/ Ident = /-?#{NMStart}#{NMChar}*/ AtKeyword = /@#{Ident}/ @@ -35,16 +33,15 @@ module Scanners reldimensions = %w[em ex px] absdimensions = %w[in cm mm pt pc] - Unit = Regexp.union(*(reldimensions + absdimensions + %w[s])) + Unit = Regexp.union(*(reldimensions + absdimensions + %w[s dpi dppx deg])) Dimension = /#{Num}#{Unit}/ - Comment = %r! /\* (?: .*? \*/ | .* ) !mx - Function = /(?:url|alpha|attr|counters?)\((?:[^)\n\r\f]|\\\))*\)?/ + Function = /(?:url|alpha|attr|counters?)\((?:[^)\n]|\\\))*\)?/ - Id = /##{Name}/ + Id = /(?!#{HexColor}\b(?!-))##{Name}/ Class = /\.#{Name}/ - PseudoClass = /:#{Name}/ + PseudoClass = /::?#{Ident}/ AttributeSelector = /\[[^\]]*\]?/ end @@ -52,7 +49,7 @@ module Scanners def setup @state = :initial - @value_expected = nil + @value_expected = false end def scan_tokens encoder, options @@ -158,7 +155,7 @@ module Scanners elsif match = scan(/(?: #{RE::Dimension} | #{RE::Percentage} | #{RE::Num} )/ox) encoder.text_token match, :float - elsif match = scan(/#{RE::Color}/o) + elsif match = scan(/#{RE::HexColor}/o) encoder.text_token match, :color elsif match = scan(/! *important/) @@ -170,7 +167,7 @@ module Scanners elsif match = scan(RE::AtKeyword) encoder.text_token match, :directive - elsif match = scan(/ [+>:;,.=()\/] /x) + elsif match = scan(/ [+>~:;,.=()\/] /x) if match == ':' value_expected = true elsif match == ';' -- cgit v1.2.1 From b159057934d2c84c0a25c83f6cbe59010345d0a7 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Tue, 11 Jun 2013 03:29:54 +0200 Subject: tweak CSS tag/id token kind patch from noprompt --- lib/coderay/scanners/css.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/coderay/scanners/css.rb') diff --git a/lib/coderay/scanners/css.rb b/lib/coderay/scanners/css.rb index 22c6bfc..732f9c5 100644 --- a/lib/coderay/scanners/css.rb +++ b/lib/coderay/scanners/css.rb @@ -10,7 +10,7 @@ module Scanners :class, :pseudo_class, :tag, :id, :directive, :key, :value, :operator, :color, :float, :string, - :error, :important, + :error, :important, :type, ] # :nodoc: module RE # :nodoc: @@ -99,7 +99,7 @@ module Scanners when :media_before_name if match = scan(RE::Ident) - encoder.text_token match, :tag + encoder.text_token match, :type states[-1] = :media_after_name next end -- cgit v1.2.1