Permalink
Browse files

append markdown reference links for all index entries

  • Loading branch information...
1 parent 634d8e6 commit fcd3bb5736f61a65099b605ce17fe998c99468fb @rtomayko rtomayko committed Jun 17, 2010
Showing with 13 additions and 1 deletion.
  1. +12 −0 lib/ronn/document.rb
  2. +1 −1 lib/ronn/index.rb
View
12 lib/ronn/document.rb
@@ -25,6 +25,9 @@ class Document
# The raw input data, read from path or stream and unmodified.
attr_reader :data
+ # The index used to resolve man and file references.
+ attr_accessor :index
+
# The man pages name: usually a single word name of
# a program or filename; displayed along with the section in
# the left and right portions of the header as well as the bottom
@@ -292,6 +295,7 @@ def strip_heading(html)
def process_markdown!
markdown = markdown_filter_heading_anchors(self.data)
+ markdown_filter_link_index(markdown)
markdown_filter_angle_quotes(markdown)
end
@@ -308,6 +312,14 @@ def process_html!
##
# Filters
+ # Appends all index links to the end of the document as Markdown reference
+ # links. This lets us use [foo(3)][] syntax to link to index entries.
+ def markdown_filter_link_index(markdown)
+ return markdown if index.nil? || index.empty?
+ markdown << "\n\n"
+ index.each { |ref| markdown << "[#{ref.name}]: #{ref.url}\n" }
+ end
+
# Add [id]: #ANCHOR elements to the markdown source text for all sections.
# This lets us use the [SECTION-REF][] syntax
def markdown_filter_heading_anchors(markdown)
View
2 lib/ronn/index.rb
@@ -12,7 +12,7 @@ class Index
def initialize(path, attributes={}, &bk)
@path = path
- @attributes = attributes
+ @attributes = attributes.merge(:index => self)
@references = []
@manuals = {}

0 comments on commit fcd3bb5

Please sign in to comment.