11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/viewmd.rb', line 11
def self.view(name)
Tempfile.create(["viewmd-#{name}-",'.htm'],Dir.tmpdir,File::CREAT|File::TRUNC|File::RDWR, 0600) do |f|
pipeline = HTML::Pipeline.new [
HTML::Pipeline::MarkdownFilter,
HTML::Pipeline::SanitizationFilter,
HTML::Pipeline::AutolinkFilter,
HTML::Pipeline::SyntaxHighlightFilter
], gfm: true
result = pipeline.call File.read(name)
f << "<!DOCTYPE html><html><head><style>"
f << "pre { background-color: #f7f7f7; padding: 16px; font-size: 85%; margin-bottom: 16px; line-height: 1.45; }"
f << open('https://raw.githubusercontent.com/aahan/pygments-github-style/master/github.css').read
f << "</style></head><body>"
f << result[:output].to_s
f << "</body></html>"
f.flush
Launchy.open(f.path)
sleep 2
end
end
|