Loading lib/jsduck/doc_formatter.rb +4 −7 Original line number Diff line number Diff line Loading @@ -2,10 +2,10 @@ require 'rubygems' require 'rdiscount' require 'strscan' require 'cgi' require 'jsduck/logger' require 'jsduck/inline_img' require 'jsduck/inline_video' require 'jsduck/html' module JsDuck Loading Loading @@ -274,7 +274,7 @@ module JsDuck when '%-' member ? "-" : "" when '%a' CGI.escapeHTML(anchor_text||"") HTML.escape(anchor_text||"") else $1 end Loading Loading @@ -327,7 +327,7 @@ module JsDuck # Blah blah blah some text. # def shorten(input) sent = first_sentence(strip_tags(input)) sent = first_sentence(HTML.strip_tags(input).strip) # Use u-modifier to correctly count multi-byte characters chars = sent.scan(/./mu) if chars.length > @max_length Loading @@ -343,15 +343,12 @@ module JsDuck # Returns true when input should get shortened. def too_long?(input) stripped = strip_tags(input) stripped = HTML.strip_tags(input).strip # for sentence v/s full - compare byte length # for full v/s max - compare char length first_sentence(stripped).length < stripped.length || stripped.scan(/./mu).length > @max_length end def strip_tags(str) str.gsub(/<.*?>/, "").strip end end end lib/jsduck/guides.rb +2 −4 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ require 'jsduck/io' require 'jsduck/null_object' require 'jsduck/logger' require 'jsduck/grouped_asset' require 'jsduck/html' require 'fileutils' module JsDuck Loading Loading @@ -111,7 +112,7 @@ module JsDuck html.each_line do |line| if line =~ /^<h2>(.*)<\/h2>$/ i += 1 text = strip_tags($1) text = HTML.strip_tags($1) toc << "<li><a href='#!/guide/#{guide['name']}-section-#{i}'>#{text}</a></li>\n" new_html << "<h2 id='#{guide['name']}-section-#{i}'>#{text}</h2>\n" else Loading Loading @@ -152,9 +153,6 @@ module JsDuck "guides/" + guide["name"] + "/icon.png" end def strip_tags(str) str.gsub(/<.*?>/, "") end end end lib/jsduck/html.rb 0 → 100644 +25 −0 Original line number Diff line number Diff line require 'cgi' module JsDuck # Helpers for dealing with HTML class HTML # Strips tags from HTML text def self.strip_tags(html) html.gsub(/<.*?>/, "") end # Escapes HTML, replacing < with < ... def self.escape(html) CGI.escapeHTML(html) end # Unescapes HTML, replacing < with < ... def self.unescape(html) CGI.unescapeHTML(html) end end end lib/jsduck/inline_examples.rb +2 −5 Original line number Diff line number Diff line require 'jsduck/json_duck' require 'cgi' require 'jsduck/html' module JsDuck Loading Loading @@ -65,7 +65,7 @@ module JsDuck ex = s.scan_until(@end_example_re).sub(@end_example_re, '') examples << { :code => CGI.unescapeHTML(strip_tags(ex)), :code => HTML.unescape(HTML.strip_tags(ex)), :options => options, } else Loading @@ -89,9 +89,6 @@ module JsDuck hash end def strip_tags(str) str.gsub(/<.*?>/, "") end end end lib/jsduck/inline_img.rb +2 −2 Original line number Diff line number Diff line require 'cgi' require 'jsduck/html' require 'jsduck/logger' module JsDuck Loading Loading @@ -42,7 +42,7 @@ module JsDuck when '%u' @base_path ? (@base_path + "/" + url) : url when '%a' CGI.escapeHTML(alt_text||"") HTML.escape(alt_text||"") else $1 end Loading Loading
lib/jsduck/doc_formatter.rb +4 −7 Original line number Diff line number Diff line Loading @@ -2,10 +2,10 @@ require 'rubygems' require 'rdiscount' require 'strscan' require 'cgi' require 'jsduck/logger' require 'jsduck/inline_img' require 'jsduck/inline_video' require 'jsduck/html' module JsDuck Loading Loading @@ -274,7 +274,7 @@ module JsDuck when '%-' member ? "-" : "" when '%a' CGI.escapeHTML(anchor_text||"") HTML.escape(anchor_text||"") else $1 end Loading Loading @@ -327,7 +327,7 @@ module JsDuck # Blah blah blah some text. # def shorten(input) sent = first_sentence(strip_tags(input)) sent = first_sentence(HTML.strip_tags(input).strip) # Use u-modifier to correctly count multi-byte characters chars = sent.scan(/./mu) if chars.length > @max_length Loading @@ -343,15 +343,12 @@ module JsDuck # Returns true when input should get shortened. def too_long?(input) stripped = strip_tags(input) stripped = HTML.strip_tags(input).strip # for sentence v/s full - compare byte length # for full v/s max - compare char length first_sentence(stripped).length < stripped.length || stripped.scan(/./mu).length > @max_length end def strip_tags(str) str.gsub(/<.*?>/, "").strip end end end
lib/jsduck/guides.rb +2 −4 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ require 'jsduck/io' require 'jsduck/null_object' require 'jsduck/logger' require 'jsduck/grouped_asset' require 'jsduck/html' require 'fileutils' module JsDuck Loading Loading @@ -111,7 +112,7 @@ module JsDuck html.each_line do |line| if line =~ /^<h2>(.*)<\/h2>$/ i += 1 text = strip_tags($1) text = HTML.strip_tags($1) toc << "<li><a href='#!/guide/#{guide['name']}-section-#{i}'>#{text}</a></li>\n" new_html << "<h2 id='#{guide['name']}-section-#{i}'>#{text}</h2>\n" else Loading Loading @@ -152,9 +153,6 @@ module JsDuck "guides/" + guide["name"] + "/icon.png" end def strip_tags(str) str.gsub(/<.*?>/, "") end end end
lib/jsduck/html.rb 0 → 100644 +25 −0 Original line number Diff line number Diff line require 'cgi' module JsDuck # Helpers for dealing with HTML class HTML # Strips tags from HTML text def self.strip_tags(html) html.gsub(/<.*?>/, "") end # Escapes HTML, replacing < with < ... def self.escape(html) CGI.escapeHTML(html) end # Unescapes HTML, replacing < with < ... def self.unescape(html) CGI.unescapeHTML(html) end end end
lib/jsduck/inline_examples.rb +2 −5 Original line number Diff line number Diff line require 'jsduck/json_duck' require 'cgi' require 'jsduck/html' module JsDuck Loading Loading @@ -65,7 +65,7 @@ module JsDuck ex = s.scan_until(@end_example_re).sub(@end_example_re, '') examples << { :code => CGI.unescapeHTML(strip_tags(ex)), :code => HTML.unescape(HTML.strip_tags(ex)), :options => options, } else Loading @@ -89,9 +89,6 @@ module JsDuck hash end def strip_tags(str) str.gsub(/<.*?>/, "") end end end
lib/jsduck/inline_img.rb +2 −2 Original line number Diff line number Diff line require 'cgi' require 'jsduck/html' require 'jsduck/logger' module JsDuck Loading Loading @@ -42,7 +42,7 @@ module JsDuck when '%u' @base_path ? (@base_path + "/" + url) : url when '%a' CGI.escapeHTML(alt_text||"") HTML.escape(alt_text||"") else $1 end Loading