Tag: 整洁

TextMate中的^ H用’Tidy’HTML导致NoMethodError

昨天我第一次尝试在HTML文档中使用’Tidy’,并得到了…… /tmp/temp_textmate.Z2P0KX:30:in `’: undefined method `empty?’ for nil:NilClass (NoMethodError) 我没有对包中的代码做任何事情…… #!/usr/bin/env ruby -wKU require ENV[‘TM_SUPPORT_PATH’] + ‘/lib/ui.rb’ require ENV[‘TM_SUPPORT_PATH’] + ‘/lib/exit_codes.rb’ result = `”${TM_TIDY:-tidy}” -f /tmp/tm_tidy_errors -iq -utf8 \ -wrap 0 –tab-size $TM_TAB_SIZE –indent-spaces $TM_TAB_SIZE \ –indent yes \ ${TM_XHTML:+-asxhtml –output-xhtml yes} \ ${TM_SELECTED_TEXT:+–show-body-only yes} \ –enclose-text yes \ –doctype strict \ –wrap-php no \ […]

使用Nokogiri清洁HTML(而不是整洁)

tidygem不再维护,并且有多个内存泄漏问题。 有人建议使用Nokogiri。 我目前正在使用以下方法清理HTML: Nokogiri::HTML::DocumentFragment.parse(html).to_html 我有两个问题: Nokogiri删除了DOCTYPE 是否有一种简单的方法可以强制清理HTML以获得html和body标签?