gmd 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gmd +6 -16
- data/lib/gmd/helpers.rb +11 -0
- data/lib/gmd/redcarpet_template_fix.rb +11 -0
- data/lib/gmd/templates/common/header.html.erb +1 -1
- data/lib/gmd/templates/layouts/default/layout.html.erb +2 -2
- data/lib/gmd/templates/layouts/github/layout.html.erb +2 -2
- data/lib/gmd/templates/layouts/metal/layout.html.erb +2 -2
- data/lib/gmd/version.rb +1 -1
- data/lib/gmd.rb +52 -4
- metadata +7 -5
data/bin/gmd
CHANGED
@@ -52,21 +52,11 @@ layout = Gmd::default_layout unless layout
|
|
52
52
|
|
53
53
|
output_file = file.gsub(/\.(md|markdown)\z/, '') + '.html' unless output_file
|
54
54
|
|
55
|
-
Gmd::
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
output =
|
60
|
-
|
61
|
-
:tables => true,
|
62
|
-
:fenced_code_blocks => true,
|
63
|
-
:autolink => true,
|
64
|
-
:strikethrough => true,
|
65
|
-
:lax_html_blocks => true,
|
66
|
-
:space_after_headers => true,
|
67
|
-
:superscript => false
|
68
|
-
).render(File.read(file))
|
69
|
-
|
70
|
-
output = Tilt.new(layout).render(self, Gmd::locals) { output } if layout
|
55
|
+
Gmd::var[:options] = options
|
56
|
+
|
57
|
+
Tilt.prefer Tilt::RedcarpetTemplate
|
58
|
+
|
59
|
+
output = Gmd::tilt_render(file)
|
60
|
+
output = Gmd::tilt_render(layout){ output } if layout
|
71
61
|
|
72
62
|
File.open(output_file, "wb") { |f| f.write(output) }
|
data/lib/gmd/helpers.rb
ADDED
@@ -1,8 +1,8 @@
|
|
1
1
|
<html>
|
2
2
|
<head>
|
3
3
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
4
|
-
<%=
|
5
|
-
<%=
|
4
|
+
<%= layout_meta_tags %>
|
5
|
+
<%= load_common(:header) %>
|
6
6
|
<style>
|
7
7
|
<%= File.read(File.dirname(__FILE__) + "/style.css") %>
|
8
8
|
</style>
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<html>
|
2
2
|
<head>
|
3
3
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
4
|
-
<%=
|
5
|
-
<%=
|
4
|
+
<%= layout_meta_tags %>
|
5
|
+
<%= load_common(:header) %>
|
6
6
|
<style>
|
7
7
|
body {background-color:#f8f8f8;font-family:Helvetica;}
|
8
8
|
h1,h2,h3,h4,h5,h6{border:0;}
|
data/lib/gmd/version.rb
CHANGED
data/lib/gmd.rb
CHANGED
@@ -2,6 +2,8 @@ require "gmd/version"
|
|
2
2
|
require "tilt"
|
3
3
|
require "redcarpet"
|
4
4
|
require "erb"
|
5
|
+
require "gmd/helpers"
|
6
|
+
require "gmd/redcarpet_template_fix"
|
5
7
|
|
6
8
|
module Gmd
|
7
9
|
class << self
|
@@ -54,15 +56,18 @@ module Gmd
|
|
54
56
|
]
|
55
57
|
filepath = choose_file_from_paths(paths)
|
56
58
|
raise "Unable to find file: #{file}" unless filepath
|
57
|
-
|
59
|
+
tilt_render(filepath)
|
58
60
|
end
|
59
61
|
|
62
|
+
# Escapes all markdown symbols found
|
60
63
|
def escape_markdown(str)
|
61
64
|
symbols = "\\`*_{}[]()#+-.!".split('')
|
62
65
|
symbols.each { |s| str.gsub!(s, "\\" + s) }
|
63
66
|
str
|
64
67
|
end
|
65
68
|
|
69
|
+
# Used to find and autoescape LaTeX in Markdown files
|
70
|
+
# NOT SAFE YET! DO NO USE THIS!
|
66
71
|
def fix_latex(str)
|
67
72
|
inline_exp = /(([^\$]\${1}[^\$].*?[^\$]?\${1}[^\$]))/
|
68
73
|
multline_exp = /((\\begin\{(\w+?)\}.+?\\end\{\3\})|(\$\$.+?\$\$))/m
|
@@ -71,9 +76,52 @@ module Gmd
|
|
71
76
|
str
|
72
77
|
end
|
73
78
|
|
74
|
-
def
|
75
|
-
@
|
79
|
+
def var
|
80
|
+
@var ||= {}
|
76
81
|
end
|
77
|
-
|
82
|
+
|
83
|
+
# Here we can specify the default options for different renderers
|
84
|
+
def rendering_options(engine)
|
85
|
+
case engine.name
|
86
|
+
when /Redcarpet/
|
87
|
+
{
|
88
|
+
:no_intra_emphasis => true,
|
89
|
+
:tables => true,
|
90
|
+
:fenced_code_blocks => true,
|
91
|
+
:autolink => true,
|
92
|
+
:strikethrough => true,
|
93
|
+
:lax_html_blocks => true,
|
94
|
+
:space_after_headers => true,
|
95
|
+
:superscript => false
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def tilt_render(file, locals = {}, &block)
|
101
|
+
Tilt.new(file, 1, rendering_options(Tilt[file]) || {})
|
102
|
+
.render(Gmd::ExtraBinding, locals, &block)
|
103
|
+
.force_encoding("UTF-8")
|
104
|
+
end
|
105
|
+
|
78
106
|
end
|
107
|
+
|
108
|
+
class ExtraBinding
|
109
|
+
class << self
|
110
|
+
|
111
|
+
include Helpers
|
112
|
+
|
113
|
+
def method_missing(method_sym, *arguments, &block)
|
114
|
+
if Gmd.respond_to?(method_sym)
|
115
|
+
Gmd.__send__(method_sym, *arguments, &block)
|
116
|
+
else
|
117
|
+
super
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def respond_to?(method_sym)
|
122
|
+
super || Gmd.respond_to?(method_sym)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
79
127
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-28 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redcarpet
|
16
|
-
requirement: &
|
16
|
+
requirement: &30605592 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *30605592
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: tilt
|
27
|
-
requirement: &
|
27
|
+
requirement: &30605340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *30605340
|
36
36
|
description: gmd is a small command-line utility to easily generate fancy HTML from
|
37
37
|
Markdown.
|
38
38
|
email:
|
@@ -49,6 +49,8 @@ files:
|
|
49
49
|
- bin/gmd
|
50
50
|
- gmd.gemspec
|
51
51
|
- lib/gmd.rb
|
52
|
+
- lib/gmd/helpers.rb
|
53
|
+
- lib/gmd/redcarpet_template_fix.rb
|
52
54
|
- lib/gmd/templates/common/header.html.erb
|
53
55
|
- lib/gmd/templates/common/highlight_js/github.css
|
54
56
|
- lib/gmd/templates/common/highlight_js/highlight.pack.js
|