markdown 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/HISTORY.md +2 -0
- data/Manifest.txt +15 -18
- data/Rakefile +3 -3
- data/lib/markdown/config.rb +202 -202
- data/lib/markdown/engines/bluecloth.rb +17 -17
- data/lib/markdown/engines/kramdown.rb +62 -62
- data/lib/markdown/engines/maruku.rb +16 -16
- data/lib/markdown/engines/pandoc_ruby.rb +37 -37
- data/lib/markdown/engines/rdiscount.rb +17 -17
- data/lib/markdown/engines/redcarpet.rb +56 -56
- data/lib/markdown/engines/rpeg_markdown.rb +13 -13
- data/lib/markdown/version.rb +4 -4
- data/lib/markdown/wrapper.rb +135 -135
- data/lib/markdown.rb +41 -43
- metadata +18 -19
- data/.gemtest +0 -0
- data/test/helper.rb +0 -12
- data/test/test_kramdown.rb +0 -43
- data/test/test_redcarpet.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0ed84c4b937db4cf349543a726ff16c3ddd365bf7206eafbe2966ed26f6371d1
|
4
|
+
data.tar.gz: e5327c8150f5c110838080fea11eb48806ead136575b250ccc5d3512bc67fc62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53cb8e0a328532dfda9996b54719f3b3d8337d29171741b34abdb147bb4cb5e6cd1e8851a04a4579aece9b926bdbcc64726679d6bd89edfc8ce735e21586df7f
|
7
|
+
data.tar.gz: 30610a33cdcd3b0c3951f8617e77a81e753c3e84676e07b0ef28802c1a0e7961d3928d33de02a5195b45f1740fb7ceeb69ddb5e52a1173ba20f7fc44c6dcf079
|
data/HISTORY.md
CHANGED
data/Manifest.txt
CHANGED
@@ -1,18 +1,15 @@
|
|
1
|
-
HISTORY.md
|
2
|
-
Manifest.txt
|
3
|
-
README.md
|
4
|
-
Rakefile
|
5
|
-
lib/markdown.rb
|
6
|
-
lib/markdown/config.rb
|
7
|
-
lib/markdown/engines/bluecloth.rb
|
8
|
-
lib/markdown/engines/kramdown.rb
|
9
|
-
lib/markdown/engines/maruku.rb
|
10
|
-
lib/markdown/engines/pandoc_ruby.rb
|
11
|
-
lib/markdown/engines/rdiscount.rb
|
12
|
-
lib/markdown/engines/redcarpet.rb
|
13
|
-
lib/markdown/engines/rpeg_markdown.rb
|
14
|
-
lib/markdown/version.rb
|
15
|
-
lib/markdown/wrapper.rb
|
16
|
-
test/helper.rb
|
17
|
-
test/test_kramdown.rb
|
18
|
-
test/test_redcarpet.rb
|
1
|
+
HISTORY.md
|
2
|
+
Manifest.txt
|
3
|
+
README.md
|
4
|
+
Rakefile
|
5
|
+
lib/markdown.rb
|
6
|
+
lib/markdown/config.rb
|
7
|
+
lib/markdown/engines/bluecloth.rb
|
8
|
+
lib/markdown/engines/kramdown.rb
|
9
|
+
lib/markdown/engines/maruku.rb
|
10
|
+
lib/markdown/engines/pandoc_ruby.rb
|
11
|
+
lib/markdown/engines/rdiscount.rb
|
12
|
+
lib/markdown/engines/redcarpet.rb
|
13
|
+
lib/markdown/engines/rpeg_markdown.rb
|
14
|
+
lib/markdown/version.rb
|
15
|
+
lib/markdown/wrapper.rb
|
data/Rakefile
CHANGED
@@ -8,10 +8,10 @@ Hoe.spec 'markdown' do
|
|
8
8
|
self.summary = 'Markdown Engine Wrapper - Use Your Markdown Library of Choice'
|
9
9
|
self.description = summary
|
10
10
|
|
11
|
-
self.urls =
|
11
|
+
self.urls = { home: 'https://github.com/rubylibs/markdown' }
|
12
12
|
|
13
13
|
self.author = 'Gerald Bauer'
|
14
|
-
self.email = '
|
14
|
+
self.email = 'gerald.bauer@gmail.com'
|
15
15
|
|
16
16
|
self.extra_deps = [
|
17
17
|
['props','>= 1.1.2'],
|
@@ -19,7 +19,7 @@ Hoe.spec 'markdown' do
|
|
19
19
|
['kramdown','>= 1.5.0']
|
20
20
|
]
|
21
21
|
|
22
|
-
# switch extension to .markdown for
|
22
|
+
# switch extension to .markdown for github formatting
|
23
23
|
self.readme_file = 'README.md'
|
24
24
|
self.history_file = 'HISTORY.md'
|
25
25
|
|
data/lib/markdown/config.rb
CHANGED
@@ -1,202 +1,202 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Markdown
|
4
|
-
|
5
|
-
class Config
|
6
|
-
|
7
|
-
# note: only kramdown is listed as a dependency in gem specs (because it's Ruby only and, thus, easy to install)
|
8
|
-
# if you want to use other markdown libs install the required/desired lib e.g.
|
9
|
-
# use gem install rdiscount for rdiscount and so on
|
10
|
-
#
|
11
|
-
# also note for now the first present markdown library gets used
|
12
|
-
# the search order is first come, first serve, that is: rdiscount, rpeg-markdown, maruku, bluecloth, kramdown (fallback, always present)
|
13
|
-
|
14
|
-
|
15
|
-
DEFAULT_EXTNAMES = [
|
16
|
-
'.markdown',
|
17
|
-
'.m',
|
18
|
-
'.mark',
|
19
|
-
'.mkdn',
|
20
|
-
'.md',
|
21
|
-
'.mdown',
|
22
|
-
'.markdn',
|
23
|
-
'.txt',
|
24
|
-
'.text' ] # todo: check - add .wiki??? ext
|
25
|
-
|
26
|
-
DEFAULT_REDCARPET = {
|
27
|
-
'extensions' => [
|
28
|
-
'no_intra_emphasis',
|
29
|
-
'fenced_code_blocks',
|
30
|
-
'tables',
|
31
|
-
'strikethrough' ] }
|
32
|
-
|
33
|
-
DEFAULT_FILTERS = [
|
34
|
-
'comments-percent-style' ] # optional (preprocessing) text filters: e.g. comments-percent-style, skip-end-directive, etc. (see textutils gem)
|
35
|
-
|
36
|
-
|
37
|
-
DEFAULTS = { 'libs' => [ 'kramdown' ], # note: make kramdown default engine
|
38
|
-
'extnames' => DEFAULT_EXTNAMES,
|
39
|
-
'redcarpet' => DEFAULT_REDCARPET, # todo/fix: merge nested hash??
|
40
|
-
'filters' => DEFAULT_FILTERS
|
41
|
-
}
|
42
|
-
|
43
|
-
#
|
44
|
-
# pandoc-ruby - how to include - gemfile cannot install binary ??
|
45
|
-
# rpeg-markdown - build failure - still active, anyway?
|
46
|
-
# rdiscount - # compilation error on heroku; sorry excluded for now
|
47
|
-
|
48
|
-
DEFAULTS_SERVICE = { 'libs' => [
|
49
|
-
'kramdown', # note: make kramdown default engine
|
50
|
-
'maruku',
|
51
|
-
'bluecloth',
|
52
|
-
'redcarpet'
|
53
|
-
],
|
54
|
-
'extnames' => DEFAULT_EXTNAMES,
|
55
|
-
'redcarpet' => DEFAULT_REDCARPET
|
56
|
-
}
|
57
|
-
|
58
|
-
def load_props
|
59
|
-
@props = @props_default = Props.new( DEFAULTS, 'DEFAULTS' )
|
60
|
-
|
61
|
-
# check for user settings (markdown.yml) in home folder
|
62
|
-
|
63
|
-
## todo: use .markdown.yml?? or differnt name ??
|
64
|
-
props_home_file = File.join( Env.home, 'markdown.yml' )
|
65
|
-
if File.
|
66
|
-
puts "Loading home settings from '#{props_home_file}'..."
|
67
|
-
@props = @props_home = Props.load_file( props_home_file, @props )
|
68
|
-
end
|
69
|
-
|
70
|
-
# check for user settings (markdown.yml) in working folder
|
71
|
-
|
72
|
-
props_work_file = File.join( '.', 'markdown.yml' )
|
73
|
-
if File.
|
74
|
-
puts "Loading work settings from '#{props_work_file}'..."
|
75
|
-
@props = @props_work = Props.load_file( props_work_file, @props )
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def load_props_service
|
80
|
-
puts "Loading service settings..."
|
81
|
-
@props = @props_default = Props.new( DEFAULTS_SERVICE, 'DEFAULTS' )
|
82
|
-
end
|
83
|
-
|
84
|
-
def initialize
|
85
|
-
|
86
|
-
# for an example see ./boot.rb
|
87
|
-
if $MARKDOWN_USE_SERVICE_CONFIG == true
|
88
|
-
load_props_service
|
89
|
-
else
|
90
|
-
load_props
|
91
|
-
end
|
92
|
-
|
93
|
-
@libs = []
|
94
|
-
|
95
|
-
require_markdown_libs()
|
96
|
-
end
|
97
|
-
|
98
|
-
def dump # for debugging dump all settings
|
99
|
-
puts "Markdown settings:"
|
100
|
-
@props_default.dump if @props_default
|
101
|
-
@props_home.dump if @props_home
|
102
|
-
@props_work.dump if @props_work
|
103
|
-
|
104
|
-
puts
|
105
|
-
puts "Markdown libs:"
|
106
|
-
puts " #{@libs.length} Markdown #{(@libs.length == 1) ? 'library' : 'libraries'} found: #{@libs.join(', ')}"
|
107
|
-
end
|
108
|
-
|
109
|
-
def markdown_extnames
|
110
|
-
@props.fetch( 'extnames', nil )
|
111
|
-
end
|
112
|
-
|
113
|
-
def markdown_filters
|
114
|
-
@props.fetch( 'filters', nil )
|
115
|
-
end
|
116
|
-
|
117
|
-
def known_markdown_libs
|
118
|
-
# returns an array of known markdown engines e.g.
|
119
|
-
# [ 'pandoc-ruby', 'rdiscount', 'rpeg-markdown', 'maruku', 'bluecloth', 'kramdown' ]
|
120
|
-
|
121
|
-
## todo: allow single lib para instead of libs
|
122
|
-
## todo: allow ENV setting markdown_[select]_lib=xxxx
|
123
|
-
|
124
|
-
## todo/fix: use lookup with config parent cascade
|
125
|
-
|
126
|
-
|
127
|
-
## lookup order
|
128
|
-
## 1) env variable MARKDOWN_LIB
|
129
|
-
## 2) lib property (single markdown engine)
|
130
|
-
## 3) libs property (first-come first-serve markdown engine list)
|
131
|
-
|
132
|
-
user_lib = Env.markdown_lib || @props.fetch( 'lib', nil )
|
133
|
-
|
134
|
-
if user_lib.nil?
|
135
|
-
user_libs = @props.fetch( 'libs', nil )
|
136
|
-
else
|
137
|
-
[ user_lib ] # return as array (wrap single lib entry)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def require_markdown_libs
|
142
|
-
# check for available markdown libs/gems
|
143
|
-
# try to require each lib and remove any not installed
|
144
|
-
|
145
|
-
known_markdown_libs.each do |lib|
|
146
|
-
begin
|
147
|
-
require lib
|
148
|
-
@libs << lib
|
149
|
-
rescue LoadError => ex
|
150
|
-
## todo: use logger.debug instead of puts
|
151
|
-
puts "Markdown library #{lib} not found. Use gem install #{lib} to install."
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
def markdown_lib=( lib )
|
157
|
-
|
158
|
-
# fix/todo: check if @libs.first == lib => do nothing; return
|
159
|
-
|
160
|
-
# check if value exists in libs array
|
161
|
-
# if yes put it into first position
|
162
|
-
# otherwise issue warning/error - better throw exception; engine not found
|
163
|
-
|
164
|
-
# try to delete
|
165
|
-
obj = @libs.delete( lib )
|
166
|
-
if obj.nil? # nothing deleted; no obj found
|
167
|
-
# try to require; will raise load error exception if not found; know what your're doing! no fallback; sorry; better fail fast
|
168
|
-
require lib
|
169
|
-
end
|
170
|
-
|
171
|
-
# add it back; make it first entry
|
172
|
-
@libs.unshift( lib )
|
173
|
-
end
|
174
|
-
|
175
|
-
def markdown_lib
|
176
|
-
@libs.first
|
177
|
-
end
|
178
|
-
|
179
|
-
def markdown_libs
|
180
|
-
@libs # NB: return all libs - should we return a clone?
|
181
|
-
end
|
182
|
-
|
183
|
-
def markdown_lib_defaults( lib=nil )
|
184
|
-
lib = @libs.first if lib.nil?
|
185
|
-
## todo: return props ? that acts like a hash?? (lets us support section lookup without deep merge???)
|
186
|
-
opts = @props.fetch( lib, {} )
|
187
|
-
end
|
188
|
-
|
189
|
-
def markdown_version_method( lib=nil )
|
190
|
-
lib = @libs.first if lib.nil?
|
191
|
-
method = "#{lib.downcase}_version" # default to <lib>_to_html if converter prop not found
|
192
|
-
method.tr('-','_').to_sym
|
193
|
-
end
|
194
|
-
|
195
|
-
def markdown_to_html_method( lib=nil )
|
196
|
-
lib = @libs.first if lib.nil?
|
197
|
-
method = @props.fetch_from_section( lib, 'converter', "#{lib.downcase}_to_html" ) # default to <lib>_to_html if converter prop not found
|
198
|
-
method.tr('-','_').to_sym
|
199
|
-
end
|
200
|
-
|
201
|
-
end # class Config
|
202
|
-
end # module Markdown
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Markdown
|
4
|
+
|
5
|
+
class Config
|
6
|
+
|
7
|
+
# note: only kramdown is listed as a dependency in gem specs (because it's Ruby only and, thus, easy to install)
|
8
|
+
# if you want to use other markdown libs install the required/desired lib e.g.
|
9
|
+
# use gem install rdiscount for rdiscount and so on
|
10
|
+
#
|
11
|
+
# also note for now the first present markdown library gets used
|
12
|
+
# the search order is first come, first serve, that is: rdiscount, rpeg-markdown, maruku, bluecloth, kramdown (fallback, always present)
|
13
|
+
|
14
|
+
|
15
|
+
DEFAULT_EXTNAMES = [
|
16
|
+
'.markdown',
|
17
|
+
'.m',
|
18
|
+
'.mark',
|
19
|
+
'.mkdn',
|
20
|
+
'.md',
|
21
|
+
'.mdown',
|
22
|
+
'.markdn',
|
23
|
+
'.txt',
|
24
|
+
'.text' ] # todo: check - add .wiki??? ext
|
25
|
+
|
26
|
+
DEFAULT_REDCARPET = {
|
27
|
+
'extensions' => [
|
28
|
+
'no_intra_emphasis',
|
29
|
+
'fenced_code_blocks',
|
30
|
+
'tables',
|
31
|
+
'strikethrough' ] }
|
32
|
+
|
33
|
+
DEFAULT_FILTERS = [
|
34
|
+
'comments-percent-style' ] # optional (preprocessing) text filters: e.g. comments-percent-style, skip-end-directive, etc. (see textutils gem)
|
35
|
+
|
36
|
+
|
37
|
+
DEFAULTS = { 'libs' => [ 'kramdown' ], # note: make kramdown default engine
|
38
|
+
'extnames' => DEFAULT_EXTNAMES,
|
39
|
+
'redcarpet' => DEFAULT_REDCARPET, # todo/fix: merge nested hash??
|
40
|
+
'filters' => DEFAULT_FILTERS
|
41
|
+
}
|
42
|
+
|
43
|
+
#
|
44
|
+
# pandoc-ruby - how to include - gemfile cannot install binary ??
|
45
|
+
# rpeg-markdown - build failure - still active, anyway?
|
46
|
+
# rdiscount - # compilation error on heroku; sorry excluded for now
|
47
|
+
|
48
|
+
DEFAULTS_SERVICE = { 'libs' => [
|
49
|
+
'kramdown', # note: make kramdown default engine
|
50
|
+
'maruku',
|
51
|
+
'bluecloth',
|
52
|
+
'redcarpet'
|
53
|
+
],
|
54
|
+
'extnames' => DEFAULT_EXTNAMES,
|
55
|
+
'redcarpet' => DEFAULT_REDCARPET
|
56
|
+
}
|
57
|
+
|
58
|
+
def load_props
|
59
|
+
@props = @props_default = Props.new( DEFAULTS, 'DEFAULTS' )
|
60
|
+
|
61
|
+
# check for user settings (markdown.yml) in home folder
|
62
|
+
|
63
|
+
## todo: use .markdown.yml?? or differnt name ??
|
64
|
+
props_home_file = File.join( Env.home, 'markdown.yml' )
|
65
|
+
if File.exist?( props_home_file )
|
66
|
+
puts "Loading home settings from '#{props_home_file}'..."
|
67
|
+
@props = @props_home = Props.load_file( props_home_file, @props )
|
68
|
+
end
|
69
|
+
|
70
|
+
# check for user settings (markdown.yml) in working folder
|
71
|
+
|
72
|
+
props_work_file = File.join( '.', 'markdown.yml' )
|
73
|
+
if File.exist?( props_work_file )
|
74
|
+
puts "Loading work settings from '#{props_work_file}'..."
|
75
|
+
@props = @props_work = Props.load_file( props_work_file, @props )
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def load_props_service
|
80
|
+
puts "Loading service settings..."
|
81
|
+
@props = @props_default = Props.new( DEFAULTS_SERVICE, 'DEFAULTS' )
|
82
|
+
end
|
83
|
+
|
84
|
+
def initialize
|
85
|
+
|
86
|
+
# for an example see ./boot.rb
|
87
|
+
if $MARKDOWN_USE_SERVICE_CONFIG == true
|
88
|
+
load_props_service
|
89
|
+
else
|
90
|
+
load_props
|
91
|
+
end
|
92
|
+
|
93
|
+
@libs = []
|
94
|
+
|
95
|
+
require_markdown_libs()
|
96
|
+
end
|
97
|
+
|
98
|
+
def dump # for debugging dump all settings
|
99
|
+
puts "Markdown settings:"
|
100
|
+
@props_default.dump if @props_default
|
101
|
+
@props_home.dump if @props_home
|
102
|
+
@props_work.dump if @props_work
|
103
|
+
|
104
|
+
puts
|
105
|
+
puts "Markdown libs:"
|
106
|
+
puts " #{@libs.length} Markdown #{(@libs.length == 1) ? 'library' : 'libraries'} found: #{@libs.join(', ')}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def markdown_extnames
|
110
|
+
@props.fetch( 'extnames', nil )
|
111
|
+
end
|
112
|
+
|
113
|
+
def markdown_filters
|
114
|
+
@props.fetch( 'filters', nil )
|
115
|
+
end
|
116
|
+
|
117
|
+
def known_markdown_libs
|
118
|
+
# returns an array of known markdown engines e.g.
|
119
|
+
# [ 'pandoc-ruby', 'rdiscount', 'rpeg-markdown', 'maruku', 'bluecloth', 'kramdown' ]
|
120
|
+
|
121
|
+
## todo: allow single lib para instead of libs
|
122
|
+
## todo: allow ENV setting markdown_[select]_lib=xxxx
|
123
|
+
|
124
|
+
## todo/fix: use lookup with config parent cascade
|
125
|
+
|
126
|
+
|
127
|
+
## lookup order
|
128
|
+
## 1) env variable MARKDOWN_LIB
|
129
|
+
## 2) lib property (single markdown engine)
|
130
|
+
## 3) libs property (first-come first-serve markdown engine list)
|
131
|
+
|
132
|
+
user_lib = Env.markdown_lib || @props.fetch( 'lib', nil )
|
133
|
+
|
134
|
+
if user_lib.nil?
|
135
|
+
user_libs = @props.fetch( 'libs', nil )
|
136
|
+
else
|
137
|
+
[ user_lib ] # return as array (wrap single lib entry)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def require_markdown_libs
|
142
|
+
# check for available markdown libs/gems
|
143
|
+
# try to require each lib and remove any not installed
|
144
|
+
|
145
|
+
known_markdown_libs.each do |lib|
|
146
|
+
begin
|
147
|
+
require lib
|
148
|
+
@libs << lib
|
149
|
+
rescue LoadError => ex
|
150
|
+
## todo: use logger.debug instead of puts
|
151
|
+
puts "Markdown library #{lib} not found. Use gem install #{lib} to install."
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def markdown_lib=( lib )
|
157
|
+
|
158
|
+
# fix/todo: check if @libs.first == lib => do nothing; return
|
159
|
+
|
160
|
+
# check if value exists in libs array
|
161
|
+
# if yes put it into first position
|
162
|
+
# otherwise issue warning/error - better throw exception; engine not found
|
163
|
+
|
164
|
+
# try to delete
|
165
|
+
obj = @libs.delete( lib )
|
166
|
+
if obj.nil? # nothing deleted; no obj found
|
167
|
+
# try to require; will raise load error exception if not found; know what your're doing! no fallback; sorry; better fail fast
|
168
|
+
require lib
|
169
|
+
end
|
170
|
+
|
171
|
+
# add it back; make it first entry
|
172
|
+
@libs.unshift( lib )
|
173
|
+
end
|
174
|
+
|
175
|
+
def markdown_lib
|
176
|
+
@libs.first
|
177
|
+
end
|
178
|
+
|
179
|
+
def markdown_libs
|
180
|
+
@libs # NB: return all libs - should we return a clone?
|
181
|
+
end
|
182
|
+
|
183
|
+
def markdown_lib_defaults( lib=nil )
|
184
|
+
lib = @libs.first if lib.nil?
|
185
|
+
## todo: return props ? that acts like a hash?? (lets us support section lookup without deep merge???)
|
186
|
+
opts = @props.fetch( lib, {} )
|
187
|
+
end
|
188
|
+
|
189
|
+
def markdown_version_method( lib=nil )
|
190
|
+
lib = @libs.first if lib.nil?
|
191
|
+
method = "#{lib.downcase}_version" # default to <lib>_to_html if converter prop not found
|
192
|
+
method.tr('-','_').to_sym
|
193
|
+
end
|
194
|
+
|
195
|
+
def markdown_to_html_method( lib=nil )
|
196
|
+
lib = @libs.first if lib.nil?
|
197
|
+
method = @props.fetch_from_section( lib, 'converter', "#{lib.downcase}_to_html" ) # default to <lib>_to_html if converter prop not found
|
198
|
+
method.tr('-','_').to_sym
|
199
|
+
end
|
200
|
+
|
201
|
+
end # class Config
|
202
|
+
end # module Markdown
|
@@ -1,17 +1,17 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Markdown
|
4
|
-
module Engine
|
5
|
-
|
6
|
-
def bluecloth_version
|
7
|
-
BlueCloth::VERSION
|
8
|
-
end
|
9
|
-
|
10
|
-
def bluecloth_to_html( content, options={} )
|
11
|
-
puts " Converting Markdown-text (#{content.length} bytes) to HTML using library bluecloth..."
|
12
|
-
|
13
|
-
BlueCloth.new( content ).to_html
|
14
|
-
end
|
15
|
-
|
16
|
-
end # module Engine
|
17
|
-
end # module Markdown
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Markdown
|
4
|
+
module Engine
|
5
|
+
|
6
|
+
def bluecloth_version
|
7
|
+
BlueCloth::VERSION
|
8
|
+
end
|
9
|
+
|
10
|
+
def bluecloth_to_html( content, options={} )
|
11
|
+
puts " Converting Markdown-text (#{content.length} bytes) to HTML using library bluecloth..."
|
12
|
+
|
13
|
+
BlueCloth.new( content ).to_html
|
14
|
+
end
|
15
|
+
|
16
|
+
end # module Engine
|
17
|
+
end # module Markdown
|
@@ -1,62 +1,62 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Markdown
|
4
|
-
module Engine
|
5
|
-
|
6
|
-
def kramdown_version
|
7
|
-
Kramdown::VERSION
|
8
|
-
end
|
9
|
-
|
10
|
-
def kramdown_to_html( content, options={} )
|
11
|
-
|
12
|
-
h = {}
|
13
|
-
|
14
|
-
# todo: find an easier (more generic?) way to setup hash - possible?
|
15
|
-
h[ :auto_ids ] = options.fetch( 'auto_ids', nil ) if options.fetch( 'auto_ids', nil )
|
16
|
-
h[ :footnote_nr ] = options.fetch( 'footnote_nr',nil ) if options.fetch( 'footnote_nr', nil )
|
17
|
-
h[ :entity_output ] = options.fetch( 'entity_output',nil ) if options.fetch( 'entity_output', nil )
|
18
|
-
h[ :toc_levels ] = options.fetch( 'toc_levels',nil ) if options.fetch( 'toc_levels', nil )
|
19
|
-
h[ :smart_quotes ] = options.fetch( 'smart_quotes',nil ) if options.fetch( 'smart_quotes', nil )
|
20
|
-
|
21
|
-
show_banner = options.fetch( 'banner', true)
|
22
|
-
|
23
|
-
# puts " Converting Markdown-text (#{content.length} bytes) to HTML using library kramdown (#{Kramdown::VERSION})"
|
24
|
-
# puts " using options: #{h.to_json}"
|
25
|
-
|
26
|
-
## allow fenced blocks a la github flavored markup
|
27
|
-
# -- thanks zenweb for inspiration:
|
28
|
-
# https://github.com/seattlerb/zenweb/blob/master/lib/zenweb/plugins/markdown.rb
|
29
|
-
|
30
|
-
content = content.
|
31
|
-
gsub(/^``` *(\w+)/) { "{:lang=\"#$1\"}\n~~~" }.
|
32
|
-
gsub(/^```/, '~~~')
|
33
|
-
|
34
|
-
content = Kramdown::Document.new( content, h ).to_html
|
35
|
-
|
36
|
-
if show_banner
|
37
|
-
|
38
|
-
# todo: check content size and newlines
|
39
|
-
# check banner option?
|
40
|
-
# only add banner if some newlines and size > treshold?
|
41
|
-
|
42
|
-
banner_begin =<<EOS
|
43
|
-
<!-- === begin markdown block ===
|
44
|
-
|
45
|
-
generated by #{Markdown.banner}
|
46
|
-
on #{Time.now} with Markdown engine kramdown (#{Kramdown::VERSION})
|
47
|
-
using options #{h.to_json}
|
48
|
-
-->
|
49
|
-
EOS
|
50
|
-
|
51
|
-
banner_end =<<EOS
|
52
|
-
<!-- === end markdown block === -->
|
53
|
-
EOS
|
54
|
-
content = banner_begin + content + banner_end
|
55
|
-
end # if show_banner
|
56
|
-
|
57
|
-
content
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
end # module Engine
|
62
|
-
end # module Markdown
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Markdown
|
4
|
+
module Engine
|
5
|
+
|
6
|
+
def kramdown_version
|
7
|
+
Kramdown::VERSION
|
8
|
+
end
|
9
|
+
|
10
|
+
def kramdown_to_html( content, options={} )
|
11
|
+
|
12
|
+
h = {}
|
13
|
+
|
14
|
+
# todo: find an easier (more generic?) way to setup hash - possible?
|
15
|
+
h[ :auto_ids ] = options.fetch( 'auto_ids', nil ) if options.fetch( 'auto_ids', nil )
|
16
|
+
h[ :footnote_nr ] = options.fetch( 'footnote_nr',nil ) if options.fetch( 'footnote_nr', nil )
|
17
|
+
h[ :entity_output ] = options.fetch( 'entity_output',nil ) if options.fetch( 'entity_output', nil )
|
18
|
+
h[ :toc_levels ] = options.fetch( 'toc_levels',nil ) if options.fetch( 'toc_levels', nil )
|
19
|
+
h[ :smart_quotes ] = options.fetch( 'smart_quotes',nil ) if options.fetch( 'smart_quotes', nil )
|
20
|
+
|
21
|
+
show_banner = options.fetch( 'banner', true)
|
22
|
+
|
23
|
+
# puts " Converting Markdown-text (#{content.length} bytes) to HTML using library kramdown (#{Kramdown::VERSION})"
|
24
|
+
# puts " using options: #{h.to_json}"
|
25
|
+
|
26
|
+
## allow fenced blocks a la github flavored markup
|
27
|
+
# -- thanks zenweb for inspiration:
|
28
|
+
# https://github.com/seattlerb/zenweb/blob/master/lib/zenweb/plugins/markdown.rb
|
29
|
+
|
30
|
+
content = content.
|
31
|
+
gsub(/^``` *(\w+)/) { "{:lang=\"#$1\"}\n~~~" }.
|
32
|
+
gsub(/^```/, '~~~')
|
33
|
+
|
34
|
+
content = Kramdown::Document.new( content, h ).to_html
|
35
|
+
|
36
|
+
if show_banner
|
37
|
+
|
38
|
+
# todo: check content size and newlines
|
39
|
+
# check banner option?
|
40
|
+
# only add banner if some newlines and size > treshold?
|
41
|
+
|
42
|
+
banner_begin =<<EOS
|
43
|
+
<!-- === begin markdown block ===
|
44
|
+
|
45
|
+
generated by #{Markdown.banner}
|
46
|
+
on #{Time.now} with Markdown engine kramdown (#{Kramdown::VERSION})
|
47
|
+
using options #{h.to_json}
|
48
|
+
-->
|
49
|
+
EOS
|
50
|
+
|
51
|
+
banner_end =<<EOS
|
52
|
+
<!-- === end markdown block === -->
|
53
|
+
EOS
|
54
|
+
content = banner_begin + content + banner_end
|
55
|
+
end # if show_banner
|
56
|
+
|
57
|
+
content
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end # module Engine
|
62
|
+
end # module Markdown
|