如何修改vim插件vimwiki中Vimwiki2HTML的一些细节
问题描述
vimwiki默认的Vimwiki2HTML命令,会把%toc转换为当前wiki条目的目录,但是会把二级目录id转换为toc_1.1(id中含有点号),而为了使用bootstrap-scrollspy实现滚动侦测(参考:如何实现网页滚动侦测以及顶端固定导航栏),id中不能用点号。
请问:
怎么能让vimwiki生成的html文件中目录id不含点号,比如用toc_1_1代替toc_1.1。怎么能让生成的目录中<ul>标签有属性class='nav',这个也是为了使用bootstrap-scrollspy。vimwiki的帮助手册里这样写道:
vimwiki-option-custom_wiki2html------------------------------------------------------------------------------Key Default value~custom_wiki2html ’’Description~The full path to an user-provided script that converts a wiki page to HTML.Vimwiki calls the provided |vimwiki-option-custom_wiki2html| script from thecommand-line, using ’!’ invocation.The following arguments, in this order, are passed to the|vimwiki-option-custom_wiki2html| script:1. force : [0/1] overwrite an existing file2. syntax : the syntax chosen for this wiki3. extension : the file extension for this wiki4. output_dir : the full path of the output directory, i.e. ’path_html’5. input_file : the full path of the wiki page6. css_file : the full path of the css file for this wikiFor an example and further instructions, refer to the following script:$VIMHOME/autoload/vimwiki/customwiki2html.shTo use the internal wiki2html converter, use an empty string (the default).我水平有限,不能直接写一个外部的脚本,想参考下vimwiki默认的脚本是什么样子,但是不知道internal wiki2html converter的脚本在哪里。
问题解答
回答1:现在有两种方法:
1. 用sed批量处理;用sed修改vimwiki生成的html,使其合乎规范,脚本如下:
sed -i ’N;s/<p class='toc'>n<ul>/<p class='toc'>n<ul class='nav'>/ ; s/toc_([0-9]*).([0-9]*)/toc_1_2/g’ ~/Documents/wiki_html/cs_html/*.html ~/Documents/wiki_html/life_html/*.html ~/Documents/wiki_html/original_html/*.html ~/Documents/wiki_html/*.html
注意:sed N命令把偶数行添加在奇数行的缓冲区,因此<p class='toc'>需要放在奇数行。
2. 修改autoload/vimwiki/html.vim文件,如下:
if level > plevel call add(toc, ’<ul class='nav'>’) elseif level < plevel let plevel = s:close_list(toc, plevel, level) endif
和
for l in range(1, h_level-1) let h_number .= a:id[l].’_’ endfor
感谢themacropodus@gmail.com 在 Can I modified the internal wiki2html... 的回答。
相关文章:
1. docker-compose中volumes的问题2. node.js - antdesign怎么集合react-redux对input控件进行初始化赋值3. python - Django ManyToManyField 字段数据在 admin后台 显示不正确,这是怎么回事?4. docker api 开发的端口怎么获取?5. angular.js - Angularjs中点击事件传递参数 给class更换样式。6. weex - Android 原生Vue.js 使用 justify-content: flex-end; 不起作用7. javascript - swiper.js嵌套了swiper 初始设置不能向下一个滑动 结束后重新初始8. angular.js - angular内容过长展开收起效果9. php由5.3升级到5.6后,登录网站,返回的是php代码,不是登录界面,各位大神有知道的吗?10. 为什么span的color非要内联样式才起作用?

网公网安备