Class: TinyWiki::App::WikiLinkRenderer
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- TinyWiki::App::WikiLinkRenderer
- Defined in:
- lib/tiny_wiki/app.rb
Overview
Custom Redcarpet renderer to handle wiki links (e.g., [[Page Name]])
Instance Method Summary collapse
-
#postprocess(full_document) ⇒ Object
The postprocess method is called after all other rendering is complete.
Instance Method Details
#postprocess(full_document) ⇒ Object
The postprocess method is called after all other rendering is complete. We use it to find and replace our custom wiki link syntax.
26 27 28 29 30 31 32 33 |
# File 'lib/tiny_wiki/app.rb', line 26 def postprocess(full_document) full_document.gsub(/\[\[(.*?)\]\]/) do page_name = $1.strip # Get the text inside the brackets # Sanitize page name for URL: replace spaces with underscores, then URI encode url_safe_page_name = URI.encode_www_form_component(page_name.gsub(' ', '_')) "<a href=\"/#{url_safe_page_name}\">#{page_name}</a>" end end |