Class: JsDuck::GuideAnchors
- Inherits:
-
Object
- Object
- JsDuck::GuideAnchors
- Defined in:
- lib/jsduck/guide_anchors.rb
Overview
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 Method Summary collapse
Class Method Details
.transform(html, guide_name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jsduck/guide_anchors.rb', line 10 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 |
.transform_id(id, guide_name) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/jsduck/guide_anchors.rb', line 22 def self.transform_id(id, guide_name) if id =~ /^#{guide_name}-section-/ id else "#{guide_name}-section-#{id}" end end |