Sha256: 95b319b443f72fedaf98b024de9c14d7f625e547d1892aa5ba8eacde47a7b9a4
Contents?: true
Size: 914 Bytes
Versions: 7
Compression:
Stored size: 914 Bytes
Contents
module JsDuck # Transforms in-page links so they won't break docs app #!-navigation. # # For example a link to "#automation" in testing guide will be # replaced with "#!/guide/testing-section-automation" and the link # target ID will be transformed into "testing-section-automation". class GuideAnchors def self.transform(html, guide_name) html.gsub(/(<a\s+(?:[^<>]*\s+)?href=['"]#)([^!\/].*?)(['"])/i) do |m| "#{$1}!/guide/#{guide_name}-section-#{$2}#{$3}" end.gsub(/(<a\s+(?:[^<>]*\s+)?name=['"])(.*?)(['"])/i) do |m| $1 + transform_id($2, guide_name) + $3 end.gsub(/(<\w+\s+(?:[^<>]*\s+)?id=['"])(.*?)(['"])/i) do |m| $1 + transform_id($2, guide_name) + $3 end end def self.transform_id(id, guide_name) if id =~ /^#{guide_name}-section-/ id else "#{guide_name}-section-#{id}" end end end end
Version data entries
7 entries across 7 versions & 1 rubygems