Last active
November 24, 2015 05:20
-
-
Save Quotation/2fd1ef8a4706ce48db40 to your computer and use it in GitHub Desktop.
Tower.im 文档编辑自动编号
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function() {$('<button type="button" class="btn btn-numbering">标题重新编号</button>') .appendTo($('.save-btns-wrap .form-field')) .click(function() {var numbers = [0, 0, 0, 0, 0, 0]; $('H1,H2,H3,H4,H5,H6', $('.simditor-body')).each(function(i, e) {var level = parseInt(e.tagName[1]); numbers[level - 1] += 1; for (var i = level; i < numbers.length; i++) {numbers[i] = 0; } var prefix = numbers.slice(0, level).join('.'); e = $(e); var title = e.text(); if (!title.startsWith(prefix)) {title = title.replace(/^(\d\.)*\d\s?/, ''); e.text(prefix + ' ' + title); } }); }); })() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
$('<button type="button" class="btn btn-numbering">标题重新编号</button>') | |
.appendTo($('.save-btns-wrap .form-field')) | |
.click(function() { | |
var numbers = [0, 0, 0, 0, 0, 0]; | |
$('H1,H2,H3,H4,H5,H6', $('.simditor-body')).each(function(i, e) { | |
var level = parseInt(e.tagName[1]); | |
numbers[level - 1] += 1; | |
for (var i = level; i < numbers.length; i++) { | |
numbers[i] = 0; | |
} | |
var prefix = numbers.slice(0, level).join('.'); | |
e = $(e); | |
var title = e.text(); | |
if (!title.startsWith(prefix)) { | |
title = title.replace(/^(\d\.)*\d\s?/, ''); | |
e.text(prefix + ' ' + title); | |
} | |
}); | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
为Tower.im的文档自动加上标题编号,效果如下:
#1 一级标题
1.1 二级标题
1.1.1 三级标题
用法
当在Tower编辑文档时,把
tower-numbering-bookmark.js
的内容拷到浏览器地址栏,回车。会发现编辑器最下方增加了一个按钮“标题重新编号”。每次点击此按钮时,文档内的所有标题即自动编号。使用限制