diff --git a/app/models/course.rb b/app/models/course.rb index bac28e4c2..7db789a7a 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -92,10 +92,21 @@ class Course < ActiveRecord::Base # 课程的短描述信息 def short_description(length = 255) - description.gsub(/<\/?.*?>/,"").strip if description + description.gsub(/<\/?.*?>/,"").html_safe if description #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description end + def strip_html(html) + return html if html.empty? || !html.include?('<') + output = "" + tokenizer = HTML::Tokenizer.new(html) + while token = tokenizer.next + node = HTML::Node.parse(nil, 0, 0, token, false) + output += token unless (node.kind_of? HTML::Tag) or (token =~ /^