Sha256: 0ea784dc7cb3ee1a4ebfe7500cea85ecc6a48cc61ff004dfe2a37fdffea493c1
Contents?: true
Size: 724 Bytes
Versions: 11
Compression:
Stored size: 724 Bytes
Contents
require "dtext/dtext" require "nokogiri" module DTextRagel class Error < StandardError; end def self.parse_inline(str) parse(str, :inline => true) end def self.parse_strip(str) parse(str, :strip => true) end def self.parse(str, strip: false, inline: false, disable_mentions: false, base_url: nil) html = c_parse(str, strip, inline, disable_mentions) html = resolve_relative_urls(html, base_url) if base_url html end private def self.resolve_relative_urls(html, base_url) nodes = Nokogiri::HTML.fragment(html) nodes.traverse do |node| if node[:href]&.start_with?("/") node[:href] = base_url.chomp("/") + node[:href] end end nodes.to_s end end
Version data entries
11 entries across 11 versions & 1 rubygems