Module: Palapala::HTMLPreprocessor

Defined in:
lib/palapala/html_preprocessor.rb

Overview

Helper module for preparing HTML for conversion

Sourced from the PDFKit project (through ferrum_pdf)

Class Method Summary collapse

Class Method Details

.process(html, base_url) ⇒ Object

Change relative paths to absolute, and relative protocols to absolute protocols

process("Some HTML", "https://example.org")


11
12
13
14
15
16
17
18
19
# File 'lib/palapala/html_preprocessor.rb', line 11

def self.process(html, base_url)
  return html if base_url.blank?

  base_url += "/" unless base_url.end_with? "/"
  protocol = base_url.split("://").first
  html = translate_relative_paths(html, base_url) if base_url
  html = translate_relative_protocols(html, protocol) if protocol
  html
end