vimwiki默认的Vimwiki2HTML命令,会把%toc转换为当前wiki条目的目录,但是会把二级目录id转换为toc_1.1(id中含有点号),而为了使用bootstrap-scrollspy实现滚动侦测(参考:如何实现网页滚动侦测以及顶端固定导航栏),id中不能用点号。
请问:
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 the
command-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 file
2. syntax : the syntax chosen for this wiki
3. extension : the file extension for this wiki
4. output_dir : the full path of the output directory, i.e. 'path_html'
5. input_file : the full path of the wiki page
6. css_file : the full path of the css file for this wiki
For an example and further instructions, refer to the following script:
$VIMHOME/autoload/vimwiki/customwiki2html.sh
To use the internal wiki2html converter, use an empty string (the default).
我水平有限,不能直接写一个外部的脚本,想参考下vimwiki默认的脚本是什么样子,但是不知道internal wiki2html converter
的脚本在哪里。
淡淡烟草味2017-05-16 16:44:17
现在有两种方法:
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__/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... 的回答。