Sha256: 0418edd91bf49d087a7732c0e04da095553d065f4a4b3af8a88f4d48a740a22d
Contents?: true
Size: 1.05 KB
Versions: 4
Compression:
Stored size: 1.05 KB
Contents
# encoding: UTF-8 module Sterile class << self # Format text with proper "curly" quotes, m-dashes, copyright, trademark, etc. # # q{"He said, 'Away with you, Drake!'"}.smart_format # => “He said, ‘Away with you, Drake!’” # def smart_format(string) smart_format_rules.each do |rule| string.gsub! rule[0], rule[1] end string end # Like +smart_format+, but works with HTML/XML (somewhat). # def smart_format_tags(string) string = string.gsub /[\p{Z}\s]+(<\/[a-zA-Z]+>)(['"][a-zA-Z])/, "\\1 \\2" # Fixes quote after whitespace + tag "<em>Dan. </em>'And" string.gsub_tags do |text| text.smart_format end.encode_entities.gsub(/(\<\/\w+\>)“/, "\\1”").gsub(/(\<\/\w+\>)‘/, "\\1’") end private # Lazy load smart formatting rules # def smart_format_rules @smart_format_rules ||= begin require "sterile/data/smart_format_rules" Data.smart_format_rules end end end # class << self end # module Sterile
Version data entries
4 entries across 4 versions & 2 rubygems