如何修改vim插件vimwiki中Vimwiki2HTML的一些細(xì)節(jié)
問題描述
vimwiki默認(rèn)的Vimwiki2HTML命令,會(huì)把%toc轉(zhuǎn)換為當(dāng)前wiki條目的目錄,但是會(huì)把二級(jí)目錄id轉(zhuǎn)換為toc_1.1(id中含有點(diǎn)號(hào)),而為了使用bootstrap-scrollspy實(shí)現(xiàn)滾動(dòng)偵測(cè)(參考:如何實(shí)現(xiàn)網(wǎng)頁滾動(dòng)偵測(cè)以及頂端固定導(dǎo)航欄),id中不能用點(diǎn)號(hào)。
請(qǐng)問:
怎么能讓vimwiki生成的html文件中目錄id不含點(diǎn)號(hào),比如用toc_1_1代替toc_1.1。怎么能讓生成的目錄中<ul>標(biāo)簽有屬性class='nav',這個(gè)也是為了使用bootstrap-scrollspy。vimwiki的幫助手冊(cè)里這樣寫道:
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).我水平有限,不能直接寫一個(gè)外部的腳本,想?yún)⒖枷聉imwiki默認(rèn)的腳本是什么樣子,但是不知道internal wiki2html converter的腳本在哪里。
問題解答
回答1:現(xiàn)在有兩種方法:
1. 用sed批量處理;用sed修改vimwiki生成的html,使其合乎規(guī)范,腳本如下:
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命令把偶數(shù)行添加在奇數(shù)行的緩沖區(qū),因此<p class='toc'>需要放在奇數(shù)行。
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... 的回答。
相關(guān)文章:
1. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發(fā)現(xiàn)2. javascript - 在 vue里面用import引入js文件,結(jié)果為undefined3. javascript - vue-resource中如何設(shè)置全局的timeout?4. html5和Flash對(duì)抗是什么情況?5. 前端 - node vue webpack項(xiàng)目文件結(jié)構(gòu)6. Java反射問題:為什么android.os.Message的recycleUnchecked方法不能通過反射獲取到?7. php如何獲取訪問者路由器的mac地址8. 多選框?qū)戇M(jìn)數(shù)據(jù)庫怎么寫9. mysql主從 - 請(qǐng)教下mysql 主動(dòng)-被動(dòng)模式的雙主配置 和 主從配置在應(yīng)用上有什么區(qū)別?10. thinkPHP5中獲取數(shù)據(jù)庫數(shù)據(jù)后默認(rèn)選中下拉框的值,傳遞到后臺(tái)消失不見。有圖有代碼,希望有人幫忙
