如何修改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. javascript - 关于Js中 this的一道题2. javascript - vue生成一维码?求助!!!!!急3. 求大神帮我看看是哪里写错了 感谢细心解答4. css - 手机页面在安卓和苹果浏览器显示不同的小小问题5. javascript - 修改表单多选项时和后台同事配合的问题。6. javascript - jqery ajax问题7. thinkjs - 使用mysql搭建cms应该如何设计表?或怎样开始?8. javascript - H5页面怎么查看console信息?9. java中没有抽象方法的抽象类有什么意义?仅仅是为了让别人不能创建该类的对象?10. mysql 获取时间函数unix_timestamp 问题?
