Skip to content

Commit

Permalink
Fixes .md link rewriter plugin to work with {% include %} as well
Browse files Browse the repository at this point in the history
  • Loading branch information
netj committed Feb 14, 2016
1 parent 1b39dbd commit a647aed
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions doc/_plugins/rewrite_md_links.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# A plugin to rewrite GitHub-friendly .md links to ones without the extension for the website
begin
# jekyll >= 3.x
Jekyll::Hooks.register :pages, :pre_render do |page|
page.content = page.content.gsub(/(\[[^\]]*\]\([^:\)]*)\.md(#[^)]*)?\)/, '\1\2)')
Jekyll::Hooks.register :pages, :pre_render, priority: :lowest do |page|
# manipulate Markdown links to drop .md extensions
#STDERR.puts "rewrite_md_links.rb: pre_render #{page.url}" if page.content.match(/(\[[^\]]*\]\([^:\)]*)\.md(#[^\)]*)?\)/)
page.content = page.content.gsub(/(\[[^\]]*\]\([^:\)]*)\.md(#[^\)]*)?\)/, '\1\2)')
end
Jekyll::Hooks.register :pages, :post_render do |page|
# need to manipulate HTML links as well because Markdown from {% include ... %} don't go through :pre_render
#STDERR.puts "rewrite_md_links.rb: post_render #{page.url}" if page.output.match(/href="([^":]+)\.md(#[^"]*)?"/)
page.output = page.output.gsub(/href="([^":]+)\.md(#[^"]*)?"/, 'href="\1\2"')
end
rescue
# jekyll <= 2.x
Expand Down

0 comments on commit a647aed

Please sign in to comment.