vimwiki預設的Vimwiki2HTML指令,會把%toc轉換成目前wiki條目的目錄,但是會把二級目錄id轉換為toc_1.1(id中含有點號),而為了使用bootstrap-scrollspy實現滾動偵測(參考:如何實現網頁滾動偵測以及頂端固定導覽列),id中不能用點號。
請問:
class="nav"
,這個也是為了使用bootstrap-scrollspy。 vimwiki的幫助手冊裡這樣寫道:
vimwiki-option-custom_wiki2htmlThe following arguments, in this order, are passed to the
------------------------------------ ------------------------------------------
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
H哈哈# command-line, using '!' invocation.
|vimwiki-option-custom_wiki2html| script:1. force : [0/1] overwrite an existing file
淡淡烟草味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指令把偶數行加在奇數行的緩衝區,因此
需要放在奇數行。
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... 的回答。