module Rules

  class NonHtml < TextElement
    def validate value
      # unlikely to be found in raw text: closing tags and named entites
      if value =~ /<\/\w+>/ or value =~ /&#?\w+;/
        log :ContainsUndeclaredHTML
      end
    end
  end

  class IsHtml < TextElement
    def validate value
      # simpleminded check: ensure that all tag attributes are completed
      if not value.split('<')[1..-1].reject { |s| s=~/^\/?\w+(\s+\w+(=(\w+|"[^"]*"|'[^']*'))?)*\s*\/?>/ }.empty?
        log :NotHtml
      end
    end
  end

end
