Welcome to mirror list, hosted at ThFree Co, Russian Federation.

markdown_to_html_ext.rb « filters « lib - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9ab372ba41d42fc9df137def2e21bd00eb529dcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

module Nanoc::Filters
  class MarkdownToHtmlExt < Nanoc::Filter
    identifier :md_to_html_ext

    # Convert internal URLs that link to `.md` files to instead link to
    # { }`.html` files since that's what Nanoc actually serves.
    def run(content, params = {})
      content.gsub(/href="(\S*.md\S*)"/) do |result| # Fetch all links in the HTML Document
        if /^href="http/.match(result).nil? # Check if link is internal
          result.gsub!(/\.md/, '.html') # Replace the extension if link is internal
        end

        result
      end
    end
  end
end