搜尋

首頁  >  問答  >  主體

如何修改vim外掛程式vimwiki中Vimwiki2HTML的一些細節

vimwiki預設的Vimwiki2HTML指令,會把%toc轉換成目前wiki條目的目錄,但是會把二級目錄id轉換為toc_1.1(id中含有點號),而為了使用bootstrap-scrollspy實現滾動偵測(參考:如何實現網頁滾動偵測以及頂端固定導覽列),id中不能用點號。

請問:

  1. 怎麼能讓vimwiki產生的html檔中目錄id不含點號,例如用toc_1_1來取代toc_1.1。
  2. 怎麼能讓生成的目錄中<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 the















H哈哈# 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 ditory, 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###的腳本在哪裡。 ###
世界只因有你世界只因有你2865 天前824

全部回覆(1)我來回復

  • 淡淡烟草味

    淡淡烟草味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... 的回答。

    回覆
    0
  • 取消回覆