aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/rails_guides
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2009-03-15 22:16:27 +0100
committerXavier Noria <fxn@hashref.com>2009-03-15 22:16:27 +0100
commita19be732cd0dbdba8dec2014c25539dabd685dfc (patch)
tree249607021fd471b407e90414e6f77e2a04ed4c25 /railties/guides/rails_guides
parenta4b1ccec5c1df24c8f9a18c599575e7263624ac4 (diff)
downloadrails-a19be732cd0dbdba8dec2014c25539dabd685dfc.tar.gz
rails-a19be732cd0dbdba8dec2014c25539dabd685dfc.tar.bz2
rails-a19be732cd0dbdba8dec2014c25539dabd685dfc.zip
guides generator warns about duplicate header IDs
Diffstat (limited to 'railties/guides/rails_guides')
-rw-r--r--railties/guides/rails_guides/generator.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb
index 3dffe372e3..8e69af5bde 100644
--- a/railties/guides/rails_guides/generator.rb
+++ b/railties/guides/rails_guides/generator.rb
@@ -137,12 +137,27 @@ module RailsGuides
end
def warn_about_broken_links(html)
+ anchors = extract_anchors(html)
+ check_fragment_identifiers(html, anchors)
+ end
+
+ def extract_anchors(html)
# Textile generates headers with IDs computed from titles.
- anchors = Set.new(html.scan(/<h\d\s+id="([^"]+)/).flatten)
+ anchors = Set.new
+ html.scan(/<h\d\s+id="([^"]+)/).flatten.each do |anchor|
+ if anchors.member?(anchor)
+ puts "*** DUPLICATE HEADER ID: #{anchor}, please consider rewording"
+ else
+ anchors << anchor
+ end
+ end
+
# Also, footnotes are rendered as paragraphs this way.
anchors += Set.new(html.scan(/<p\s+class="footnote"\s+id="([^"]+)/).flatten)
-
- # Check fragment identifiers.
+ return anchors
+ end
+
+ def check_fragment_identifiers(html, anchors)
html.scan(/<a\s+href="#([^"]+)/).flatten.each do |fragment_identifier|
next if fragment_identifier == 'mainCol' # in layout, jumps to some DIV
unless anchors.member?(fragment_identifier)