Tip #110: text->html table converter.
tip karma |
Rating 1/3, Viewed by 1125
|
created: |
|
September 7, 2001 2:40 |
|
complexity: |
|
intermediate |
author: |
|
Wenzhi Liang |
|
as of Vim: |
|
5.7 |
Below are two functions and a mapping which will convert lines of plain text into
HTML table code.
For example, you have several lines like:
-----------------------------------------------
1
2
3
4
5
6
---------------------------------------------------
by visualizing all the 7 lines and press <F5>, you can change the text into
<table><tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr><tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr></table>
which will eventually render into a table.
So the rule is:
Every line is a table item, every empty line means starting of a new table row.
"A text->html table code converter
"By: Wenzhi Liang [email protected]
"You can distribute/change this file freely as long as you keep the title area. Thanks
func Table()
let end=line("'>")
let start=line("'<")
let i=start
wh i <= end
exe ":" . i
let e=Empty()
if e == 1
exe "normal I</tr><tr>"
else
exe "normal I<td>A</td>>>"
endif
let i=i+1
endwh
exe "normal o</tr></table><<"
exe ":" . start
exe "normal O<table><tr><<"
endfunc
vmap <F5> <ESC>:call Table()<CR>
func Empty()
let line_nr= line (".")
let a=getline ( line_nr )
let m=match(a, "\\S")
if m == -1
return 1
else
return 0
endif
endfunc
<<jump between files |
Printing with syntax highlighting independent of your normal highlighting >>
Additional Notes
|