Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP code syntax coloring in HTML
Message
 
 
To
06/04/2000 16:43:42
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00355687
Message ID:
00359828
Views:
26
Mike,

I prepared a new version of your program.

How does it sound? Works much faster, than yours... See commented lines (I just have not enough time to check case, when we have a string (don't need to insert tags in string).
********************************************************************
*  Description.......: nnHTMLCode
*  Calling Samples...: on key label F9 _cliptext=nnHTMLCode(_cliptext)
*  Parameter List....: lcCode, lcPath, lcBeatify
*  Created by........: Mike Helland
*  Modified by.......: Nadya Nosonovsky 04/13/2000 11:02:34 AM
********************************************************************
 lparameters lcCode, lcPath, lcBeatify
 if empty(lcCode)or vartype(lcCode)<>'C'&& Check if first parameter exists
    return.f.
 endif
 lnSec=seconds()
 if vartype(lcBeatify)<>'C'
    release lcBeatify
    lcBeatify='M'&& Mixed
 endif
 if vartype(lcBeatify)='C' and not inlist(left(upper(lcBeatify),1),'U','L')
    lcBeatify='M'
 endif
 #define SINGLEQUOTE chr(39)
 #define DOUBLEQUOTE chr(34)
 #define LEFTPAR   chr(91)
 #define RIGHTPAR  chr(91)
 #define FONTBLUE  '<font color=blue>'
 #define FONTGREEN  '<font color=green>'
 #define FONTEND   '</font>'
 #define SYMBOLS   ':;./\<>+=-{}[]()#*'
*Do some basic HTML intializing
 lcCode=strtran(lcCode, chr(9), space(5))
 lcCode=strtran(lcCode, '&', '&')
 lcCode=strtran(lcCode, '<', '<')
 lcCode=strtran(lcCode, '>', '>')
*Create an array ouf of our strings.
 local laLines[1], lcReturn, lnLines, lnI, lcLine, lnWA
 local lcFL, lcComment, lcBeforeComment, lnWords, lcResult
 dimension laWords[1]
 local lcDoubleAmp, lnStartComment, k, lcLeft, lcRight
 lnLines=alines(laLines, lcCode)
 lcReturn='<pre>'
 lnWA=select()
 if !used('words')
    use(iif(empty(lcPath), '', lcPath)+'words')in 0 order tag revword
 endif
*Proccess each line
 for lnI=1 to lnLines
    lcLine=laLines[lnI]
*Don't even bother the blank ones
    if empty(alltrim(lcLine))
      lcReturn=lcReturn+chr(13)+chr(10)
      loop
    endif
*Full Line Comments, first
    if left(alltrim(lcLine),1)='*'
      lcLine=FONTGREEN+lcLine+FONTEND
*Print line here
      lcReturn=lcReturn+chr(13)+chr(10)+lcLine
      loop
    endif
    lcComment=''
    lcBeforeComment=lcLine
*     lcFL = ' '+ upper(trim(chrtran(lcBeforeComment, ':;./\<>+=-}]()#', space(15)))) + ' '
*Now end of the line comments
    lcDoubleAmp='&&'&& This is to test our function
    lnStartComment=at(lcDoubleAmp, lcLine)
    if lnStartComment >0
      lcComment=FONTGREEN+substr(lcLine, lnStartComment)+FONTEND
      lcBeforeComment=substr(lcLine, 1,lnStartComment-1)
    endif
*!* Devide string into words
    lnWords=aparser(@laWords, lcBeforeComment,SYMBOLS)
    lcResult=''
    for k=1 to lnWords
*!*              lcLeft=left(laWords[k],1)
*!*              lcRight=''
*!*
*!*              if inlist(lcLeft,DOUBLEQUOTE,SINGLEQUOTE,LEFTPAR) && String starts
*!*                 lcResult=lcResult+laWords[k]
*!*                 if len(laWords[k])>1
*!*                      lcRight=right(laWords[k],1)
*!*                  endif
*!*                  if lcLeft=LEFTPAR
*!*                     lcLeft=RIGHTPAR
*!*                  endif
*!*                  k=k+1
*!*                  do while k<=lnWords  and (lcLeft=lcRight or lcLeft=left(laWords[k],1))
*!*                     lcLeft=left(laWords[k],1)
*!*                      if len(laWords[k])>1
*!*                           lcRight=right(laWords[k],1)
*!*                       endif
*!*                       if lcLeft=LEFTPAR
*!*                          lcLeft=RIGHTPAR
*!*                       endif
*!*                     lcResult=lcResult+laWords[k]
*!*                       k=k+1
*!*                  enddo
*!*                 endif
      if not empty(laWords[k])and seek(upper(padr(laWords[k],22)),'words','revword')&& Word found
         do case
         case left(upper(lcBeatify),1)='U'&& Upper case
           laWords[k]=upper(laWords[k])
         case left(upper(lcBeatify),1)='L'&& Lower case
           laWords[k]=lower(laWords[k])
         endcase
         laWords[k]=FONTBLUE+laWords[k]+FONTEND
      endif
      lcResult=lcResult+;
         iif(laWords[k]$SYMBOLS or(k>1 and laWords[k-1]$SYMBOLS),'',space(1))+laWords[k]
   next
    if not empty(lcBeforeComment)and not empty(lcResult)
      lcBeforeComment=lcResult
    endif
*Submit the process line
    lcReturn=lcReturn +chr(13)+chr(10)+lcBeforeComment+lcComment&& Another In Line Test to use
 endfor
 lcReturn=lcReturn +'</pre>'
 use in words
 select(lnWA)
 wait window nowait 'Transformed '+alltrim(str(lnLines))+' lines in '+alltrim(str(seconds()-lnSec))+' sec'
 return lcReturn
**********************************************************************
 function aparser
*  Description.......: Function parses a text string into an array.
*                    : Each element of the array contains one word...
*  Calling Samples...: dimension laWords[1]
*                    : lcWordString = "Some text string"
*                    : lnWords = aparser(@laWords, lcWordString)
*  Parameter List....: paWords, pcWordString, pcDelimiter
********************************************************************
 lparameter paWords, pcWordString, pcDelimiter
 local lnWords, i, lcSymbol
 lcDelimiter=space(1)
 external array paWords
 if vartype(pcDelimiter)<>'C'
    pcDelimiter=space(1)
 endif
 for i=1 to len(pcDelimiter)
    lcSymbol=substr(pcDelimiter,i,1)
    pcWordString=strtran(pcWordString,lcSymbol,space(1)+lcSymbol+space(1))
 next
*!* Replace the delimiter with CHR(13) using STRTRAN.
 pcWordString=strtran(pcWordString, space(1), chr(13))
*!* Now put each element in an array.
 lnWords=alines(paWords, pcWordString)
 return lnWords
How without < b >?
>
>You can modify it however you wish. If you ever read a foxtalk article, you may have noticed any code sampes are bolded, thats why I included that, also, any tabs were converted to spaces for the same reason, and it actually made it easier.
>
>I also had code a white box around it so it would have a white background too, but the UT doesn't allow the TABLE tag, which is what I used. So HTMLers, how can I do that with only simple HTML (IE and NS).
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform