class Object
Constants
- DB
- LINK_REGEX
Public Instance Methods
content_for(item, front_matter = {})
click to toggle source
# File bin/pombola_extract_info_pages, line 32 def content_for(item, front_matter = {}) <<CONTENT #{YAML.dump(front_matter)}--- #{tidy_markdown(item[:markdown_content])} CONTENT end
tidy_markdown(markdown)
click to toggle source
# File bin/pombola_extract_info_pages, line 12 def tidy_markdown(markdown) markdown.tr!("\r\n", "\n") markdown.gsub!(/\n+$/, "\n") markdown.gsub!("\n\n**\n", "**\n") markdown.strip! links = markdown.to_enum(:scan, LINK_REGEX).map { Regexp.last_match } return markdown unless links.any? links.each do |link| if link[:title] == '""' # Get rid of empty title markdown.sub!(link.to_s, "[#{link[:text].strip}](#{link[:url].strip})") end if !link[:url].lstrip.start_with?('/') && !link[:url].lstrip.start_with?('http') # Fix relative links to be absolute markdown.sub!(link.to_s, "[#{link[:text].strip}](/info/#{link[:url].strip})") end end markdown end