A vim script for pasting syntax code to webpage
Many times when I using my old blog system, I fell in bad mood when I have to mix my source code with content, or no support for source code like syntax highlighted. And when I use vim’s script TOhtml to deal with these thing, I feel that it’s handy, but still not enough convenient. I have to choose and copy the html code by my hand, then add a something like <quoteblock class=”vimblock”>(”vimblock” is a user-defined CSS element, will be mention later) tag to differentiate these code from common <quoteblock>. It’s too inconvenient, also seems easy to be done with a script. So I wrote this.
The script based on TOhtml written by Bram Moolenarr. It convert the current selection to html using TOhtml, then get the body of html and wrap it with <blockquote class=”vimblock”>. In the end, it send the wrapped section of syntax code to clipboard for the further use.
Usage: You need specify CSS for using the code generate by this script.
The default CSS of your schema can be generated by TOhtml, though it will only generate the elements that used by current file, you can find a file with most kinds of elements to generate the basis and modify it when you need more elements.
After generation, just copy the section between <!– –> just below the <style type=”text/css”>, replace element name “body” with “.vimblock” and append it to your CSS file( usually style.css).
After have well defined your CSS, you can use the V and :Yankcode and paste to use this script.
Thanks for the support from Yuxuan ‘fishy’ Wang.
The script can be found at here. And my relate style.css selection is shown below:
1 /* for vim :TOhtml */
2 .vimblock { margin-left: 1.5em;
3 padding-left: 5px;
4 border: 1px dotted #ccc;
5 border-left: 5px solid #ccc;
6 color: #ffffff;
7 background-color: #000000;}
8 .lnr { color: #ffff00; font-weight: bold; }
9 .Underlined { color: #80a0ff; text-decoration: underline; }
10 .Special { color: #ffa500; }
11 .Comment { color: #80a0ff; }
12 .Identifier { color: #40ffff; }
13 .Statement { color: #ffff60; font-weight: bold; }
14 .Constant { color: #ffa0a0; }
15 .Type { color: #60ff60; font-weight: bold; }
16 .PreProc { color: #ff80ff; }
17 .Title { color: #ff00ff; font-weight: bold; }
18 .Error { color: #ff0000; background-color: #000000; }