search

Home  >  Q&A  >  body text

How to modify some details of Vimwiki2HTML in vim plug-in vimwiki

The default Vimwiki2HTML command of vimwiki will convert %toc to the directory of the current wiki entry, but will convert the secondary directory id to toc_1.1 (the id contains a dot), and in order to use bootstrap-scrollspy to implement scrolling detection Test (reference: How to implement web page scroll detection and fixed navigation bar at the top), dots cannot be used in the id.

Excuse me:

  1. How can I make the directory id in the html file generated by vimwiki not contain a period, for example, use toc_1_1 instead of toc_1.1.
  2. How to make the <ul> tag in the generated directory have the attribute class="nav", this is also for using bootstrap-scrollspy.

The help manual of vimwiki reads:

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).

My level is limited and I cannot directly write an external script. I would like to refer to what vimwiki's default script looks like, but I don't know where the internal wiki2html converter script is.

世界只因有你世界只因有你2774 days ago763

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 16:44:17

    Now there are two methods:

    1. Use sed for batch processing; use sed to modify the html generated by vimwiki to make it conform to the specifications. The script is as follows:

    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

    Note: The sed N command adds even lines to the buffer of odd lines, so <p class="toc"> needs to be placed on odd lines.

    2. Modify the autoload/vimwiki/html.vim file as follows:

        if level > plevel
          call add(toc, '<ul class="nav">')
        elseif level < plevel
          let plevel = s:close_list(toc, plevel, level)
        endif
       

    and

        for l in range(1, h_level-1)
          let h_number .= a:id[l].'_' 
        endfor

    Thanks to themacropodus@gmail.com for the answer on Can I modified the internal wiki2html....

    reply
    0
  • Cancelreply