# encoding: utf-8 require 'inky' def reformat_html(html) html .gsub(/\s+/, ' ') # Compact all whitespace to a single space .gsub(/> *\n<") # Use returns between tags .gsub(%r{<(\w+)([^>]*)>\n}, '<\1\2/>') # Auto close empty tags, e.g.
\n =>
.gsub(/ "/, '"').gsub(/\=" /, '="') # Remove leading/trailing spaces inside attributes .gsub(/ /, '>') # Remove leading/trailing spaces inside tags .gsub(' data-parsed=""', '') # Don't consider this known inky-node artefact .gsub(' data-parsed>', '>') # Ditto .gsub(' ', ' ') # These are the same entity... .gsub(/(align="[^"]+") (class="[^"]+")/, '\2 \1') # Tweak order to match inky-node on container .gsub(/class\="([^"]+)"/) do # Sort class names classes = $1.split(' ').sort.join(' ') %{class="#{classes}"} end .gsub(/