vimwiki

Personal wiki for vim
git clone https://github.com/vimwiki/vimwiki.git
Log | Files | Refs | README | LICENSE

commit 2141fde8b8c68ce8c6136673890acc354dc78f8c
parent 064a8f7ade20311601fb3618955e7fcf677b916f
Author: ysftaha <tahay@uwindsor.ca>
Date:   Sat, 18 Dec 2021 09:40:17 -0500

Addresses issue #621 (#1181)

* issue#621: html highlighter

* docs for issue#621

* removing windows support for issue#621

Co-authored-by: Tinmarino <tinmarino@gmail.com>
Diffstat:
Mautoload/vimwiki/html.vim | 26++++++++++++++++++++++++++
Mautoload/vimwiki/vars.vim | 2++
Mdoc/vimwiki.txt | 36++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim @@ -1879,6 +1879,32 @@ function! s:convert_file(path_html, wikifile) abort return '' endif call vimwiki#path#mkdir(path_html) + + if g:vimwiki_global_vars['listing_hl'] > 0 && has("unix") + let i = 0 + while i < len(html_lines) + if html_lines[i] =~ '^<pre .*type=.\+>' + let type = split(split(split(html_lines[i], 'type=')[1], '>')[0], '\s\+')[0] + let attr = split(split(html_lines[i], '<pre ')[0], '>')[0] + let start = i + 1 + let cur = start + + while html_lines[cur] !~ '^<\/pre>' + let cur += 1 + endwhile + + let tmp = ('tmp'. split(system('mktemp -p . --suffix=.' . type, 'silent'), 'tmp')[-1])[:-2] + call system('echo ' . shellescape(join(html_lines[start:cur - 1], '\n')) . ' > ' . tmp) + call system(g:vimwiki_global_vars['listing_hl_command'] . ' ' . tmp . ' > ' . tmp . '.html') + let html_out = system('cat ' . tmp . '.html') + call system('rm ' . tmp . ' ' . tmp . '.html') + let i = cur + let html_lines = html_lines[0:start - 1] + split(html_out, '\n') + html_lines[cur:] + endif + let i += 1 + endwhile + endif + call writefile(html_lines, path_html.htmlfile) return path_html . htmlfile endif diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim @@ -167,6 +167,8 @@ function! s:get_default_global() abort \ }}, \ 'links_header': {'type': type(''), 'default': 'Generated Links', 'min_length': 1}, \ 'links_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6}, + \ 'listing_hl': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'listing_hl_command': {'type': type(''), 'default': 'pygmentize -f html'}, \ 'listsyms': {'type': type(''), 'default': ' .oOX', 'min_length': 2}, \ 'listsym_rejected': {'type': type(''), 'default': '-', 'length': 1}, \ 'map_prefix': {'type': type(''), 'default': '<Leader>w'}, diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt @@ -3573,6 +3573,40 @@ The default is 1. ------------------------------------------------------------------------------ +*g:vimwiki_listing_hl* + +When set to 1, enables syntax highlighting in resulting HTML. Whenever a code +block is encountered the *g:vimwiki_listing_hl_command* is invoked on the +code block. + + +Value Description~ +0 Do not highlight code blocks in HTML. +1 Highlight code blocks in HTML. see *g:vimwiki_listing_hl_command* + +Default: 0 + + +------------------------------------------------------------------------------ +*g:vimwiki_listing_hl_command* + +A string specifying the command for highlighting code blocks in html. The +argument is going to be a file with an extension specified by a +type=extension. For example, a python listing would be written like s: > + {{{type=py + print("hello world") + }}} +The argument in this case is going to be a `foo.py`. The result of the +highlighting command is going to be enclosed in pre tags with the `type` +attribute. > + <pre type=py> + %output of highlight command& + </pre> + +The default is 'pygmentize -f html'. + + +------------------------------------------------------------------------------ *g:vimwiki_tags_header* A string with the magic header that tells Vimwiki where the generated tags @@ -3924,6 +3958,7 @@ Contributors and their Github usernames in roughly chronological order: - Vinny Furia (@vinnyfuria) - paperbenni (@paperbenni) - Lily Foster (@lilyinstarlight) + - Youssof Taha (@ysftaha) - Thomas Leyh (@leyhline) ============================================================================== @@ -3936,6 +3971,7 @@ http://code.google.com/p/vimwiki/issues/list. They may be accessible from https://github.com/vimwiki-backup/vimwiki/issues. New:~ + * Issue #621: Feature request: Highlight code listings in HTML * Issue #290: Calendar plugin, do not sign if no wiki * Issue #281: Permit `\|` in tables * PR #1128: VimwikiGoto: Support wiki pages with spaces