markshi 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'markshi'
4
+ require 'digest/sha1'
5
+ require 'tmpdir'
6
+
7
+ include Markshi
8
+
9
+ filename = ARGV[0];
10
+
11
+ if (ARGV.size < 1)
12
+ abort "Usage: #{$0} <markdown file>"
13
+ end
14
+
15
+ title = File.basename(filename).gsub(/\.(markdown|md)/m, '')
16
+ content = File.read(filename)
17
+
18
+ (toc, html) = markdownize(content)
19
+ output = layout(title, toc, decorate_boxes(highlight_code(html)))
20
+ hash = Digest::SHA1::hexdigest(output)
21
+
22
+ tmpfile = "#{Dir.tmpdir}/markshi-#{hash}.html"
23
+ File.open(tmpfile, 'w+') do |f|
24
+ f.puts output
25
+ end
26
+
27
+ puts "created new html file #{tmpfile}"
28
+
29
+ `open #{tmpfile} || gnome-open #{tmpfile}`
30
+
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rdiscount'
5
+ require 'coderay'
6
+ require 'erb'
7
+
8
+ module Markshi
9
+ def markdownize(text)
10
+ rd = RDiscount.new(text, :smart, :generate_toc)
11
+ [rd.toc_content, rd.to_html]
12
+ end
13
+
14
+ def highlight_code(text)
15
+ text.gsub(/<pre><code>(\[(\w+)\])?\n([^<]+)<\/code><\/pre>/m) do
16
+ CodeRay.scan($3, $2).div(:css => :class).gsub('&amp;', '&')
17
+ end
18
+ end
19
+
20
+ def decorate_boxes(text)
21
+ boxes = %w[note quote caution tip]
22
+ boxes = boxes.join '|'
23
+ text.gsub(/<blockquote><p><strong>(#{boxes})<\/strong>/mi) do
24
+ "<blockquote class=\"#{$1}\"><p>".downcase
25
+ end
26
+ end
27
+
28
+ def layout(title, toc, text, template = 'default')
29
+ templates_dir = File.expand_path('../../templates', __FILE__)
30
+ template = ERB.new(File.read("#{templates_dir}/#{template}.erb.html"))
31
+ template.result(binding)
32
+ end
33
+ end
34
+
@@ -0,0 +1,4 @@
1
+ module Markshi
2
+ VERSION = "0.0.2"
3
+ end
4
+
@@ -0,0 +1,121 @@
1
+ .CodeRay {
2
+ background-color: #f8f8f8;
3
+ border: 1px solid silver;
4
+ font-family: 'Courier New', 'Terminal', monospace;
5
+ color: #000;
6
+ }
7
+ .CodeRay pre { margin: 0px; }
8
+
9
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px; }
10
+
11
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px; }
12
+ table.CodeRay td { padding: 2px 4px; vertical-align: top; }
13
+
14
+ .CodeRay .line_numbers, .CodeRay .no {
15
+ background-color: #def;
16
+ color: gray;
17
+ text-align: right;
18
+ }
19
+ .CodeRay .line_numbers a:target, .CodeRay .no a:target { color: blue; }
20
+ .CodeRay .line_numbers .highlighted, .CodeRay .no .highlighted { color: red; }
21
+ .CodeRay .no { padding: 0px 4px; }
22
+ .CodeRay .code { width: 100%; }
23
+ .CodeRay .code pre { overflow: auto; }
24
+
25
+ .CodeRay .debug { color:white ! important; background:blue ! important; }
26
+
27
+ .CodeRay .an { color:#007 }
28
+ .CodeRay .at { color:#f08 }
29
+ .CodeRay .av { color:#700 }
30
+ .CodeRay .bi { color:#509; font-weight:bold }
31
+ .CodeRay .c { color:#888; }
32
+ .CodeRay .c .dl { color:#444; }
33
+ .CodeRay .c .ch { color:#444; }
34
+
35
+ .CodeRay .ch { color:#04D }
36
+ .CodeRay .ch .k { color:#04D }
37
+ .CodeRay .ch .dl { color:#039 }
38
+
39
+ .CodeRay .cl { color:#B06; font-weight:bold }
40
+ .CodeRay .cm { color:#A08; font-weight:bold }
41
+ .CodeRay .co { color:#036; font-weight:bold }
42
+ .CodeRay .cr { color:#0A0 }
43
+ .CodeRay .cv { color:#369 }
44
+ .CodeRay .de { color:#B0B; }
45
+ .CodeRay .df { color:#099; font-weight:bold }
46
+ .CodeRay .di { color:#088; font-weight:bold }
47
+ .CodeRay .dl { color:black }
48
+ .CodeRay .do { color:#970 }
49
+ .CodeRay .dt { color:#34b }
50
+ .CodeRay .ds { color:#D42; font-weight:bold }
51
+ .CodeRay .e { color:#666; font-weight:bold }
52
+ .CodeRay .en { color:#800; font-weight:bold }
53
+ .CodeRay .er { color:#F00; background-color:#FAA }
54
+ .CodeRay .ex { color:#C00; font-weight:bold }
55
+ .CodeRay .fl { color:#60E; font-weight:bold }
56
+ .CodeRay .fu { color:#06B; font-weight:bold }
57
+ .CodeRay .gv { color:#d70; font-weight:bold }
58
+ .CodeRay .hx { color:#058; font-weight:bold }
59
+ .CodeRay .i { color:#00D; font-weight:bold }
60
+ .CodeRay .ic { color:#B44; font-weight:bold }
61
+
62
+ .CodeRay .il { background-color: hsla(0,0%,0%,0.1); color: black }
63
+ .CodeRay .il .idl { font-weight: bold; color: #666 }
64
+ .CodeRay .idl { font-weight: bold; color: #666; }
65
+
66
+ .CodeRay .im { color:#f00; }
67
+ .CodeRay .in { color:#B2B; font-weight:bold }
68
+ .CodeRay .iv { color:#33B }
69
+ .CodeRay .la { color:#970; font-weight:bold }
70
+ .CodeRay .lv { color:#963 }
71
+ .CodeRay .ns { color:#707; font-weight:bold }
72
+ .CodeRay .oc { color:#40E; font-weight:bold }
73
+ .CodeRay .op { }
74
+ .CodeRay .pc { color:#058; font-weight:bold }
75
+ .CodeRay .pd { color:#369; font-weight:bold }
76
+ .CodeRay .pp { color:#579; }
77
+ .CodeRay .ps { color:#00C; font-weight:bold }
78
+ .CodeRay .pt { color:#074; font-weight:bold }
79
+ .CodeRay .r, .kw { color:#080; font-weight:bold }
80
+
81
+ .CodeRay .ke { color: #808; }
82
+ .CodeRay .ke .dl { color: #606; }
83
+ .CodeRay .ke .ch { color: #80f; }
84
+ .CodeRay .vl { color: #088; }
85
+
86
+ .CodeRay .rx { background-color:hsla(300,100%,50%,0.1); color:#808 }
87
+ .CodeRay .rx .k { }
88
+ .CodeRay .rx .dl { color:#404 }
89
+ .CodeRay .rx .mod { color:#C2C }
90
+ .CodeRay .rx .fu { color:#404; font-weight: bold }
91
+
92
+ .CodeRay .s { background-color:hsla(0,100%,50%,0.1); color: #D20; }
93
+ .CodeRay .s .k { }
94
+ .CodeRay .s .ch { color: #b0b; }
95
+ .CodeRay .s .dl { color: #710; }
96
+
97
+ .CodeRay .sh { background-color:hsla(120,100%,50%,0.1); color:#2B2 }
98
+ .CodeRay .sh .k { }
99
+ .CodeRay .sh .dl { color:#161 }
100
+
101
+ .CodeRay .sy { color:#A60 }
102
+ .CodeRay .sy .k { color:#A60 }
103
+ .CodeRay .sy .dl { color:#630 }
104
+
105
+ .CodeRay .ta { color:#070 }
106
+ .CodeRay .ts { color:#D70; font-weight:bold }
107
+ .CodeRay .ty { color:#339; font-weight:bold }
108
+ .CodeRay .v { color:#036 }
109
+ .CodeRay .xt { color:#444 }
110
+
111
+ .CodeRay .ins { background: #afa; }
112
+ .CodeRay .del { background: #faa; }
113
+ .CodeRay .chg { color: #aaf; background: #007; }
114
+ .CodeRay .head { color: #f8f; background: #505 }
115
+ .CodeRay .head .filename { color: white; }
116
+
117
+ .CodeRay .ins .ins { color: #080; font-weight:bold }
118
+ .CodeRay .del .del { color: #800; font-weight:bold }
119
+ .CodeRay .chg .chg { color: #66f; }
120
+ .CodeRay .head .head { color: #f4f; }
121
+
@@ -0,0 +1,26 @@
1
+ pre
2
+ {
3
+ background-color: black;
4
+ color: white;
5
+ padding: 1em;
6
+ }
7
+
8
+ .CodeRay .c
9
+ {
10
+ color: #BD48B3;
11
+ font-style: italic;
12
+ }
13
+
14
+ .CodeRay .r
15
+ {
16
+ color: #FFCC66;
17
+ font-weight: normal;
18
+ }
19
+
20
+ .CodeRay .fu,
21
+ .CodeRay .cl
22
+ {
23
+ color: white;
24
+ font-weight: normal;
25
+ }
26
+
@@ -0,0 +1,62 @@
1
+ html, body
2
+ {
3
+ padding: 0;
4
+ margin: 0;
5
+ font-family: Verdana, Tahoma, Arial, sans-serif;
6
+ }
7
+
8
+ .container
9
+ {
10
+ background-color: white;
11
+ }
12
+
13
+ .article
14
+ {
15
+ width: 90%;
16
+ margin: 0 auto;
17
+ }
18
+
19
+ .footer
20
+ {
21
+ text-align: center;
22
+ }
23
+
24
+ blockquote.note,
25
+ blockquote.caution,
26
+ blockquote.tip
27
+ {
28
+ font-weight: normal;
29
+ min-height: 3.6em;
30
+ padding: 0.6em 2em 0.6em 3.6em;
31
+ margin: 1em 0;
32
+ border-top: 1px solid #ddd;
33
+ border-bottom: 1px solid #ddd;
34
+ background-color: #ffd;
35
+ background-repeat: no-repeat;
36
+ background-position: 1em 1.2em;
37
+ }
38
+
39
+ blockquote.note
40
+ {
41
+ background-image: url('../images/note.png');
42
+ }
43
+
44
+ blockquote.caution
45
+ {
46
+ background-image: url('../images/caution.png');
47
+ }
48
+
49
+ blockquote.tip
50
+ {
51
+ background-image: url('../images/tip.png');
52
+ }
53
+
54
+ blockquote.quote
55
+ {
56
+ margin: 2em 4em;
57
+ min-height: 4em;
58
+ color: #575757;
59
+ padding: 0 3.5em;
60
+ background: transparent url('../images/blockquote.gif') no-repeat 0 0;
61
+ }
62
+
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE HTML>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5
+ <link rel="stylesheet" type="text/css" href="<%= "#{templates_dir}/css/coderay.css" %>" />
6
+ <link rel="stylesheet" type="text/css" href="<%= "#{templates_dir}/css/main.css" %>" />
7
+ <link rel="stylesheet" type="text/css" href="<%= "#{templates_dir}/css/default.css" %>" />
8
+ <title><%= title %></title>
9
+ </head>
10
+ <body>
11
+ <div class="container">
12
+ <div class="header">
13
+ <h1><%= title %></h1>
14
+ </div>
15
+ <div class="article">
16
+ <div class="toc">
17
+ <%= toc %>
18
+ </div>
19
+ <div class="text">
20
+ <%= text %>
21
+ </div>
22
+ </div>
23
+ <div class="footer">
24
+ <small>Generated by Markshi - <%= Time.now().strftime('%c') %></small>
25
+ </div>
26
+ </div>
27
+ </body>
28
+ </html>
29
+
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markshi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Cestari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-09-06 00:00:00 -04:30
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rdiscount
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: coderay
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Tool to make Markdown authoring easier by providing fast and good looking previews
36
+ email:
37
+ - dcestari@gmail.com
38
+ executables:
39
+ - markshi
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - lib/markshi.rb
46
+ - lib/markshi/version.rb
47
+ - templates/css/default.css
48
+ - templates/css/main.css
49
+ - templates/css/coderay.css
50
+ - templates/images/caution.png
51
+ - templates/images/blockquote.gif
52
+ - templates/images/tip.png
53
+ - templates/images/note.png
54
+ - templates/default.erb.html
55
+ has_rdoc: true
56
+ homepage: http://github.com/dcestari/markshi
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.3.5
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Markdown to HTML (previewer)
83
+ test_files: []
84
+