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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tiny_wiki/app.rb', line 34 def postprocess(full_document) full_document.gsub(/\[\[(.*?)\]\]/) do raw_page_path = $1.strip # e.g., "Folder/Page Name" # Split the path into components path_components = raw_page_path.split('/') # Sanitize each component and convert spaces to underscores for the URL # Then URI encode each component url_safe_components = path_components.map do |comp| # Replace spaces with underscores for URL segment sanitized_comp = comp.gsub(' ', '_') # URI encode the individual component URI.encode_www_form_component(sanitized_comp) end # Rejoin with '/' to form the URL path url_path = url_safe_components.join('/') "<a href=\"/#{url_path}\">#{raw_page_path}</a>" end end |