Monday, January 3, 2011

Post process the html file for blogger using vi script

"function to post-process the html file created by TOhtml for blogger
"copyright @ http://scriptdemo.blogspot.com

:if exists("TOblogger_loaded")
:   delfun TOblogger
:   delfun RePlaceSpace
:endif

:function TOblogger()
:set nowrap
:1,$ call RePlaceSpace()
:endfunction

:function RePlaceSpace()
:let line = getline(".")
:if line =~ "^\ "
:   let line = substitute(line,"^\ ",'\ ',"g")
:   while line =~ "  "
:            let line = substitute(line,' \ ','\ \ ',"g")
:   endwhile
:   call setline(".",line)
:endif
:unlet line
:endfunction
:let TOblogger_loaded = 1
An html file can be generated from the source code file using the vim "build-in" command TOhtml. However, to publish in blogger, the blank spaces will be ignored by blogger, which results in a ugly view. Here using the script (TOblogger.vim), you can replace the blank spaces at the beginning of each line with  
To use it, you need to open the html file first, then
                             :source TOblogger.vim   #using the path if necessary
                             :call TOblogger()
and save your new html file using :w
Enjoy!

1 comment:

who said...

Do you use vim?
If you do, you can follow what i said in the post to generate the html source code and then post in blogger.
It's not a necessary procedure, but make the code block look better.

ShowCalendar