Sha256: 31039b0103a6db2f6275af008a435c239e99712db7a1541b25aac1cd03378645

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

<%
if File.exists? file
	markdown = Redcarpet::Markdown.new Redcarpet::Render::HTML, tables: true, no_intra_emphasis: true
	contents = markdown.render File.read(file)
	contents = contents.gsub("<table>", "<table class='ui celled table'>")
	contents = contents.gsub("<img ", "<img class='ui fluid image'")
	contents = contents.gsub(/<img[^>]+src=(['"])([^'"]+)\1[^>]*>/i) { |match|

		next $2 if $2.include? "//"

		# Attempt to find the refrenced file
		img = File.expand_path($2, File.dirname(file))
		next $2 unless File.exists? img

		# Only allow images through
		mime_type = MIME::Types.type_for(File.extname img).first.to_s
		next $2 unless mime_type.start_with? "image/"

		# Base64 encode & inline the image
		match.sub $2, "data:#{mime_type};base64,#{Base64.encode64(File.read img)}"

	}
%>
	<div class="rendered-markdown">
		<%= contents %>
	</div>
<% else %>
	<div class="ui warning message">
		<div class="header">No markdown file found</div>
		The file <code><%= file %></code> does not exist.
	</div>
<% end %>

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pg-doc-0.0.4 views/includes/markdown.erb
pg-doc-0.0.3 views/includes/markdown.erb
pg-doc-0.0.2 views/includes/markdown.erb
pg-doc-0.0.1 views/includes/markdown.erb