i5ting_toc工具优化

i5ting_ztree_toc:

this is a jQuery plugin for preview markdown table of content.

Address

官网:https://www.npmjs.com/package/i5ting_toc
github源码:https://github.com/i5ting/i5ting_ztree_toc
gitgee源码:https://gitee.com/mirrors/i5ting_ztree_toc

ruby版本tocmd:https://github.com/i5ting/tocmd.gem
node版本i5ting_toc:https://github.com/i5ting/tocmd.npm
zTree_Toc lite version:https://github.com/i5ting/markdown_toc

Node i5ting_toc

Install

npm install -g i5ting_toc

使用

CMD:

i5ting_toc -f sample.md

PowerShell:

i5ting_toc.cmd -f sample.md -o

参数说明:

Options:
-V, --version output the version number
-f, --file [filename] default is README.md
-o, --open open in browser
-v, --verbose 打印详细日志
-h, --help output usage information

定制修改

i5ting_toc 默认参数修改

文件路径:C:\Users\xxx\AppData\Roaming\npm\node_modules\i5ting_toc\bin\tocmd.js
可修改默认输入文件名,生成html的默认存储路径,是否默认生成html后打开该文件等。

参数说明:
pwd是存放preview的位置
source_file 要编译的mardown文件
dest_file_path 生成的html完整路径和文件名
is_open 是否在编译后使用浏览器中打开html
markd_config 编译md的选项(具体见 https://github.com/chjj/marked )

参考:
https://www.npmjs.com/package/i5ting_toc
https://marked.js.org

Example:
修改默认生成html文件存储路径:
修改:C:\Users\xxx\AppData\Roaming\npm\node_modules\i5ting_toc\bin\tocmd.js

var dest_file_path = pwd + '/mynotes/' + _file_name + '.html'

修改:C:\Users\xxx\AppData\Roaming\npm\node_modules\i5ting_toc\index.js

var preview_path = pwd + '/mynotes'

渲染html格式修改

i5ting_toc 引用了开源的markdjs, 配置文件路径如下:
正在处理文件: C:\Users\xxx\AppData\Roaming\npm\node_modules\i5ting_toc\node_modules\marked\lib\marked.js
通过此文件marked.defaults 可修改是否支持换行,是否支持Table语法, 是否支持Git Hub标准的markdown等。
参数如下:

OPTIONS
       -o, --output [output]
	      Specify file output. If none is specified, write to stdout.

       -i, --input [input]
	      Specify file input, otherwise use last argument as  input  file.
	      If no input file is specified, read from stdin.

       -t, --tokens
	      Output a token stream instead of html.

       --pedantic
	      Conform  to  obscure  parts  of markdown.pl as much as possible.
	      Don't fix original markdown bugs.

       --gfm  Enable github flavored markdown.

       --breaks
	      Enable GFM line breaks. Only works with the gfm option.

       --tables
	      Enable GFM tables. Only works with the gfm option.

       --sanitize
	      Sanitize output. Ignore any HTML input.

       --smart-lists
	      Use smarter list behavior than the original markdown.

       --lang-prefix [prefix]
	      Set the prefix for code block classes.

       --mangle
	      Mangle email addresses.

       --no-sanitize, -no-etc...
	      The inverse of any of the marked options above.

       --silent
	      Silence error output.

       -h, --help
	      Display help information.

Example:
转换Markdown为html支持文本回车换行,修改如下:

breaks:true

Reference:
https://www.cnblogs.com/djtao/p/6224399.html

支持语法高亮

修改:C:\Users\xxx\AppData\Roaming\npm\node_modules\i5ting_toc\node_modules\marked\lib\marked.js 804行如下:

  if (!lang) {
    return '<pre class="prettyprint linenums:0"><code>'

修改: C:\Users\xxx\AppData\Roaming\npm\node_modules\i5ting_toc\vendor\template.html

<script type="text/javascript" src="toc_conf.js"></script>
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script> <!--  增加这一行 -->

延时加载树结构(防止树结构点击定位不准):

<SCRIPT type="text/javascript" >
<!--
$(document).ready(function(){
    var css_conf = eval(markdown_panel_style);
    $('#readme').css(css_conf)

    var conf = eval(jquery_ztree_toc_opts);
    setTimeout(function () {
    	$('#tree').ztree_toc(conf);
    },500);
});
//-->
</SCRIPT>

Reference Doc

https://www.npmjs.com/package/i5ting_toc
https://github.com/chjj/marked

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值