Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Arbitrary colors in style-code

Greetings! I have a very small request...

Right now, there are a limited amount of [b][red]c[/red][blue]o[/blue][green]l[/green][purple]o[/purple][grey]r[/grey]s[/b] that we can use to markup posts. In addition to these, I would like to see arbitrary RGB values allowed - something like:

[ff0000]this text would be red[/ff0000]

or

[ff0000]this text would be red[/color]

This would be very easy to implement, taking 15 minutes to your time.

I have written a script that automatically syntax highlights over 300 languages and file types for this message board. However, the full spectrum of colors must be mapped down to the limited colors available on this board, so the results are sometimes very ugly. The script would be far more useful and powerful if this mapping was not necessary, if arbitrary RGB values were accepted.

A secondary, but less important request: it would be nice to be able to set the background color of CODE blocks.

Thanks!
Eric



«1

Comments

  • Eric TetzEric Tetz Posts: 2,141Member
    If you just don't have the time to do this, I will gladly add it myself. I would [italic]really[/italic] like this feature. You could just send me the module responsible for parsing post to convert style-code to HTML, and I would make the necessary changes. Language is unimportant.

    Cheers,
    Eric

  • WEBMASTERWEBMASTER Posts: 549Member
    Thanks for your offer, I will implement it by my self as soon as I got time :-)

    If you want to contribute with your syntax-coloring, then send me an email because that would be really cool to have here.

    Regarding the syntax I think something like

    [color=ff0000]this text would be red[/color] would be more
    suitable.

    What do you think?


    [blue][italic][b]/WEBMASTER[/b][/italic][/blue]


  • Eric TetzEric Tetz Posts: 2,141Member
    : Thanks for your offer, I will implement it by my self as soon as I got time :-)
    :
    : If you want to contribute with your syntax-coloring, then send me an email because that would be really cool to have here.

    Well, my syntax highlighting script is for the editor VIM. The script queries VIM for highlighting information, which it then uses to markup the text with Programmer's Heaven style-codes. With the correct command line arguments, you [italic]could[/italic] use VIM to markup text from a CGI script. Of course, this would require an extension the CODE tag so that you could specify which language to use for highlighting. Something like:

    [code=pascal]

    or

    [code language=pascal]

    : Regarding the syntax I think something like
    :
    : [color=ff0000]this text would be red[/color] would be more
    : suitable.
    :
    : What do you think?

    That's fine, though a little verbose. Some other alternatives...

    [#ff0000][/color]

    or simply:

    [#ff0000][/#]


    These are just as easy to parse (if not easier), requires less typing, and are still unlikely to conflict with valid language constructs (unlike some style codes, like 'strikethrough' and 'bold').

    In the end, it doesn't make much difference to me, as my editor will be doing the markup automatically.

    Cheers,
    Eric


    P.S. I'm sure you aware that some people's code is being incorrectly marked up when an expression in their code is mistaken for style-code. For instance, this was a common problem with [black][[/black]i] until you changed the style-code for italic to [black][[/black]italic]. However, this did not solve the problem for other style-codes like [black][[/black]x] and [black][[/black]b]. I see this all the time in code like:

    [code]for( int x=0; x<10; ++x )
    cout << myarray[black][[/black]x] << '
    '
    [/code]
    One way to prevent this in the future, without needed to modify the syntax of style-code, and without requiring style-code characters to be 'escaped' in normal text, would be to [italic]only markup text if the closing tag is found[/italic]. In the case of the code snippet above, [black][[/black]x] would not be mistaken for a style-code because there is no closing [black][[/black]/x] tag.



  • WEBMASTERWEBMASTER Posts: 549Member
    I today rewrote the message rendering code and added support for any color and and code background.

    So, now you can do this

    [size=5]
    [color=000000]P[/color][color=100000]r[/color][color=200000]o[/color][color=300000]g[/color][color=400000]r[/color][color=500000]a[/color][color=600000]m[/color][color=700000]m[/color][color=800000]e[/color][color=900000]r[/color][color=a00000]s[/color] [color=b00000]H[/color][color=c00000]e[/color][color=d00000]a[/color][color=e00000]v[/color][color=f00000]e[/color][color=ff00000]n[/color]
    [/size]

    by using the [ color=xxxxxx].....[/color] tag, where the xxxxxx is the RGB HEX values.

    Also, i also now support the use of
    [ code=xxxxxx]
    Where you can set the default background color of a code block, like

    [code=00ff00]
    case "blue"
    if closed=false then
    strBuf = strBuf & ""
    else
    strBuf = strBuf & "
    "
    end if
    [/code]




    [blue][italic][b]/WEBMASTER[/b][/italic][/blue]


  • Eric TetzEric Tetz Posts: 2,141Member
    Awesome! You rock dude!

    Here's an example of my script highlighting some Java code, with two different colorization schemes...

    [code=ffffff]
    [color=a020f0]import[/color] javax.swing.text.*;
    [color=a020f0]import[/color] javax.swing.undo.*;
    [color=a020f0]import[/color] javax.swing.event.*;
    [color=a020f0]import[/color] javax.swing.*;

    [color=80a0b0][italic]/**[/italic][/color]
    [color=80a0b0][italic] *[/italic][/color][color=907050] Sample application using the simple text editor component that[/color]
    [color=80a0b0][italic] *[/italic][/color][color=907050] supports only one font.[/color]
    [color=80a0b0][italic] */[/italic][/color]
    [color=000080][b]class[/b][/color] Notepad [color=000080][b]extends[/b][/color] JPanel {

    [color=000080][b]private[/b][/color] [color=000080][b]static[/b][/color] ResourceBundle resources;

    [color=000080][b]static[/b][/color] {
    [color=000000][b]try[/b][/color] {
    resources = ResourceBundle.getBundle([color=bb0000]"resources.Notepad"[/color],
    Locale.getDefault());
    } [color=000000][b]catch[/b][/color] (MissingResourceException mre) {
    System.err.println([color=bb0000]"resources/Notepad.properties not found"[/color]);
    System.exit([color=bb0000]1[/color]);
    }
    }

    Notepad() {
    [color=000080]super[/color]([color=bb0000]true[/color]);

    [color=80a0b0][italic]// Force SwingSet to come up in the Cross Platform L&F[/italic][/color]
    [color=000000][b]try[/b][/color] {
    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    [color=80a0b0][italic]// If you want the System L&F instead, comment out the above line and[/italic][/color]
    [color=80a0b0][italic]// uncomment the following:[/italic][/color]
    [color=80a0b0][italic]// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());[/italic][/color]
    } [color=000000][b]catch[/b][/color] (Exception exc) {
    System.err.println([color=bb0000]"Error loading L&F: "[/color] + exc);
    }
    [/code]
    [code=000000]
    [color=ff80ff]import[/color][color=ffffff] javax.swing.text.*;[/color]
    [color=ff80ff]import[/color][color=ffffff] javax.swing.undo.*;[/color]
    [color=ff80ff]import[/color][color=ffffff] javax.swing.event.*;[/color]
    [color=ff80ff]import[/color][color=ffffff] javax.swing.*;[/color]

    [color=aaaa66][italic]/**[/italic][/color]
    [color=aaaa66][italic] *[/italic][/color][color=ffa500] Sample application using the simple text editor component that[/color]
    [color=aaaa66][italic] *[/italic][/color][color=ffa500] supports only one font.[/color]
    [color=aaaa66][italic] */[/italic][/color]
    [color=ffffff][b]class[/b][/color][color=ffffff] Notepad [/color][color=ffffff][b]extends[/b][/color][color=ffffff] JPanel {[/color]

    [color=ffffff] [/color][color=ffffff][b]private[/b][/color][color=ffffff] [/color][color=ffffff][b]static[/b][/color][color=ffffff] ResourceBundle resources;[/color]

    [color=ffffff] [/color][color=ffffff][b]static[/b][/color][color=ffffff] {[/color]
    [color=ffffff] [/color][color=b3d2ff][b]try[/b][/color][color=ffffff] {[/color]
    [color=ffffff] resources = ResourceBundle.getBundle([/color][color=dd5555]"resources.Notepad"[/color][color=ffffff], [/color]
    [color=ffffff] Locale.getDefault());[/color]
    [color=ffffff] } [/color][color=b3d2ff][b]catch[/b][/color][color=ffffff] (MissingResourceException mre) {[/color]
    [color=ffffff] System.err.println([/color][color=dd5555]"resources/Notepad.properties not found"[/color][color=ffffff]);[/color]
    [color=ffffff] System.exit([/color][color=dd5555]1[/color][color=ffffff]);[/color]
    [color=ffffff] }[/color]
    [color=ffffff] }[/color]

    [color=ffffff] Notepad() {[/color]
    [color=ffffff] [/color][color=ffffcc]super[/color][color=ffffff]([/color][color=dd5555]true[/color][color=ffffff]);[/color]

    [color=ffffff] [/color][color=aaaa66][italic]// Force SwingSet to come up in the Cross Platform L&F[/italic][/color]
    [color=ffffff] [/color][color=b3d2ff][b]try[/b][/color][color=ffffff] {[/color]
    [color=ffffff] UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());[/color]
    [color=ffffff] [/color][color=aaaa66][italic]// If you want the System L&F instead, comment out the above line and[/italic][/color]
    [color=ffffff] [/color][color=aaaa66][italic]// uncomment the following:[/italic][/color]
    [color=ffffff] [/color][color=aaaa66][italic]// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());[/italic][/color]
    [color=ffffff] } [/color][color=b3d2ff][b]catch[/b][/color][color=ffffff] (Exception exc) {[/color]
    [color=ffffff] System.err.println([/color][color=dd5555]"Error loading L&F: "[/color][color=ffffff] + exc);[/color]
    [color=ffffff] }[/color]
    [/code]


  • WEBMASTERWEBMASTER Posts: 549Member
    That's nice!

    What I need now is a ASP script or COM component that could do real realtime syntaxcoloring!


    [blue][italic][b]/WEBMASTER[/b][/italic][/blue]


  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : I today rewrote the message rendering code and added support for any color and and code background.
    :
    : So, now you can do this
    :
    : [size=5]
    : [color=000000]P[/color][color=100000]r[/color][color=200000]o[/color][color=300000]g[/color][color=400000]r[/color][color=500000]a[/color][color=600000]m[/color][color=700000]m[/color][color=800000]e[/color][color=900000]r[/color][color=a00000]s[/color] [color=b00000]H[/color][color=c00000]e[/color][color=d00000]a[/color][color=e00000]v[/color][color=f00000]e[/color][color=ff00000]n[/color]
    : [/size]
    :
    : by using the [ color=xxxxxx].....[/color] tag, where the xxxxxx is the RGB HEX values.
    :
    : Also, i also now support the use of
    : [ code=xxxxxx]
    : Where you can set the default background color of a code block, like
    :
    : [code=00ff00]
    : case "blue"
    : if closed=false then
    : strBuf = strBuf & ""
    : else
    : strBuf = strBuf & "
    "
    : end if
    : [/code]
    :
    :
    :
    :
    : [blue][italic][b]/WEBMASTER[/b][/italic][/blue]
    :
    :

    Very cool! Thanks a million!

  • gautamgautam Posts: 642Member
    : : I today rewrote the message rendering code and added support for any color and and code background.
    : :
    : : So, now you can do this
    : :
    : : [size=5]
    : : [color=000000]P[/color][color=100000]r[/color][color=200000]o[/color][color=300000]g[/color][color=400000]r[/color][color=500000]a[/color][color=600000]m[/color][color=700000]m[/color][color=800000]e[/color][color=900000]r[/color][color=a00000]s[/color] [color=b00000]H[/color][color=c00000]e[/color][color=d00000]a[/color][color=e00000]v[/color][color=f00000]e[/color][color=ff00000]n[/color]
    : : [/size]
    : :
    : : by using the [ color=xxxxxx].....[/color] tag, where the xxxxxx is the RGB HEX values.
    : :
    : : Also, i also now support the use of
    : : [ code=xxxxxx]
    : : Where you can set the default background color of a code block, like
    : :
    : : [code=00ff00]
    : : case "blue"
    : : if closed=false then
    : : strBuf = strBuf & ""
    : : else
    : : strBuf = strBuf & "
    "
    : : end if
    : : [/code]
    : :
    : :
    : :
    : :
    : : [blue][italic][b]/WEBMASTER[/b][/italic][/blue]
    : :
    : :
    :
    : Very cool! Thanks a million!
    :
    [code=00ff00] testing [/code]
    [code=100000]testing[/code]
    [code=100001]Ignore this post[/code]

    [code=00ff00]
    [italic] if this post works this is damn cool man
    [/code]

  • gautamgautam Posts: 642Member
    : : : I today rewrote the message rendering code and added support for any color and and code background.
    : : :
    : : : So, now you can do this
    : : :
    : : : [size=5]
    : : : [color=000000]P[/color][color=100000]r[/color][color=200000]o[/color][color=300000]g[/color][color=400000]r[/color][color=500000]a[/color][color=600000]m[/color][color=700000]m[/color][color=800000]e[/color][color=900000]r[/color][color=a00000]s[/color] [color=b00000]H[/color][color=c00000]e[/color][color=d00000]a[/color][color=e00000]v[/color][color=f00000]e[/color][color=ff00000]n[/color]
    : : : [/size]
    : : :
    : : : by using the [ color=xxxxxx].....[/color] tag, where the xxxxxx is the RGB HEX values.
    : : :
    : : : Also, i also now support the use of
    : : : [ code=xxxxxx]
    : : : Where you can set the default background color of a code block, like
    : : :
    : : : [code=00ff00]
    : : : case "blue"
    : : : if closed=false then
    : : : strBuf = strBuf & ""
    : : : else
    : : : strBuf = strBuf & "
    "
    : : : end if
    : : : [/code]
    : : :
    : : :
    : : :
    : : :
    : : : [blue][italic][b]/WEBMASTER[/b][/italic][/blue]
    : : :
    : : :
    : :
    : : Very cool! Thanks a million!
    : :
    : [color=00ff00] testing [/color]
    : [color=100000]testing[/color]
    : [color=100001]Ignore this post[/color]
    :
    : [code=00ff00]
    : [italic] if this post works this is damn cool man
    : [/code]
    :


  • Eric TetzEric Tetz Posts: 2,141Member
    Well, you could easily use VIM as an external text filter. Let's say you encounter:

    [black][[/black]code=ff0000 lang=fortran]
    ... text ...
    [black][[/black]/code]

    You gather up the text and pass it off to VIM along with the language name. VIM would markup the text with the appropriate style-code and return it to you. You could feed the text to VIM via stdin, and receive the altered text via stdout (like a CGI app), or you could just save it the text to a temp file and pass the filename to VIM.

    I've not had the occasion to use ASP before, but if it requires external code to reside in a COM component, we could easily write one that exported a single conversion function and took care of invoking VIM...
    [code=ffffff]
    string markupText( in string text, in string language )
    [/code]
    Of course, spawning external processes to do work is not as fast as memory resident server extensions, but that wouldn't really be an issue here. This would only need to be done once with each new post.

    Once this was in place, Programmer's Heaven would be able to automatically syntax highlighting for over 300 filetypes!

    [size=1] abaqus, abc, abel, acedb, ada, aflex, ahdl, amiga, aml, antlr, apache, apachestyle, asm, asm68k, asmh8300, asn, aspperl, aspvbs, atlas, automake, ave, awk, ayacc, b, basic, bc, bdf, bib, bindzone, blank, btm, c, catalog, cf, cfg, ch, change, changelog, cl, clean, clipper, cobol, colortest, conf, config, cpp, crontab, csc, csh, csp, css, cterm, ctrlh, cupl, cuplsim, cvs, cweb, cynlib, cynpp, dcl, debchangelog, debcontrol, def, diff, diva, dns, docbk, dosbatch, dosini, dot, dracula, dsl, dtd, dtml, dylan, dylanintr, dylanlid, ecd, eiffel, elf, elmfilt, erlang, esqlc, eterm, expect, exports, fgl, focexec, form, forth, fortran, foxpro, fvwm, gdb, gdmo, gedcom, gnuplot, gp, groff, gsp, gtkrc, haskell, hb, help, hercules, hitest, hog, html, htmlm4, htmlos, ia64, icon, idl, idlang, indent, inform, inittab, ishd, iss, ist, jam, jargon, java, javacc, javascript, jess, jgraph, jproperties, jsp, kix, kscript, kwt, lace, latte, lex, lftp, lhaskell, lilo, lisp, lite, lotos, lout, lprolog, lss, lua, lynx, m4, mail, make, man, manual, maple, masm, mason, master, matlab, mel, mf, mgp, mib, mma, model, modsim3, modula2, modula3, mp, msql, mush, muttrc, named, nasm, nastran, natural, ncf, nosyntax, nqc, nroff, objc, ocaml, omnimark, openroad, opl, ora, papp, pascal, pcap, pccts, perl, pfmain, php, phtml, pic, pike, pilrc, pine, plm, plsql, po, pod, postscr, pov, povini, ppwiz, procmail, progress, prolog, psf, ptcap, purifylog, python, qf, r, radiance, ratpoison, rc, rcslog, readline, rebol, registry, remind, rexx, robots, rpcgen, rtf, ruby, samba, sas, sather, scheme, screen, sdl, sed, sgml, sgmldecl, sgmllnx, sh, sicad, simula, sinda, sindacmp, sindaout, skill, sl, slang, slrnrc, slrnsc, sm, smil, smith, sml, snnsnet, snnspat, snnsres, snobol4, spec, specman, spice, spup, sql, sqlforms, sqr, squid, st, stp, strace, syncolor, synload, syntax, tads, tags, tak, takcmp, takout, tasm, tcl, terminfo, tex, texinfo, texmf, tf, tidy, tli, trasys, tsalt, tsscl, tssgm, tssop, types, uc, uil, vb, verilog, vgrindefs, vhdl, vim, viminfo, virata, vrml, vsejcl, wdiff, web, webmacro, wget, whitespace, winbatch, wml, wsh, xdefaults, xkb, xmath, xml, xpm, xpm2, xs, xxd, yacc, z8a, zsh [/size]

    Personally, it doesn't make a difference to me. My editor already does this for me. But if you want to add this for everyone elses benefit, I could help you out with the VIM part of it, supplying the conversion script and the appropriate command-line. If you think it would be feasible (you know more about your website setup than I do), I could even write the COM component for you.

    Cheers,
    Eric


«1
Sign In or Register to comment.