Hello Ben, Bram and list,
:TOhtml does not take the spell checking info into account. Therefore,
here is a patch, that makes 2html aware of the syntax highlighting for
SpellBad, SpellRare, SpellLocal and SpellCaps
It does this by using a simple gif file and using a css property of
'background: url(file), bottom repeat-x' For ease of use, it uses the
gif file base64 encoded inside the html file, so no separate image file
is needed in addition to the generated html file. The only problem is,
the colors are fixed to the ones, vim uses with the default color scheme
(e.g. red curly line for SpellBad, blue curly line for SpellCap, magenta
colored for SpellRare and cyan colored for SpellLocal).
All words that need to be highlighted using one of the Spelling
highlighting will get a <span id=SpellBad> tag around it.
The gif file was take away from the tinymceš project (which is LGPL
licensed) and color converted to all needed colors by me and finally
base64 encoded.
regards,
Christian
š)http://www.tinymce.com/
--
Der Fehler schwacher Geister ist, dass sie im Reflektieren
sogleich vom Einzelnen ins Allgemeine gehen, anstatt dass man nur in
der Gesamtheit das Allgemeine suchen kann.
-- Goethe, Maximen und Reflektionen, Nr. 1046
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/autoload/tohtml.vim b/runtime/autoload/tohtml.vim
--- a/runtime/autoload/tohtml.vim
+++ b/runtime/autoload/tohtml.vim
@@ -614,6 +614,7 @@
call tohtml#GetOption(user_settings, 'no_pre', 0 )
call tohtml#GetOption(user_settings, 'whole_filler', 0 )
call tohtml#GetOption(user_settings, 'use_xhtml', 0 )
+ call tohtml#GetOption(user_settings, 'spellcheck', has('spell') )
" }}}
" override those settings that need it {{{
@@ -639,6 +640,10 @@
let user_settings.use_css = 1
endif
+ if !user_settings.use_css || !&spell
+ let user_settings.spellcheck = 0
+ endif
+
" if we're not using CSS we cannot use a pre section because <font> tags
" aren't allowed inside a <pre> block
if !user_settings.use_css
diff --git a/runtime/syntax/2html.vim b/runtime/syntax/2html.vim
--- a/runtime/syntax/2html.vim
+++ b/runtime/syntax/2html.vim
@@ -152,7 +152,9 @@
endif
" Enclose in a span of class style_name
- let formatted = '<span class="' . l:style_name . '">' . formatted . '</span>'
+ if !empty(l:style_name)
+ let formatted = '<span class="' . l:style_name . '">' . formatted . '</span>'
+ endif
" Add the class to class list if it's not there yet.
" Add normal groups to the beginning so diff groups can override them.
@@ -178,7 +180,7 @@
endfun
" Return CSS style describing given highlight id (can be empty)
-function! s:CSS1(id)
+function! s:CSS1(id, ...)
let a = ""
if synIDattr(a:id, "inverse")
" For inverse, we always must set both colors (and exchange them)
@@ -195,9 +197,27 @@
if synIDattr(a:id, "bold") | let a = a . "font-weight: bold; " | endif
if synIDattr(a:id, "italic") | let a = a . "font-style: italic; " | endif
if synIDattr(a:id, "underline") | let a = a . "text-decoration: underline; " | endif
+ if len(a:000) == 1 && a:1 =~ 'Spell'
+ return a:1
+ endif
return a
endfun
+function! s:CSSCurly(name)
+ let a = 'background: url(data:image/gif;base64,'
+ if a:name == 'SpellBad'
+ let a.= 'R0lGODlhBAADAIABAPwqKv///yH5BAEAAAEALAAAAAAEAAMAAAIFRB5mGQUAOw=='
+ elseif a:name == 'SpellCap'
+ let a.= 'R0lGODlhBAADAIABAAAA/////yH5BAEAAAEALAAAAAAEAAMAAAIFRB5mGQUAOw=='
+ elseif a:name == 'SpellRare'
+ let a.= 'R0lGODlhBAADAIABAP8A/////yH5BAEAAAEALAAAAAAEAAMAAAIFRB5mGQUAOw=='
+ else
+ let a.= 'R0lGODlhBAADAIABAACLi////yH5BAEAAAEALAAAAAAEAAMAAAIFRB5mGQUAOw=='
+ endif
+ let a.=') bottom repeat-x;'
+ return a
+endfu
+
if s:settings.dynamic_folds
" compares two folds as stored in our list of folds
" A fold is "less" than another if it starts at an earlier line number,
@@ -1018,6 +1038,22 @@
endwhile
endif
+ if s:settings.spellcheck && !empty(s:new)
+ for line in split(s:new, '<[^>]*>')
+ for word in split(line)
+ let spell_list=spellbadword(word)
+ if empty(spell_list[0])
+ continue
+ endif
+ let s:spell_check_name = spell_list[1] == 'rare' ? 'SpellRare' :
+ \ spell_list[1] == 'caps' ? 'SpellCaps' :
+ \ spell_list[1] == 'bad' ? 'SpellBad' : 'SpellLocal'
+ let s:new = substitute(s:new, '[^>]*>.\{-}\zs\<' . spell_list[0] . '\>', '<span id="' .
+ \ s:spell_check_name . '">\0</span>', '')
+ endfor
+ endfor
+ endif
+
call extend(s:lines, split(s:new.s:HtmlEndline, '\n', 1))
if !s:settings.no_progress && s:pgb.needs_redraw
redrawstatus
@@ -1044,6 +1080,15 @@
endif
endif
+if s:settings.spellcheck
+ for value in ['SpellBad', 'SpellCap', 'SpellRare', 'SpellLocal']
+ let s:id = hlID(value)
+ if index(s:idlist, s:id) == -1
+ call insert(s:idlist, s:id)
+ endif
+ endfor
+endif
+
if s:settings.no_pre
if !s:settings.use_css
" Close off the font tag that encapsulates the whole <body>
@@ -1110,14 +1155,18 @@
while !empty(s:idlist)
let s:attr = ""
let s:id = remove(s:idlist, 0)
- let s:attr = s:CSS1(s:id)
let s:id_name = synIDattr(s:id, "name", s:whatterm)
+ let s:attr = s:CSS1(s:id, s:id_name)
" If the class has some attributes, export the style, otherwise DELETE all
" its occurences to make the HTML shorter
if s:attr != ""
if s:settings.use_css
- execute "normal! A\n." . s:id_name . " { " . s:attr . "}"
+ if s:id_name =~ 'Spell\%(Bad\|Cap\|Local\|Rare\)'
+ execute "normal! A\n#" . s:id_name . " { " . s:CSSCurly(s:id_name) . " } "
+ else
+ execute "normal! A\n." . s:id_name . " { " . s:attr . "}"
+ endif
else
" replace spans of just this class name with non-CSS style markup
execute '%s+<span class="' . s:id_name . '">\([^<]*\)</span>+' . s:HtmlOpening(s:id) . '\1' . s:HtmlClosing(s:id) . '+ge'
@@ -1128,6 +1177,15 @@
endif
else
execute '%s+<span class="' . s:id_name . '">\([^<]*\)</span>+\1+ge'
+ " Delete empty class names (but exclude Spelling <span>
+ " Probably not needed, but shouldn't do any harm
+ if s:settings.use_css
+ let a='<span class="">\(\%([^<]*\)\%(\%(<span '
+ \ . 'id="Spell\%(Bad\|Rare\|Local\|Caps\)">[^<]*</span>\)'
+ \ . '[^<]*\)*\)</span>'
+ exe '%s+' . a . '+\1+ge'
+ endif
+ execute '%s+<span class="' . s:id_name . '">\([^<]*\)</span>+\1+ge'
execute '%s+<span class="' . s:id_name . ' \(Diff\%(Add\|Change\|Delete\|Text\)\)">\([^<]*\)</span>+<span class="\1">\2</span>+ge'
if s:settings.use_css
1;/<\/style>/-2
@@ -1212,6 +1270,7 @@
if !s:settings.use_css
delfunc s:HtmlOpening
delfunc s:HtmlClosing
+ delfunc s:CSSCurly
endif
if s:settings.dynamic_folds
delfunc s:FoldCompare