Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Wednesday, June 19, 2013

[Bash] text to html using vim built-in function TOhtml

#!/bin/bash
# convert a text file to html using vim built-in function TOhtml
# usage:
#            toHTML text-files
# http://scriptdemo.blogspot.com

if [ $# -eq 0 ]; then
   sed -n '3,4p' `which toHTML`
   exit
else
   for mytxt in $*
   do
      if [ -e ${mytxt} ]; then
         vim -c 'syntax on|TOhtml' -c 'wq|q!' ${mytxt}
      else
         echo "${mytxt} is not found"
      fi
   done
fi

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!

ShowCalendar