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>
This commit is contained in:
ysftaha
2021-12-18 09:40:17 -05:00
committed by GitHub
parent 064a8f7ade
commit 2141fde8b8
3 changed files with 64 additions and 0 deletions
+26
View File
@@ -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
+2
View File
@@ -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'},
+36
View File
@@ -3572,6 +3572,40 @@ The header level of generated links. Valid values are from 1 to 6.
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*
@@ -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