trans 0.5.0
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.
- checksums.yaml +7 -0
- data/bin/trans +85 -0
- data/lib/tocmd.rb +20 -0
- data/lib/tocmd/translator_trans.rb +370 -0
- data/lib/tocmd/version.rb +3 -0
- data/test/mdptest.rb +100 -0
- data/vendor/meta.js +1 -0
- data/vendor/template.html +0 -0
- data/vendor/toc/css/bootstrap.icons.css +487 -0
- data/vendor/toc/css/component.css +297 -0
- data/vendor/toc/css/demo.css +33 -0
- data/vendor/toc/css/glyphicons-halflings-white.png +0 -0
- data/vendor/toc/css/glyphicons-halflings.png +0 -0
- data/vendor/toc/css/icons.css +198 -0
- data/vendor/toc/css/normalize.css +1 -0
- data/vendor/toc/css/zTreeStyle/img/diy/1_close.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/diy/1_open.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/diy/2.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/diy/3.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/diy/4.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/diy/5.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/diy/6.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/diy/7.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/diy/8.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/diy/9.png +0 -0
- data/vendor/toc/css/zTreeStyle/img/line_conn.gif +0 -0
- data/vendor/toc/css/zTreeStyle/img/loading.gif +0 -0
- data/vendor/toc/css/zTreeStyle/img/zTreeStandard.gif +0 -0
- data/vendor/toc/css/zTreeStyle/img/zTreeStandard.png +0 -0
- data/vendor/toc/css/zTreeStyle/zTreeStyle.css +97 -0
- data/vendor/toc/fonts/codropsicons/codropsicons.eot +0 -0
- data/vendor/toc/fonts/codropsicons/codropsicons.svg +24 -0
- data/vendor/toc/fonts/codropsicons/codropsicons.ttf +0 -0
- data/vendor/toc/fonts/codropsicons/codropsicons.woff +0 -0
- data/vendor/toc/fonts/codropsicons/license.txt +6 -0
- data/vendor/toc/fonts/linecons/Read Me.txt +3 -0
- data/vendor/toc/fonts/linecons/license.txt +10 -0
- data/vendor/toc/fonts/linecons/linecons.dev.svg +488 -0
- data/vendor/toc/fonts/linecons/linecons.eot +0 -0
- data/vendor/toc/fonts/linecons/linecons.svg +488 -0
- data/vendor/toc/fonts/linecons/linecons.ttf +0 -0
- data/vendor/toc/fonts/linecons/linecons.woff +0 -0
- data/vendor/toc/fonts/linecons/lte-ie7.js +85 -0
- data/vendor/toc/img/glyphicons-halflings-white.png +0 -0
- data/vendor/toc/img/glyphicons-halflings.png +0 -0
- data/vendor/toc/img/icon-cog-shadow.png +0 -0
- data/vendor/toc/img/icon-cog-small.png +0 -0
- data/vendor/toc/img/icon-cog.png +0 -0
- data/vendor/toc/img/pattern-2.png +0 -0
- data/vendor/toc/js/classie.js +80 -0
- data/vendor/toc/js/jquery-1.4.4.min.js +167 -0
- data/vendor/toc/js/jquery.js +9555 -0
- data/vendor/toc/js/jquery.ztree.all-3.5.min.js +157 -0
- data/vendor/toc/js/mlpushmenu.js +243 -0
- data/vendor/toc/js/modernizr.custom.js +4 -0
- data/vendor/toc/js/ztree_toc.js +282 -0
- data/vendor/toc/js/ztree_toc.min.js +4 -0
- data/vendor/toc/style/Clearness Dark.css +146 -0
- data/vendor/toc/style/Clearness.css +147 -0
- data/vendor/toc/style/GitHub.css +90 -0
- data/vendor/toc/style/GitHub2.css +297 -0
- data/vendor/toc/style/github-bf51422f4bb36427d391e4b75a1daa083c2d840e.css +1 -0
- data/vendor/toc/style/github2-d731afd4f624c99a4b19ad69f3083cd6d02b81d5.css +1 -0
- data/vendor/toc/style/makedownpad.css +285 -0
- data/vendor/toc/toc_conf.js +20 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 78246b58b88d2f7956ebac7886438ff507431ce5
|
4
|
+
data.tar.gz: f636f38190dde01168eb5e7b6cd7a75ebdfceb71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a651a82f6b0c0f67d4840afc8be228e5ec3fe9dff9fd1197281069a2394cdd230a7e61f675b5164556bc4347b3027f6edad12473b870211fe27bce111b0c41bc
|
7
|
+
data.tar.gz: 0cba19664a8fa29b2afa085def13aa9d7cf54802ad3450eb88290b220b04be08baa196b0ddffbcf84d962caba61f9e2d686278d685ff3cb3b1444515b33728af
|
data/bin/trans
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'tocmd'
|
5
|
+
require 'pathname'
|
6
|
+
# p ARGV
|
7
|
+
# puts Mdpreview.hi(ARGV)
|
8
|
+
#
|
9
|
+
# puts __FILE__
|
10
|
+
# puts File.dirname(__FILE__)
|
11
|
+
|
12
|
+
|
13
|
+
# File.join(File.dirname(__FILE__), '..', 'lib')
|
14
|
+
path = Pathname.new(File.join(File.dirname(__FILE__), '..')).realpath.to_s
|
15
|
+
|
16
|
+
# p "开始#{Dir.pwd}"
|
17
|
+
# p "path = #{path}"
|
18
|
+
|
19
|
+
require 'optparse'
|
20
|
+
|
21
|
+
options = {}
|
22
|
+
option_parser = OptionParser.new do |opts|
|
23
|
+
# 这里是这个命令行工具的帮助信息
|
24
|
+
opts.banner = 'preview markdown file with toc of the command line tool.'
|
25
|
+
|
26
|
+
# # Option 作为switch,不带argument,用于将switch设置成true或false
|
27
|
+
# options[:switch] = false
|
28
|
+
# # 下面第一项是Short option(没有可以直接在引号间留空),第二项是Long option,第三项是对Option的描述
|
29
|
+
# opts.on('-s', '--switch', 'Set options as switch') do
|
30
|
+
# # 这个部分就是使用这个Option后执行的代码
|
31
|
+
# options[:switch] = true
|
32
|
+
# end
|
33
|
+
vendor_path = Pathname.new(File.expand_path('../../template/', __FILE__)).realpath.to_s
|
34
|
+
|
35
|
+
src_p = Dir.pwd
|
36
|
+
|
37
|
+
begin
|
38
|
+
Dir.delelte(File.join(src_p ,"preview"))
|
39
|
+
Dir.mkdir(File.join(src_p ,"preview"), 0700) #=> 0
|
40
|
+
rescue
|
41
|
+
ensure
|
42
|
+
end
|
43
|
+
|
44
|
+
begin
|
45
|
+
Dir.mkdir(File.join(src_p ,"preview"), 0700) #=> 0
|
46
|
+
rescue
|
47
|
+
ensure
|
48
|
+
end
|
49
|
+
|
50
|
+
# begin
|
51
|
+
# Dir.mkdir(File.join(src_p ,".toc"), 0700) #=> 0
|
52
|
+
# rescue
|
53
|
+
# ensure
|
54
|
+
# f = File.new(File.join(vendor_path ,"template.html"), "w+").path
|
55
|
+
# FileUtils.cp(f ,File.join(src_p ,".toc"))
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
|
59
|
+
# Option 作为flag,带argument,用于将argument作为数值解析,比如"name"信息
|
60
|
+
#下面的“value”就是用户使用时输入的argument
|
61
|
+
opts.on('-f sourceFileNAME', '--name sourceFileNAME', 'Pass-in source file name') do |value|
|
62
|
+
# options[:fname] = value
|
63
|
+
|
64
|
+
Tocmd.hi_trans_local(src_p + '/' + value)
|
65
|
+
end
|
66
|
+
|
67
|
+
opts.on('-d dirNAME', '--name sourceFileNAME', 'Pass-in source file name') do |value|
|
68
|
+
# options[:fname] = value
|
69
|
+
p value
|
70
|
+
|
71
|
+
if value == '.'
|
72
|
+
Tocmd.hi_trans_dir_local(src_p + '/' )
|
73
|
+
else
|
74
|
+
Tocmd.hi_trans_dir_local(src_p + '/' + value)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
# Option 作为flag,带一组用逗号分割的arguments,用于将arguments作为数组解析
|
80
|
+
# opts.on('-a A,B', '--array A,B', Array, 'List of arguments') do |value|
|
81
|
+
# options[:array] = value
|
82
|
+
# end
|
83
|
+
end.parse!
|
84
|
+
|
85
|
+
# puts options.inspect
|
data/lib/tocmd.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "tocmd/version"
|
2
|
+
require "tocmd/translator_trans"
|
3
|
+
|
4
|
+
module Tocmd
|
5
|
+
# ---------------- tocmd_trans command -----------------
|
6
|
+
def self.hi_trans_local(a)
|
7
|
+
translator = TranslatorTrans.new(a)
|
8
|
+
translator.hi
|
9
|
+
# puts version info
|
10
|
+
p VERSION
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.hi_trans_dir_local(a)
|
14
|
+
translator = TranslatorTrans.new(a)
|
15
|
+
translator.hi_dir
|
16
|
+
# puts version info
|
17
|
+
p VERSION
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,370 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
# require 'FileUtils'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
class Tocmd::TranslatorTrans
|
6
|
+
def initialize(source_file_path)
|
7
|
+
#源文件路径
|
8
|
+
@source_file_path = source_file_path
|
9
|
+
#gem跟目录
|
10
|
+
@gem_root_path = File.expand_path('../', @source_file_path)
|
11
|
+
#editor path
|
12
|
+
@editor_path = Pathname.new(File.expand_path('../../../template', __FILE__)).realpath.to_s
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def hi
|
17
|
+
generate_meta_js
|
18
|
+
# cp_source_file_to_cur_file
|
19
|
+
|
20
|
+
ar = @source_file_path.split('/')
|
21
|
+
ar.pop()
|
22
|
+
|
23
|
+
puts "src path = #{ar.join('/').to_s}"
|
24
|
+
src_path = ar.join('/').to_s
|
25
|
+
|
26
|
+
ar.push('preview');
|
27
|
+
dest_dir = ar.join('/').to_s
|
28
|
+
|
29
|
+
puts "desc path = #{ar.join('/').to_s}"
|
30
|
+
|
31
|
+
# copy vendor/toc to dest directory
|
32
|
+
`cp -rf #{@editor_path}/ #{dest_dir}`
|
33
|
+
|
34
|
+
# _toc_config(dest_dir)
|
35
|
+
|
36
|
+
# build now
|
37
|
+
build_with_dir(@source_file_path ,dest_dir)
|
38
|
+
|
39
|
+
# if mac open in browser
|
40
|
+
open_in_browser
|
41
|
+
end
|
42
|
+
|
43
|
+
def hi_dir
|
44
|
+
generate_meta_js
|
45
|
+
# cp_source_file_to_cur_file
|
46
|
+
|
47
|
+
ar = @source_file_path.split('/')
|
48
|
+
# ar.pop()
|
49
|
+
|
50
|
+
puts "hi_dir src path = #{ar.join('/').to_s}"
|
51
|
+
src_path = ar.join('/').to_s
|
52
|
+
|
53
|
+
ar.push('preview');
|
54
|
+
dest_dir = ar.join('/').to_s
|
55
|
+
|
56
|
+
puts "hi_dir desc path = #{ar.join('/').to_s}"
|
57
|
+
|
58
|
+
# copy vendor/toc to dest directory
|
59
|
+
`cp -rf #{@editor_path}/toc #{dest_dir}/toc`
|
60
|
+
|
61
|
+
# _toc_config(dest_dir)
|
62
|
+
|
63
|
+
build_with_dir(src_path ,dest_dir)
|
64
|
+
|
65
|
+
open_in_browser
|
66
|
+
end
|
67
|
+
|
68
|
+
def _toc_config(dest_dir)
|
69
|
+
if File.exist?("#{dest_dir}/toc_conf.js")
|
70
|
+
puts 'toc_conf file exist'
|
71
|
+
else
|
72
|
+
# if file not exit,create toc_conf
|
73
|
+
`touch #{dest_dir}/toc_conf.js`
|
74
|
+
|
75
|
+
# fill data to toc_conf.js
|
76
|
+
`echo 'var jquery_ztree_toc_opts = {'>#{dest_dir}/toc_conf.js`
|
77
|
+
`echo 'is_auto_number:true,' >> #{dest_dir}/toc_conf.js`
|
78
|
+
`echo "documment_selector:'.markdown-body'" >> #{dest_dir}/toc_conf.js`
|
79
|
+
|
80
|
+
`echo '};' >> #{dest_dir}/toc_conf.js`
|
81
|
+
|
82
|
+
`echo "var markdown_panel_style = {'width':'70%','margin-left':'20%'};">> #{dest_dir}/toc_conf.js`
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def open_in_browser
|
87
|
+
ar = @source_file_path.split('/')
|
88
|
+
|
89
|
+
if File.directory?(@source_file_path) == false #普通文件
|
90
|
+
file_name = ar.pop().split('.')[0]
|
91
|
+
src_path = ar.join('/').to_s
|
92
|
+
|
93
|
+
ar.push('preview');
|
94
|
+
dest_dir = ar.join('/').to_s
|
95
|
+
|
96
|
+
`open #{ar.join('/').to_s}/#{file_name}.html`
|
97
|
+
|
98
|
+
else
|
99
|
+
# 目录
|
100
|
+
src_path = ar.join('/').to_s
|
101
|
+
|
102
|
+
Dir.foreach(src_path) do |ff|
|
103
|
+
file_name = ff.split('.')[0]
|
104
|
+
end
|
105
|
+
|
106
|
+
ar.push('preview');
|
107
|
+
dest_dir = ar.join('/').to_s
|
108
|
+
`open #{ar.join('/').to_s}/#{file_name}.html`
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def generate_meta_js
|
113
|
+
f = File.new(File.join(@editor_path,"meta.js"), "w+")
|
114
|
+
f.puts("#{@source_file_path}")
|
115
|
+
end
|
116
|
+
|
117
|
+
def cp_source_file_to_cur_file
|
118
|
+
# cp param must be string
|
119
|
+
f = File.new(File.join(@editor_path,"cur.file"), "w+").path
|
120
|
+
FileUtils.cp(@source_file_path,f)
|
121
|
+
end
|
122
|
+
|
123
|
+
def build_with_dir(destiny_dir,dest_dir)
|
124
|
+
p "start building......"
|
125
|
+
|
126
|
+
if File.directory?(destiny_dir) == false
|
127
|
+
p 'process_with_one'
|
128
|
+
ar = @source_file_path.split('/')
|
129
|
+
file_name = ar.pop().split('.')[0]
|
130
|
+
|
131
|
+
src_path = ar.join('/').to_s
|
132
|
+
|
133
|
+
ar.push('preview');
|
134
|
+
dest_dir = ar.join('/').to_s
|
135
|
+
|
136
|
+
# return;
|
137
|
+
process_with_one(src_path,dest_dir,destiny_dir.split('/').pop().to_s)
|
138
|
+
|
139
|
+
return;
|
140
|
+
end
|
141
|
+
|
142
|
+
p "src_dir = #{destiny_dir}"
|
143
|
+
p "dest_dir = #{dest_dir}"
|
144
|
+
Dir.foreach(destiny_dir) do |ff|
|
145
|
+
# puts ff
|
146
|
+
unless /^\./ =~ ff ||/^images/ =~ ff ||/^css/ =~ ff || File.directory?(ff) || File.extname(ff) != '.md'
|
147
|
+
|
148
|
+
process_with_one(destiny_dir,dest_dir,ff)
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def process_with_one(destiny_dir ,dest_dir ,ff)
|
155
|
+
# get markdown text
|
156
|
+
text = IO.read(destiny_dir + '/' + ff)
|
157
|
+
|
158
|
+
# options = [:fenced_code,:generate_toc,:hard_wrap,:no_intraemphasis,:strikethrough,:gh_blockcode,:autolink,:xhtml,:tables]
|
159
|
+
|
160
|
+
# convert to html
|
161
|
+
markdown = Redcarpet::Markdown.new(HTMLwithPygments,:gh_blockcode=>true,:no_intra_emphasis=>true,:filter_html => true,:hard_wrap => true,:autolink => false, :space_after_headers => true,:fenced_code_blocks => true,:tables => true,:filter_html=>false)
|
162
|
+
parse_markdown = markdown.render(text)
|
163
|
+
# parse_markdown = syntax_highlighter(parse_markdown)
|
164
|
+
|
165
|
+
css_link = ''
|
166
|
+
if destiny_dir.to_s.index('/')
|
167
|
+
css_link = %Q{
|
168
|
+
<link href="toc/style/github-bf51422f4bb36427d391e4b75a1daa083c2d840e.css" media="all" rel="stylesheet" type="text/css"/>
|
169
|
+
<link href="toc/style/github2-d731afd4f624c99a4b19ad69f3083cd6d02b81d5.css" media="all" rel="stylesheet" type="text/css"/>
|
170
|
+
<link href="toc/css/zTreeStyle/zTreeStyle.css" media="all" rel="stylesheet" type="text/css"/>
|
171
|
+
<link rel="stylesheet" type="text/css" href="toc/css/normalize.css" />
|
172
|
+
<link rel="stylesheet" type="text/css" href="toc/css/demo.css" />
|
173
|
+
<link rel="stylesheet" type="text/css" href="toc/css/icons.css" />
|
174
|
+
<link rel="stylesheet" type="text/css" href="toc/css/component.css" />
|
175
|
+
}
|
176
|
+
else
|
177
|
+
css_link = %Q{
|
178
|
+
<link href="toc/style/github-bf51422f4bb36427d391e4b75a1daa083c2d840e.css" media="all" rel="stylesheet" type="text/css"/>
|
179
|
+
<link href="toc/style/github2-d731afd4f624c99a4b19ad69f3083cd6d02b81d5.css" media="all" rel="stylesheet" type="text/css"/>
|
180
|
+
<link href="toc/css/zTreeStyle/zTreeStyle.css" media="all" rel="stylesheet" type="text/css"/>
|
181
|
+
<link rel="stylesheet" type="text/css" href="toc/css/normalize.css" />
|
182
|
+
<link rel="stylesheet" type="text/css" href="toc/css/demo.css" />
|
183
|
+
<link rel="stylesheet" type="text/css" href="toc/css/icons.css" />
|
184
|
+
<link rel="stylesheet" type="text/css" href="toc/css/component.css" />
|
185
|
+
}
|
186
|
+
end
|
187
|
+
|
188
|
+
t = %Q{
|
189
|
+
<html>
|
190
|
+
<head>
|
191
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
192
|
+
<title>#{ff.gsub('.md','')}</title>
|
193
|
+
#{css_link}
|
194
|
+
</head>
|
195
|
+
<body>
|
196
|
+
<div class="container">
|
197
|
+
<!-- Push Wrapper -->
|
198
|
+
<div class="mp-pusher" id="mp-pusher">
|
199
|
+
|
200
|
+
<!-- mp-menu -->
|
201
|
+
<nav id="mp-menu" class="mp-menu">
|
202
|
+
<div class="mp-level">
|
203
|
+
<h2 class="icon icon-world" style='font-size: 34;color:white;'>泰然译品</h2>
|
204
|
+
<ul>
|
205
|
+
</ul>
|
206
|
+
|
207
|
+
</div>
|
208
|
+
</nav>
|
209
|
+
<!-- /mp-menu -->
|
210
|
+
|
211
|
+
<div class="scroller"><!-- this is for emulating position fixed of the nav -->
|
212
|
+
<div class="scroller-inner">
|
213
|
+
<!-- Top Navigation -->
|
214
|
+
|
215
|
+
<div>
|
216
|
+
<div style='width:25%;'>
|
217
|
+
<ul id="tree" class="ztree" style='width:100%'>
|
218
|
+
|
219
|
+
</ul>
|
220
|
+
</div>
|
221
|
+
<div id='readme' style='width:70%;margin-left:20%;'>
|
222
|
+
<article class='markdown-body'>
|
223
|
+
#{parse_markdown}
|
224
|
+
</article>
|
225
|
+
</div>
|
226
|
+
</div>
|
227
|
+
<div id="normal-button" class="settings-button">
|
228
|
+
<img src="toc/img/icon-cog-small.png" />
|
229
|
+
</div>
|
230
|
+
|
231
|
+
|
232
|
+
</div><!-- /scroller-inner -->
|
233
|
+
</div><!-- /scroller -->
|
234
|
+
|
235
|
+
</div><!-- /pusher -->
|
236
|
+
</div><!-- /container -->
|
237
|
+
|
238
|
+
|
239
|
+
</body>
|
240
|
+
</html>
|
241
|
+
<script type="text/javascript" src="toc/js/jquery.js"></script>
|
242
|
+
<script type="text/javascript" src="toc/js/jquery.ztree.all-3.5.min.js"></script>
|
243
|
+
<script type="text/javascript" src="toc/js/ztree_toc.js"></script>
|
244
|
+
<script type="text/javascript" src="toc/toc_conf.js"></script>
|
245
|
+
<script src="toc/js/classie.js"></script>
|
246
|
+
<script src="toc/js/mlpushmenu.js"></script>
|
247
|
+
<script src="toc/js/modernizr.custom.js"></script>
|
248
|
+
<script src="toc/js/jquery.transtool.js"></script>
|
249
|
+
|
250
|
+
<SCRIPT type="text/javascript" >
|
251
|
+
<!--
|
252
|
+
$(document).ready(function(){
|
253
|
+
var css_conf = eval(markdown_panel_style);
|
254
|
+
$('#readme').css(css_conf)
|
255
|
+
|
256
|
+
var conf = eval(jquery_ztree_toc_opts);
|
257
|
+
$('#tree').ztree_toc(conf);
|
258
|
+
|
259
|
+
new mlPushMenu( document.getElementById( 'mp-menu' ), document.getElementById( 'normal-button' ), {
|
260
|
+
type : 'cover'
|
261
|
+
} );
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
// <li id='todo'><a class="icon icon-shop" href="#">todo</a></li>
|
266
|
+
// <li id='review'><a class="icon icon-cloud" href="#">review</a></li>
|
267
|
+
// <li id='ok'><a class="icon icon-diamond" href="#">ok</a></li>
|
268
|
+
// <li id='zh'><a class="icon icon-photo" href="#">中文</a></li>
|
269
|
+
// <li id='en'><a class="icon icon-wallet" href="#">英文</a></li>
|
270
|
+
//<li id='all'><a class="icon icon-shop" href="#">show all</a></li>
|
271
|
+
$.transtool({
|
272
|
+
toolbarselector:"#mp-menu",
|
273
|
+
default_state:'zh',
|
274
|
+
states:[
|
275
|
+
{
|
276
|
+
'all':{
|
277
|
+
'icon':'icon-shop',
|
278
|
+
'display':"全部",
|
279
|
+
click:function(){
|
280
|
+
alert('zh111');
|
281
|
+
}
|
282
|
+
},
|
283
|
+
'zh':{
|
284
|
+
'icon':'icon-world',
|
285
|
+
'display':"中文",
|
286
|
+
click:function(){
|
287
|
+
alert('zh111');
|
288
|
+
}
|
289
|
+
},
|
290
|
+
'en':{
|
291
|
+
'icon':'icon-cloud',
|
292
|
+
'display':"英文",
|
293
|
+
click:function(){
|
294
|
+
alert('en');
|
295
|
+
}
|
296
|
+
}
|
297
|
+
}
|
298
|
+
]
|
299
|
+
});
|
300
|
+
|
301
|
+
// $('#tree').hide()
|
302
|
+
|
303
|
+
});
|
304
|
+
//-->
|
305
|
+
</SCRIPT>
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
if destiny_dir.to_s.index('/')
|
310
|
+
# p '1build src/' + destiny_dir.to_s.split('/')[1] + '/' + ff.gsub('.md','') + '.html'
|
311
|
+
build_dir = 'preview/'
|
312
|
+
|
313
|
+
p 'build = ' + dest_dir + '/' + ff.gsub('.md','') + '.html'
|
314
|
+
IO.write(dest_dir + '/' + ff.gsub('.md','') + '.html',t) # => 10
|
315
|
+
else
|
316
|
+
# p '2build src/' + ff.gsub('.md','') + '.html'
|
317
|
+
build_dir = 'preview/'
|
318
|
+
# write to html file
|
319
|
+
IO.write(build_dir + '/' + ff.gsub('.md','') + '.html',t) # => 10
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
|
326
|
+
require 'redcarpet'
|
327
|
+
require 'pygments'
|
328
|
+
|
329
|
+
require 'redcarpet'
|
330
|
+
require 'rexml/document'
|
331
|
+
module Redcarpet::Render
|
332
|
+
class Custom < Base
|
333
|
+
def header(title, level)
|
334
|
+
@headers ||= []
|
335
|
+
|
336
|
+
title_elements = REXML::Document.new(title)
|
337
|
+
flattened_title = title_elements.inject('') do |flattened, element|
|
338
|
+
flattened += if element.respond_to?(:text)
|
339
|
+
element.text
|
340
|
+
else
|
341
|
+
element.to_s
|
342
|
+
end
|
343
|
+
end
|
344
|
+
permalink = flattened_title.downcase.gsub(/[^a-z\s]/, '').gsub(/\W+/, "-")
|
345
|
+
|
346
|
+
# for extra credit: implement this as its own method
|
347
|
+
if @headers.include?(permalink)
|
348
|
+
permalink += "_1"
|
349
|
+
# my brain hurts
|
350
|
+
loop do
|
351
|
+
break if !@headers.include?(permalink)
|
352
|
+
# generate titles like foo-bar_1, foo-bar_2
|
353
|
+
permalink.gsub!(/\_(\d+)$/, "_#{$1.to_i + 1}")
|
354
|
+
end
|
355
|
+
end
|
356
|
+
@headers << permalink
|
357
|
+
%(\n<h#{level}><a name="#{permalink}" class="anchor" href="##{permalink}"><span class="anchor-icon"></span></a>#{title}</h#{level}>\n)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
class HTMLwithPygments < Redcarpet::Render::HTML
|
363
|
+
def doc_header()
|
364
|
+
'<style>' + Pygments.css('.highlight',:style => 'friendly') + '</style>'
|
365
|
+
end
|
366
|
+
|
367
|
+
def block_code(code, language)
|
368
|
+
Pygments.highlight(code, :lexer => language, :options => {:encoding => 'utf-8'})
|
369
|
+
end
|
370
|
+
end
|