/
app.rb
54 lines (47 loc) · 982 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'sinatra'
require 'rdiscount'
VALID_OPTIONS = [
:smart,
:filter_styles,
:filter_html,
:fold_lines,
:generate_toc,
:no_image,
:no_links,
:no_tables,
:strict,
:autolink,
:safelink,
:no_pseudo_protocols
]
get '/' do
text = File.read('README.md')
markdown = RDiscount.new(text, :smart)
body = markdown.to_html
erb :home, :layout => false, :locals => {:body => body}
end
post '/' do
text = params[:text] or halt 403
text = text[:tempfile].read if Hash === text
options = VALID_OPTIONS.select {|name| params[name] == '1' }
markdown = RDiscount.new(text, *options)
content_type 'text/html'
markdown.to_html
end
__END__
@@ home
<!DOCTYPE html>
<html>
<head>
<title>Markdown as a Service</title>
<style type="text/css">
body {font: 14px Helvetica, sans-serif;padding: 5%;}
#wrapper {width: 500px; margin: 0 auto;}
</style>
</head>
<body>
<div id="wrapper">
<%= body %>
</div>
</body>
</html>