# encoding: UTF-8 module Publishr class HtmlProcessor def initialize(markup='',inpath='',metadata={},rails_resources_url='') @markup = markup @lines = markup.split("\n") @line = '' @inpath = inpath @metadata = metadata @rails_resources_url = rails_resources_url @custom_fixes = File.open(File.join(@inpath,'html_postprocessing.rb'), 'r').read if File.exists?(File.join(@inpath,'html_postprocessing.rb')) @depth = 0 @quotetype = nil @add_footnote = false @process_footnotes = false @footnote_number = 0 @footnote_reference = '' end def self.sanitize(html) Sanitize.clean(html, :elements => ['b','i','em','strong','code','br','var','p','blockquote','img','span'], :attributes => { 'img' => ['src', 'alt'] }) end def degrade processed_lines = [] @lines.each do |l| @line = l process_line processed_lines << @line end processed_lines.join("\n") end def process_line @process_footnotes = true if @line.include?('
/){ "
" } @footnote_reference = /
[#{ @footnote_number }]: " @add_footnote = false end def make_footnote_paragraph @line.gsub! /
' @line.gsub! '=======', '
' @line.gsub! /»»».*$/, '
' end end end