Permalink
Browse files

Support single or double quotes in anchor tags for quicklinks plugin.

  • Loading branch information...
1 parent 5031311 commit 6df1a13c00b0e5b6ff41d979088d50bccac72a0c @scottfrederick scottfrederick committed Mar 7, 2013
Showing with 43 additions and 27 deletions.
  1. +4 −0 config.rb
  2. +0 −27 navigation.rb
  3. +39 −0 quicklinks.rb
View
@@ -48,6 +48,7 @@
# end
require 'navigation'
+require 'quicklinks'
set :markdown_engine, :redcarpet
set :markdown, :layout_engine => :erb,
@@ -91,6 +92,9 @@
# For navigation breadcrumbs
activate :navigation
+# For generated intra-page links
+activate :quicklinks
+
helpers do
class Middleman::Sitemap::Page
def banner_url
View
@@ -1,8 +1,5 @@
# mostly from https://github.com/multiscan/middleman-navigation but modified slightly
module Navigation
-
- require 'redcarpet'
-
class << self
def registered(app)
app.helpers HelperMethods
@@ -62,30 +59,6 @@ def children_nav(options={})
return content_tag :ul, menu_content, options
end
- def quick_links()
- links = []
- page_src = File.read(current_page.source_file)
- sections = page_src.scan /\n\#{2,3}[^#]+\#{2,3}\n/
-
- markdown = ''
-
- sections.each do |s|
-
- next if s.match(/id='(.+)'/).nil? or s.match(/<\/a>([^#.]+)\#{2,3}/).nil?
-
- anchor_name = s.match(/id='(.+)'/)[1]
- title = s.match(/<\/a>([^#.]+)\#{2,3}/)[1].strip!
- indent = (s.count('#') / 2) - 2
-
- markdown << ' ' * indent
- markdown << "* [#{title}](##{anchor_name})\n"
-
- end
-
- md = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
- md.render(markdown)
- end
-
# create an <ul> list with links to all the parent pages down to the root
def trail_nav() # removed sep
p = current_page
View
@@ -0,0 +1,39 @@
+module QuickLinks
+ require 'redcarpet'
+
+ class << self
+ def registered(app)
+ app.helpers HelperMethods
+ end
+
+ alias :included :registered
+ end
+
+ module HelperMethods
+ def quick_links()
+ links = []
+ page_src = File.read(current_page.source_file)
+ sections = page_src.scan /\n\#{2,3}[^#]+\#{2,3}\n/
+
+ markdown = ''
+
+ sections.each do |s|
+
+ next if s.match(/id=['"](.+)['"]/).nil? or s.match(/<\/a>([^#.]+)\#{2,3}/).nil?
+
+ anchor_name = s.match(/id=['"](.+)['"]/)[1]
+ title = s.match(/<\/a>([^#.]+)\#{2,3}/)[1].strip!
+ indent = (s.count('#') / 2) - 2
+
+ markdown << ' ' * indent
+ markdown << "* [#{title}](##{anchor_name})\n"
+
+ end
+
+ md = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
+ md.render(markdown)
+ end
+ end
+end
+
+::Middleman::Extensions.register(:quicklinks, QuickLinks)

0 comments on commit 6df1a13

Please sign in to comment.