Syntax language can be highlighted

Reply

Join Date: Feb 2002
Posts: 12,043
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 129
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Syntax language can be highlighted

 
0
  #1
Oct 24th, 2006
Hey guys! Just what you've been waiting for ... You can now specify a language within your code bbcode to use syntax highlighting just like in our code snippet library.

For example ... Just do [code=c] ...

  1. printf("Hello World\n");

Additionally, you can use the noparse bbcode when you don't want bbcode to be parsed. For example ... [b]Hi[/b] ... notice that [b] wasn't parsed into bold despite a matching close tag and no funky spaces thrown in.
Last edited by cscgal; Oct 24th, 2006 at 9:36 pm.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Syntax language can be highlighted

 
0
  #2
Oct 25th, 2006
Excellent!!!

If I may humbly suggest a few visual suggestions, though:
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. char* Word[]= { "Alpha ", "Bravo ", "Charlie ", "Delta ", "Echo ",
  5. "Foxtrot ", "Golf ", "Hotel ", "India ", "Juliet ",
  6. "Kilo ", "Lima ", "Mike ", "November ","Oscar ",
  7. "Papa ", "Quebec ", "Romeo ", "Sierra ", "Tango ",
  8. "Uniform ", "Victor ", "Whiskey ", "X=ray ", "Yankee ",
  9. "Zulu "
  10. };
  11.  
  12. int main() // This is a comment
  13. {
  14. char inbuf[200];
  15. char *p;
  16. int i;
  17.  
  18. printf("Enter: ");
  19. fgets(inbuf, 200, stdin);
  20.  
  21. p = inbuf;
  22. while (*p)
  23. {
  24. if (isupper(*p))
  25. {
  26. i = *p - 'A';
  27. printf("%s", Word[i]);
  28. }
  29. else
  30. if (islower(*p))
  31. {
  32. i = *p - 'a';
  33. printf("%s", Word[i]);
  34. }
  35. else
  36. {
  37. putchar(*p);
  38. }
  39. p++;
  40. }
  41.  
  42. return 1;
  43. }
To follow more closely what I've seen:
comments in green
"Strings" and 'characters' in blue
Numbers in dark blue
Keywords in bold purple (no underline)
All else is black
C/C++ functions don't need to be colored, but if they are, use a dark color like maybe red

All the colors should be of a similar intensity. The switch from the keyword-yellow to function-underline/blue is too striking.


 #include <stdio.h>
 #include <ctype.h>

 char* Word[]= { "Alpha ",   "Bravo ",   "Charlie ", "Delta ",   "Echo ",    
                "Foxtrot ", "Golf ",    "Hotel ",   "India ",   "Juliet ",  
                "Kilo ",    "Lima ",    "Mike ",    "November ","Oscar ",   
                "Papa ",    "Quebec ",  "Romeo ",   "Sierra ",  "Tango ",   
                "Uniform ", "Victor ",  "Whiskey ", "X=ray ",   "Yankee ",  
                "Zulu "
              };

int main()   // This is a comment
{
    char  inbuf[200];
    char *p;
    int   i;
    
    printf("Enter: ");
    fgets(inbuf, 200, stdin);
    
    p = inbuf;
    while (*p)
    {
        if (isupper(*p))
        {
            i = *p - 'A';
            printf("%s", Word[i]);
        }
        else
        if (islower(*p))
        {
            i = *p - 'a';
            printf("%s", Word[i]);
        }
        else
        {
            putchar(*p);
        }
        p++;
    }
    
    return 1;
}
I also notice in the [code=c] section, there is no formatting displayed in the edit window. I assume that's just a glitch, but I thought I'd at least point it out, just in case.

Also, is there a possibility to close up the gap between lines just a tad -- at least as a test? I'd like to see a little less space and a little more code. Instead of 1.5 spacing maybe 1.25.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Syntax language can be highlighted

 
1
  #3
Oct 26th, 2006
Or how about 1.00...

But WaltP's colors are all wrong. Yours are better. (Mine are the best. No you can't have them )

I know! Let's through obscure languages at the feature!

  1. factorial 0 = 1
  2. factorial n = n * factorial (n - 1)

It doesn't look like you have Haskell highlighting yet.

  1. ((call/cc call/cc)
  2. (lambda (f)
  3. (display "Hello, world!")
  4. (newline)
  5. (f f)))

Well at least you have Scheme. But the highlighting is broken, since it treats display and newline like keywords, when they're just built-in procedures.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC