tocmd 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mdpreview/translator.rb +14 -11
- data/lib/mdpreview/version.rb +1 -1
- data/vendor/meta.js +1 -0
- data/vendor/toc/js/jquery.ztree_toc.js +277 -0
- data/vendor/toc/js/jquery.ztree_toc.min.js +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e83c31950b40f1c55248ccb60c5454b5ceb5a75
|
4
|
+
data.tar.gz: f212313e28a0917ec249580df4cf93fd6e6d52ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89089f917c9bbf99ecb9e5bbd4439fb8d54de6c04941949ca1772c18c8263204422d1ac52940a3a664c1a7c1925c1246cb2c8636a54d23e3c7f32458f0eda5be
|
7
|
+
data.tar.gz: 1c1e3a70cb348e29a79bc1ee05115f4e3b0436227304bbf436649cca10cce936479ee9e233641bfdce5ebdeaa0b8372cb68f6631f65b0d7e81e39914ee3cb97c
|
data/lib/mdpreview/translator.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
# require 'FileUtils'
|
3
|
+
require 'fileutils'
|
3
4
|
|
4
5
|
class Mdpreview::Translator
|
5
6
|
def initialize(source_file_path)
|
@@ -209,17 +210,18 @@ class Mdpreview::Translator
|
|
209
210
|
</style>
|
210
211
|
</head>
|
211
212
|
<body>
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
<div id='readme' style='width:834px;margin:20px auto'>
|
216
|
-
<ul id="tree" class="ztree" style="">
|
213
|
+
<div>
|
214
|
+
<div style='width:25%;'>
|
215
|
+
<ul id="tree" class="ztree" style='width:100%'>
|
217
216
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
217
|
+
</ul>
|
218
|
+
</div>
|
219
|
+
<div id='readme' style='width:70%;margin-left:20%;'>
|
220
|
+
<article class='markdown-body'>
|
221
|
+
#{parse_markdown}
|
222
|
+
</article>
|
223
|
+
</div>
|
224
|
+
</div>
|
223
225
|
</body>
|
224
226
|
</html>
|
225
227
|
<script type="text/javascript" src="#{@editor_path}/toc/js/jquery-1.4.4.min.js"></script>
|
@@ -229,7 +231,8 @@ class Mdpreview::Translator
|
|
229
231
|
<!--
|
230
232
|
$(document).ready(function(){
|
231
233
|
$('#tree').ztree_toc({
|
232
|
-
|
234
|
+
is_auto_number:true,
|
235
|
+
documment_selector:'.markdown-body'
|
233
236
|
});
|
234
237
|
});
|
235
238
|
//-->
|
data/lib/mdpreview/version.rb
CHANGED
data/vendor/meta.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/Volumes/data/Github/toc.md/
|
@@ -0,0 +1,277 @@
|
|
1
|
+
/*! ztree_toc - v0.2.0 - 2014-02-05
|
2
|
+
* https://github.com/i5ting/jQuery.zTree_Toc.js
|
3
|
+
* Copyright (c) 2014 alfred.sang; Licensed MIT */
|
4
|
+
function encode_id_with_array(opts,arr) {
|
5
|
+
var result = 0;
|
6
|
+
for(var z = 0; z < arr.length; z++ ) {
|
7
|
+
result += factor(opts, arr.length - z ,arr[z]);
|
8
|
+
}
|
9
|
+
|
10
|
+
return result;
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
/**
|
15
|
+
* 1.1.1 = 1*100*100 + 1*100 + 1
|
16
|
+
* 1.2.2 = 1*100*100 + 2*100 + 3
|
17
|
+
*
|
18
|
+
* 1 = 0*100 +1
|
19
|
+
|
20
|
+
1,1 = 100
|
21
|
+
|
22
|
+
*/
|
23
|
+
function get_parent_id_with_array(opts,arr) {
|
24
|
+
var result_arr = [];
|
25
|
+
|
26
|
+
for(var z = 0; z < arr.length; z++ ) {
|
27
|
+
result_arr.push(arr[z]);
|
28
|
+
}
|
29
|
+
|
30
|
+
result_arr.pop();
|
31
|
+
|
32
|
+
var result = 0;
|
33
|
+
for(var z = 0; z < result_arr.length; z++ ) {
|
34
|
+
result += factor(opts,result_arr.length - z,result_arr[z]);
|
35
|
+
}
|
36
|
+
|
37
|
+
return result;
|
38
|
+
}
|
39
|
+
|
40
|
+
function factor(opts ,count,current) {
|
41
|
+
if(1 == count) {
|
42
|
+
return current;
|
43
|
+
}
|
44
|
+
|
45
|
+
var str = '';
|
46
|
+
for(var i = count - 1;i > 0; i-- ) {
|
47
|
+
str += current * opts.step+'*';
|
48
|
+
}
|
49
|
+
|
50
|
+
return eval( str + '1' );
|
51
|
+
}
|
52
|
+
|
53
|
+
;(function($) {
|
54
|
+
/*
|
55
|
+
* 根据header创建目录内容
|
56
|
+
*/
|
57
|
+
function create_toc(opts) {
|
58
|
+
$(opts.documment_selector).find(':header').each(function() {
|
59
|
+
var level = parseInt(this.nodeName.substring(1), 10);
|
60
|
+
|
61
|
+
_rename_header_content(opts,this,level);
|
62
|
+
|
63
|
+
_add_header_node(opts,$(this));
|
64
|
+
});//end each
|
65
|
+
}
|
66
|
+
|
67
|
+
/*
|
68
|
+
* 渲染ztree
|
69
|
+
*/
|
70
|
+
function render_with_ztree(opts) {
|
71
|
+
var t = $(opts._zTree);
|
72
|
+
t = $.fn.zTree.init(t,opts.ztreeSetting,opts._header_nodes).expandAll(opts.is_expand_all);
|
73
|
+
// alert(opts._headers * 88);
|
74
|
+
// $(opts._zTree).height(opts._headers * 33 + 33);
|
75
|
+
|
76
|
+
$(opts._zTree).css(opts.ztreeStyle);
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
* 将已有header编号,并重命名
|
81
|
+
*/
|
82
|
+
function _rename_header_content(opts ,header_obj ,level) {
|
83
|
+
if(opts._headers.length == level) {
|
84
|
+
opts._headers[level - 1]++;
|
85
|
+
} else if(opts._headers.length > level) {
|
86
|
+
opts._headers = opts._headers.slice(0, level);
|
87
|
+
opts._headers[level - 1] ++;
|
88
|
+
} else if(opts._headers.length < level) {
|
89
|
+
for(var i = 0; i < (level - opts._headers.length); i++) {
|
90
|
+
// console.log('push 1');
|
91
|
+
opts._headers.push(1);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
if(opts.is_auto_number == true) {
|
96
|
+
$(header_obj).text(opts._headers.join('.') + '. ' + $(header_obj).text());
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
/*
|
101
|
+
* 给ztree用的header_nodes增加数据
|
102
|
+
*/
|
103
|
+
function _add_header_node(opts ,header_obj) {
|
104
|
+
var id = encode_id_with_array(opts,opts._headers);
|
105
|
+
var pid = get_parent_id_with_array(opts,opts._headers);
|
106
|
+
|
107
|
+
// 设置锚点id
|
108
|
+
$(header_obj).attr('id',id);
|
109
|
+
|
110
|
+
log($(header_obj).text());
|
111
|
+
|
112
|
+
opts._header_offsets.push($(header_obj).offset().top - opts.highlight_offset);
|
113
|
+
|
114
|
+
log('h offset ='+( $(header_obj).offset().top - opts.highlight_offset ) );
|
115
|
+
|
116
|
+
opts._header_nodes.push({
|
117
|
+
id:id,
|
118
|
+
pId:pid ,
|
119
|
+
name:$(header_obj).text()||'null',
|
120
|
+
open:true,
|
121
|
+
url:'#'+ id,
|
122
|
+
target:'_self'
|
123
|
+
});
|
124
|
+
}
|
125
|
+
|
126
|
+
/*
|
127
|
+
* 根据滚动确定当前位置,并更新ztree
|
128
|
+
*/
|
129
|
+
function bind_scroll_event_and_update_postion(opts) {
|
130
|
+
var timeout;
|
131
|
+
var highlight_on_scroll = function(e) {
|
132
|
+
if (timeout) {
|
133
|
+
clearTimeout(timeout);
|
134
|
+
}
|
135
|
+
|
136
|
+
timeout = setTimeout(function() {
|
137
|
+
var top = $(window).scrollTop(),highlighted;
|
138
|
+
|
139
|
+
if(opts.debug) console.log('top='+top);
|
140
|
+
|
141
|
+
for (var i = 0, c = opts._header_offsets.length; i < c; i++) {
|
142
|
+
// fixed: top+5防止点击ztree的时候,出现向上抖动的情况
|
143
|
+
if (opts._header_offsets[i] >= (top + 5) ) {
|
144
|
+
console.log('opts._header_offsets['+ i +'] = '+opts._header_offsets[i]);
|
145
|
+
$('a').removeClass('curSelectedNode');
|
146
|
+
|
147
|
+
// 由于有root节点,所以i应该从1开始
|
148
|
+
var obj = $('#tree_' + (i+1) + '_a').addClass('curSelectedNode');
|
149
|
+
break;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}, opts.refresh_scroll_time);
|
153
|
+
};
|
154
|
+
|
155
|
+
if (opts.highlight_on_scroll) {
|
156
|
+
$(window).bind('scroll', highlight_on_scroll);
|
157
|
+
highlight_on_scroll();
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
/*
|
162
|
+
* 初始化
|
163
|
+
*/
|
164
|
+
function init_with_config(opts) {
|
165
|
+
opts.highlight_offset = $(opts.documment_selector).offset().top;
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* 日志
|
170
|
+
*/
|
171
|
+
function log(str) {
|
172
|
+
return;
|
173
|
+
if($.fn.ztree_toc.defaults.debug == true) {
|
174
|
+
console.log(str);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
$.fn.ztree_toc = function(options) {
|
179
|
+
// 将defaults 和 options 参数合并到{}
|
180
|
+
var opts = $.extend({},$.fn.ztree_toc.defaults,options);
|
181
|
+
|
182
|
+
return this.each(function() {
|
183
|
+
opts._zTree = $(this);
|
184
|
+
|
185
|
+
// 初始化
|
186
|
+
init_with_config(opts);
|
187
|
+
|
188
|
+
// 创建table of content,获取元数据_headers
|
189
|
+
create_toc(opts);
|
190
|
+
|
191
|
+
// 根据_headers生成ztree
|
192
|
+
render_with_ztree(opts);
|
193
|
+
|
194
|
+
// 根据滚动确定当前位置,并更新ztree
|
195
|
+
bind_scroll_event_and_update_postion(opts);
|
196
|
+
});
|
197
|
+
// each end
|
198
|
+
}
|
199
|
+
|
200
|
+
//定义默认
|
201
|
+
$.fn.ztree_toc.defaults = {
|
202
|
+
_zTree: null,
|
203
|
+
_headers: [],
|
204
|
+
_header_offsets: [],
|
205
|
+
_header_nodes: [{ id:1, pId:0, name:"Table of Content",open:true}],
|
206
|
+
debug: true,
|
207
|
+
highlight_offset: 0,
|
208
|
+
highlight_on_scroll: true,
|
209
|
+
/*
|
210
|
+
* 计算滚动判断当前位置的时间,默认是50毫秒
|
211
|
+
*/
|
212
|
+
refresh_scroll_time: 50,
|
213
|
+
documment_selector: 'body',
|
214
|
+
is_posion_top: false,
|
215
|
+
/*
|
216
|
+
* 默认是否显示header编号
|
217
|
+
*/
|
218
|
+
is_auto_number: false,
|
219
|
+
/*
|
220
|
+
* 默认是否展开全部
|
221
|
+
*/
|
222
|
+
is_expand_all: true,
|
223
|
+
/*
|
224
|
+
* 是否对选中行,显示高亮效果
|
225
|
+
*/
|
226
|
+
is_highlight_selected_line: true,
|
227
|
+
step: 100,
|
228
|
+
ztreeStyle: {
|
229
|
+
width:'260px',
|
230
|
+
overflow: 'auto',
|
231
|
+
position: 'fixed',
|
232
|
+
'z-index': 2147483647,
|
233
|
+
border: '0px none',
|
234
|
+
left: '0px',
|
235
|
+
bottom: '0px',
|
236
|
+
// height:'100px'
|
237
|
+
},
|
238
|
+
ztreeSetting: {
|
239
|
+
view: {
|
240
|
+
dblClickExpand: false,
|
241
|
+
showLine: true,
|
242
|
+
showIcon: false,
|
243
|
+
selectedMulti: false
|
244
|
+
},
|
245
|
+
data: {
|
246
|
+
simpleData: {
|
247
|
+
enable: true,
|
248
|
+
idKey : "id",
|
249
|
+
pIdKey: "pId",
|
250
|
+
// rootPId: "0"
|
251
|
+
}
|
252
|
+
},
|
253
|
+
callback: {
|
254
|
+
beforeClick: function(treeId, treeNode) {
|
255
|
+
$('a').removeClass('curSelectedNode');
|
256
|
+
if(treeNode.id == 1){
|
257
|
+
// TODO: when click root node
|
258
|
+
console.log('click root table of content');
|
259
|
+
}
|
260
|
+
if($.fn.ztree_toc.defaults.is_highlight_selected_line == true) {
|
261
|
+
$('#' + treeNode.id).css('color' ,'red').fadeOut("slow" ,function() {
|
262
|
+
// Animation complete.
|
263
|
+
$(this).show().css('color','black');
|
264
|
+
});
|
265
|
+
}
|
266
|
+
},
|
267
|
+
onRightClick: function(event, treeId, treeNode) {
|
268
|
+
if(treeNode.id == 1){
|
269
|
+
// TODO: when right_click root node:table content
|
270
|
+
console.log('right_click root table of content');
|
271
|
+
}
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}
|
275
|
+
};
|
276
|
+
|
277
|
+
})(jQuery);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! ztree_toc - v0.
|
1
|
+
/*! ztree_toc - v0.2.0 - 2014-02-05
|
2
2
|
* https://github.com/i5ting/jQuery.zTree_Toc.js
|
3
3
|
* Copyright (c) 2014 alfred.sang; Licensed MIT */
|
4
|
-
function encode_id_with_array(a,b){
|
4
|
+
function encode_id_with_array(a,b){for(var c=0,d=0;d<b.length;d++)c+=factor(a,b.length-d,b[d]);return c}function get_parent_id_with_array(a,b){for(var c=[],d=0;d<b.length;d++)c.push(b[d]);c.pop();for(var e=0,d=0;d<c.length;d++)e+=factor(a,c.length-d,c[d]);return e}function factor(opts,count,current){if(1==count)return current;for(var str="",i=count-1;i>0;i--)str+=current*opts.step+"*";return eval(str+"1")}!function(a){function b(b){a(b.documment_selector).find(":header").each(function(){var c=parseInt(this.nodeName.substring(1),10);d(b,this,c),e(b,a(this))})}function c(b){var c=a(b._zTree);c=a.fn.zTree.init(c,b.ztreeSetting,b._header_nodes).expandAll(b.is_expand_all),a(b._zTree).css(b.ztreeStyle)}function d(b,c,d){if(b._headers.length==d)b._headers[d-1]++;else if(b._headers.length>d)b._headers=b._headers.slice(0,d),b._headers[d-1]++;else if(b._headers.length<d)for(var e=0;e<d-b._headers.length;e++)b._headers.push(1);1==b.is_auto_number&&a(c).text(b._headers.join(".")+". "+a(c).text())}function e(b,c){var d=encode_id_with_array(b,b._headers),e=get_parent_id_with_array(b,b._headers);a(c).attr("id",d),h(a(c).text()),b._header_offsets.push(a(c).offset().top-b.highlight_offset),h("h offset ="+(a(c).offset().top-b.highlight_offset)),b._header_nodes.push({id:d,pId:e,name:a(c).text()||"null",open:!0,url:"#"+d,target:"_self"})}function f(b){var c,d=function(){c&&clearTimeout(c),c=setTimeout(function(){var c=a(window).scrollTop();b.debug&&console.log("top="+c);for(var d=0,e=b._header_offsets.length;e>d;d++)if(b._header_offsets[d]>=c+5){console.log("opts._header_offsets["+d+"] = "+b._header_offsets[d]),a("a").removeClass("curSelectedNode"),a("#tree_"+(d+1)+"_a").addClass("curSelectedNode");break}},b.refresh_scroll_time)};b.highlight_on_scroll&&(a(window).bind("scroll",d),d())}function g(b){b.highlight_offset=a(b.documment_selector).offset().top}function h(a){}a.fn.ztree_toc=function(d){var e=a.extend({},a.fn.ztree_toc.defaults,d);return this.each(function(){e._zTree=a(this),g(e),b(e),c(e),f(e)})},a.fn.ztree_toc.defaults={_zTree:null,_headers:[],_header_offsets:[],_header_nodes:[{id:1,pId:0,name:"Table of Content",open:!0}],debug:!0,highlight_offset:0,highlight_on_scroll:!0,refresh_scroll_time:50,documment_selector:"body",is_posion_top:!1,is_auto_number:!1,is_expand_all:!0,is_highlight_selected_line:!0,step:100,ztreeStyle:{width:"260px",overflow:"auto",position:"fixed","z-index":2147483647,border:"0px none",left:"0px",bottom:"0px"},ztreeSetting:{view:{dblClickExpand:!1,showLine:!0,showIcon:!1,selectedMulti:!1},data:{simpleData:{enable:!0,idKey:"id",pIdKey:"pId"}},callback:{beforeClick:function(b,c){a("a").removeClass("curSelectedNode"),1==c.id&&console.log("click root table of content"),1==a.fn.ztree_toc.defaults.is_highlight_selected_line&&a("#"+c.id).css("color","red").fadeOut("slow",function(){a(this).show().css("color","black")})},onRightClick:function(a,b,c){1==c.id&&console.log("right_click root table of content")}}}}}(jQuery);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tocmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shiren1118
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: convert markdown to html with toc plugin
|
14
14
|
email:
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- lib/mdpreview/translator.rb
|
25
25
|
- lib/mdpreview/version.rb
|
26
26
|
- test/mdptest.rb
|
27
|
+
- vendor/meta.js
|
27
28
|
- vendor/template.html
|
28
29
|
- vendor/toc/css/demo.css
|
29
30
|
- vendor/toc/css/zTreeStyle/img/diy/1_close.png
|
@@ -43,6 +44,7 @@ files:
|
|
43
44
|
- vendor/toc/css/zTreeStyle/zTreeStyle.css
|
44
45
|
- vendor/toc/js/jquery-1.4.4.min.js
|
45
46
|
- vendor/toc/js/jquery.ztree.all-3.5.min.js
|
47
|
+
- vendor/toc/js/jquery.ztree_toc.js
|
46
48
|
- vendor/toc/js/jquery.ztree_toc.min.js
|
47
49
|
- vendor/toc/style/Clearness Dark.css
|
48
50
|
- vendor/toc/style/Clearness.css
|