您的位置:首页技术文章
文章详情页

如何修改vim插件vimwiki中Vimwiki2HTML的一些细节

【字号: 日期:2024-04-01 17:16:56浏览:118作者:猪猪

问题描述

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... 的回答。

标签: HTML
相关文章: