944,155 Members | Top Members by Rank

Ad:
Oct 24th, 2006
0

Syntax language can be highlighted

Expand Post »
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.
Similar Threads
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 163
The Queen of DaniWeb
cscgal is offline Offline
13,646 posts
since Feb 2002
Oct 25th, 2006
0

Re: Syntax language can be highlighted

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.
Moderator
Reputation Points: 3281
Solved Threads: 896
Posting Sage
WaltP is offline Offline
7,749 posts
since May 2006
Oct 26th, 2006
1

Re: Syntax language can be highlighted

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!

haskell Syntax (Toggle Plain Text)
  1. factorial 0 = 1
  2. factorial n = n * factorial (n - 1)

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

scheme Syntax (Toggle Plain Text)
  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.
Team Colleague
Reputation Points: 1135
Solved Threads: 173
Super Senior Demiposter
Rashakil Fol is offline Offline
2,480 posts
since Jun 2005
Apr 14th, 2010
0

Which [CODE] syntaxes are currently available?

I would like to see this:
[CODE=text]This is text[/CODE]
And this:
[CODE=toggled]This text is allready toggled[/CODE]
And of course, a list of supported syntaxes on the Help with Code Tags page.
Last edited by Soren Werk; Apr 14th, 2010 at 11:06 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Soren Werk is offline Offline
3 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in IT Professionals' Lounge Forum Timeline: Sorry to bother you
Next Thread in IT Professionals' Lounge Forum Timeline: Help me choose my specialization?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC