Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

issue #14

Convert highlighting to syntax highlighting, so a plugin like TOhtml can
properly generate a website with all colors highlighted correctly.
  • Loading branch information...
commit b274ce2368582f22d4aedf65af34c1bfcef2002b 1 parent b569b1d
@chrisbra authored
View
25 autoload/Colorizer.vim
@@ -1220,6 +1220,10 @@ function! s:Init(...) "{{{1
let s:color_names = 1
endif
+ if exists("g:colorizer_persist")
+ let s:color_syntax = 1
+ endif
+
if !s:force_hl && s:old_fgcontrast != g:colorizer_fgcontrast
\ && s:swap_fg_bg == 0
" Doesn't work with swapping fg bg colors
@@ -1533,10 +1537,17 @@ function! Colorizer#ColorOff() "{{{1
unlet! s:match_list
endfu
-function! Colorizer#DoColor(force, line1, line2) "{{{1
+function! Colorizer#DoColor(force, line1, line2, ...) "{{{1
" initialize plugin
try
call s:Init(a:force)
+ if exists("a:1")
+ if a:1 =~# '^\%(syntax\|nomatch\)$'
+ let s:color_syntax = 1
+ elseif a:1 =~# '^\%(nosyntax\|match\)$'
+ let s:color_syntax = 0
+ endif
+ endif
catch /nocolor/
" nothing to do
call s:Warn("Your terminal doesn't support colors or no colors".
@@ -1605,6 +1616,18 @@ function! Colorizer#DoColor(force, line1, line2) "{{{1
" search history and this can be disturbing, so delete it from there.
call histdel('/', -1)
endif
+ if exists("s:color_syntax") && s:color_syntax
+ " convert matches into synatx highlighting, so TOhtml can display it
+ " correctly
+ for hi in getmatches()
+ if hi.group !~# '\x\{6\}'
+ continue
+ endif
+ exe "syn match" hi.group "excludenl /". hi.pattern. "/ display containedin=ALL"
+ " We have syntax highlighting, can clear the matching
+ call matchdelete(hi.id)
+ endfor
+ endif
call s:SaveRestoreOptions(0, save, [])
call winrestview(_a)
endfu
View
21 doc/Colorizer.txt
@@ -57,10 +57,17 @@ matches in the file.
This plugin defines the following commands:
*:ColorHighlight*
-:[range]ColorHighlight[!] Scan the lines given by [range] for color codes
- names and highlight those. If [range] is omitted,
- the whole file will be scanned. If the ! is used,
- the plugin will redefine all highlighting groups.
+:[range]ColorHighlight[!] [args]
+
+Scan the lines given by [range] for color codes names and highlight those. If
+[range] is omitted, the whole file will be scanned. If the ! is used, the
+plugin will redefine all highlighting groups.
+
+[args] can by any of "syntax" or "match". Syntax means to convert the
+highlighting to syntax highlighting. This is useful, so a plugin like
+|2html.vim| can convert the colors correctly to website. The default is
+"match", which means to use the |matchadd()| function. (Prepending a "no" is
+allowed, to disable that setting and use the opposite).
*:ColorClear*
:ColorClear Turn off Color highlighting.
@@ -72,7 +79,7 @@ This plugin defines the following commands:
format #RRGGBB (the hex format of the colors reg,
green and blue the '#' is optional or
alternatively like rgb(X,X,X)
-
+
Uses the number of colors your terminal is capable
to handle (or 256 colors for gVim).
@@ -238,7 +245,9 @@ looking at my Amazon whishlist: http://www.amazon.de/wishlist/2BKAHE8J7Z6UW
0.8: (unreleased) {{{1
- https://github.com/chrisbra/color_highlight/issues/13 (colorizing should not
- stop at word-boundaries
+ stop at word-boundaries, reported by teschmitz, thanks!)
+- https://github.com/chrisbra/color_highlight/issues/14 (convert highlighting
+ to syntax groups, so TOhtml works, reported by teschmitz, thanks!)
0.7: Jul 25, 2012 {{{1
- Highlight rgb colors with whitespace after comma (reported by sergey-vlasov
View
9 plugin/ColorizerPlugin.vim
@@ -24,9 +24,14 @@ let g:loaded_colorizer = 1
let s:cpo_save = &cpo
set cpo&vim
+" helper functions "{{{1
+fu! ColorHiArgs(A,L,P)
+ return "syntax\nmatch\nnosyntax\nnomatch"
+endfu
+
" define commands "{{{1
-command! -bang -range=% ColorHighlight
- \ :call Colorizer#DoColor(<q-bang>, <q-line1>, <q-line2>)
+command! -bang -range=% -nargs=? -complete=custom,ColorHiArgs ColorHighlight
+ \ :call Colorizer#DoColor(<q-bang>, <q-line1>, <q-line2>, <q-args>)
command! -bang -nargs=1 RGB2Xterm
\ :call Colorizer#RGB2Term(<q-args>)
Please sign in to comment.
Something went wrong with that request. Please try again.