• code to HTML with syntax coloring?
    20 replies, posted
Hi! I often have to send my code to someone who doesnt have Notepad++ or IDE to open up the code with colored syntax. Consequently the code is harder to read. Is there a way to get the code into HTML and in the process adding syntax coloring, for example, the parser reads public static void and writes <font color = "blue"><b> public static void </b></font>. I know I could do that myself, but adding syntax coloring to a language is quite lenghty process and Im sure it has already been done (the way I need it). If anyone knows such a program please tell. Thanks.
You could paste the code to [url=http://pastebin.com/]pastebin.com[/url] and give them the link to it. [editline]6th January 2012[/editline] I'm sure there are some PHP libraries to do the same thing if this isn't quite what you were looking for.
Yes, pastebin is quite useful but sometimes I want to have the file on my HDD :)
This is probably overkill, but I know that [url=http://www.stack.nl/~dimitri/doxygen/]Doxygen[/url] can show code with syntax highlighting as a webpage.
Can't you export things to html with N++?
You can use CodeRay with Ruby! [img]http://i.imgur.com/NxnuE.png[/img]
[QUOTE=Map in a box;34088617]Can't you export things to html with N++?[/QUOTE] Notepad++ does not do that, but there is a [URL="http://harrysnppstuff.webs.com/"]plugin[/URL] for that (didn't try/test). Also, Code::Blocks has an export to HTML feature, in case you use that one.
I prefer codepad.org over pastebin, less bloat and it loads way faster
Hmm, this N++ plugin looks useful but when I try it I first get access violation exception, then when I try to use it (because for some reason that exception doesnt f*** up N++) I cant get it to do what I want :S
There's also some standalone application: [url]http://www.andre-simon.de[/url] Didn't try that either.
This one actually works, thanks :D
[QUOTE=Jinx786;34081452]Yes, pastebin is quite useful but sometimes I want to have the file on my HDD :)[/QUOTE] You can save the pastbin page to your computer.
[QUOTE=Dienes;34092020]Notepad++ does not do that, but there is a [URL="http://harrysnppstuff.webs.com/"]plugin[/URL] for that (didn't try/test). Also, Code::Blocks has an export to HTML feature, in case you use that one.[/QUOTE] It's part of the default installation actually.
[QUOTE=jaybuz;34095102]It's part of the default installation actually.[/QUOTE] Wow, it really is, totally overlooked it in the plugins menu... Better solution than the separate tool imo.
Oh my, I'm so sorry, when I was looking around N++ I must have missed it, thanks for telling me tho :) But the highlighter program you posted (Dienes) is useful even more, it has BBcode support for forums, check it out: [CODE] [SIZE=10][COLOR=#8f0055]public class[/COLOR] aclass[COLOR=#000000]{[/COLOR] [COLOR=#8f0055]public static[/COLOR] [COLOR=#8f0055]void[/COLOR] [COLOR=#000000]main[/COLOR][COLOR=#000000]([/COLOR]String[COLOR=#000000][][/COLOR] args[COLOR=#000000]){[/COLOR] System[COLOR=#000000].[/COLOR]out[COLOR=#000000].[/COLOR][COLOR=#000000]println[/COLOR][COLOR=#000000]([/COLOR][COLOR=#c00000]"Yay! :D"[/COLOR][COLOR=#000000]);[/COLOR] [COLOR=#000000]}[/COLOR] [COLOR=#000000]}[/COLOR] [/SIZE] [/CODE] Oh damn, not working :(
If you don't mind it in PDF, simply get some PDF printer software and File -> Print -> And select your PDF printer. [editline]13th January 2012[/editline] Gah, just realized this thread is 5 days old - sorry!
[QUOTE=h2ooooooo;34193032]If you don't mind it in PDF, simply get some PDF printer software and File -> Print -> And select your PDF printer. [editline]13th January 2012[/editline] Gah, just realized this thread is 5 days old - sorry![/QUOTE] New ideas are always welcome. As for pdf, yeah, we use them a lot :)
[QUOTE=swift and shift;34090470]You can use CodeRay with Ruby! [img]http://i.imgur.com/NxnuE.png[/img][/QUOTE] But why comic sans
[QUOTE=DrLuke;34196875]But why comic sans[/QUOTE] I think that's the Mac equivalent font, actually. It seems quite popular as a programming font. [I]For some reason.[/I]
I recently needed to install a syntax-highlighter program called [url=http://www.andre-simon.de/zip/download.html]highlight[/url] for an extention I added to my wiki. Apparantly it also has a windows version, but it's command-line which probably wouldn't be as appealing. In fact, I wonder if I could write a PHP script where you could upload a file to it, then have highlight process it, and return it as HTML... [editline]22nd January 2012[/editline] Looks like I can! Live example available: [url]http://96.35.9.243/highlight.html[/url] HTML code for the highlight.html: [code] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Syntax Highlighter</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <form action="highlight.php" method="POST"> What language is this:<br/> <select name="lang"> <option value="abap4">ABAP/4</option> <option value="abnf">Advanced Backus-Naur Form</option> <option value="actionscript">Action Script</option> <option value="ada">ADA95</option> <option value="agda">Agda</option> <option value="ampl">AMPL</option> <option value="amtrix">AMTrix</option> <option value="applescript">AppleScript</option> <option value="arc">Arc</option> <option value="arm">ARM</option> <option value="ascend">ASCEND</option> <option value="asp">ASP</option> <option value="aspect">Abstract</option> <option value="assembler">Assembler</option> <option value="ats">Applied Type System</option> <option value="autohotkey">AutoHotKey</option> <option value="autoit">AutoIt</option> <option value="avenue">Avenue</option> <option value="awk">(G)AWK</option> <option value="bat">DOS Batch</option> <option value="bbcode">BBcode</option> <option value="bibtex">BibTeX</option> <option value="bison">Bison</option> <option value="blitzbasic">Blitz Basic</option> <option value="bms">BM Script</option> <option value="bnf">Backus-Naur Form</option> <option value="boo">Boo</option> <option value="c" selected>C and C++</option> <option value="chill">CHILL</option> <option value="clean">Clean</option> <option value="clearbasic">ClearBasic</option> <option value="clipper">Clipper</option> <option value="clojure">Clojure</option> <option value="clp">Clips</option> <option value="cobol">COBOL</option> <option value="coldfusion">ColdFusion MX</option> <option value="csharp">C#</option> <option value="css">CSS</option> <option value="d">D</option> <option value="diff">Diff</option> <option value="dylan">Dylan</option> <option value="ebnf">Extended Backus-Naur Form</option> <option value="eiffel">Eiffel</option> <option value="erlang">Erlang</option> <option value="euphoria">Euphoria</option> <option value="express">Express</option> <option value="fame">FAME</option> <option value="felix">Felix</option> <option value="fortran77">Fortran 77</option> <option value="fortran90">Fortran 90</option> <option value="frink">Frink</option> <option value="fsharp">F#</option> <option value="go">Go</option> <option value="graphviz">Graphviz</option> <option value="haskell">Haskell</option> <option value="haxe">haXe</option> <option value="hcl">Hecl</option> <option value="html">HTML</option> <option value="httpd">Apache Config</option> <option value="icon">Icon</option> <option value="idl">IDL</option> <option value="idlang">Interactive Data Language</option> <option value="inc_luatex">Lua (for LuaTeX)</option> <option value="informix">Informix</option> <option value="ini">INI</option> <option value="innosetup">Inno Setup</option> <option value="interlis">INTERLIS</option> <option value="io">IO</option> <option value="jasmin">Jasmin</option> <option value="java">Java</option> <option value="js">Javascript</option> <option value="jsp">JSP</option> <option value="ldif">LDAP</option> <option value="lhs">Haskell LHS</option> <option value="lilypond">Lilypond</option> <option value="lindenscript">Linden Script</option> <option value="lisp">Lisp</option> <option value="logtalk">Logtalk</option> <option value="lotos">Lotos</option> <option value="lotus">Lotus</option> <option value="lua">Lua</option> <option value="luban">Luban</option> <option value="make">Make</option> <option value="maple">Maple</option> <option value="matlab">Matlab</option> <option value="maya">Maya</option> <option value="mercury">Mercury</option> <option value="miranda">Miranda</option> <option value="mod2">Modula2</option> <option value="mod3">Modula3</option> <option value="modelica">Modelica</option> <option value="ms">MaxScript</option> <option value="mssql">MSSQL</option> <option value="nasal">Nasal</option> <option value="nbc">NeXT Byte Codes</option> <option value="nemerle">Nemerle</option> <option value="netrexx">NetRexx</option> <option value="nice">Nice</option> <option value="nsis">NSIS</option> <option value="nxc">Not eXactly C</option> <option value="oberon">Oberon</option> <option value="objc">Objective C</option> <option value="ocaml">Objective Caml</option> <option value="octave">Octave</option> <option value="oorexx">Open Object Rexx</option> <option value="os">Object Script</option> <option value="oz">Oz</option> <option value="paradox">Paradox</option> <option value="pas">Pascal</option> <option value="perl">Perl</option> <option value="php">PHP</option> <option value="pike">Pike</option> <option value="pl1">PL/1</option> <option value="pov">POV-Ray</option> <option value="pro">Prolog</option> <option value="progress">Progress</option> <option value="ps">PostScript</option> <option value="ps1">Microsoft PowerShell</option> <option value="psl">PATROL</option> <option value="pure">Pure</option> <option value="pyrex">Pyrex</option> <option value="python">Python</option> <option value="q">Qore</option> <option value="qmake">QMake Project</option> <option value="qu">Qu</option> <option value="r">R</option> <option value="rebol">Rebol</option> <option value="rexx">Rexx</option> <option value="rnc">Relax NG</option> <option value="ruby">Ruby</option> <option value="s">PowerPC Assembler</option> <option value="sas">SAS</option> <option value="scala">Scala</option> <option value="scilab">Scilab</option> <option value="sh">Bash</option> <option value="small">SMALL</option> <option value="smalltalk">Smalltalk</option> <option value="sml">Standard ML</option> <option value="snmp">SNMP</option> <option value="snobol">SNOBOL</option> <option value="spec">RPM Spec</option> <option value="spn">SPIN SQL</option> <option value="sql">PL/SQL</option> <option value="squirrel">Squirrel</option> <option value="sybase">Sybase SQL</option> <option value="tcl">Tcl/Tk</option> <option value="tcsh">TCSH</option> <option value="test_re">Regex tests</option> <option value="tex">TeX and LaTeX</option> <option value="ttcn3">TTCN3</option> <option value="txt">Plain text</option> <option value="vala">Vala</option> <option value="vb">Visual Basic</option> <option value="verilog">Verilog</option> <option value="vhd">VHDL</option> <option value="xml">XML</option> <option value="xpp">SuperX++</option> <option value="yaiff">Yaiff</option> <option value="znn">Zonnon</option> </select> <br/> <input type="checkbox" name="numbered" value="1" /> Line Numbers <br/> Copy/paste your code here:<br/> <textarea name="code" rows="50" cols="150"> </textarea><br/> <input type="submit" value="Submit"/> </form> </body> </html> [/code] PHP code for the highlight.php: [php] <?php #List of supported languages. $supported = array( "abap4" => true, "abnf" => true, "actionscript" => true, "ada" => true, "agda" => true, "ampl" => true, "amtrix" => true, "applescript" => true, "arc" => true, "arm" => true, "ascend" => true, "asp" => true, "aspect" => true, "assembler" => true, "ats" => true, "autohotkey" => true, "autoit" => true, "avenue" => true, "awk" => true, "bat" => true, "bbcode" => true, "bibtex" => true, "bison" => true, "blitzbasic" => true, "bms" => true, "bnf" => true, "boo" => true, "c" => true, "chill" => true, "clean" => true, "clearbasic" => true, "clipper" => true, "clojure" => true, "clp" => true, "cobol" => true, "coldfusion" => true, "csharp" => true, "css" => true, "d" => true, "diff" => true, "dylan" => true, "ebnf" => true, "eiffel" => true, "erlang" => true, "euphoria" => true, "express" => true, "fame" => true, "felix" => true, "fortran77" => true, "fortran90" => true, "frink" => true, "fsharp" => true, "go" => true, "graphviz" => true, "haskell" => true, "haxe" => true, "hcl" => true, "html" => true, "httpd" => true, "icon" => true, "idl" => true, "idlang" => true, "inc_luatex" => true, "informix" => true, "ini" => true, "innosetup" => true, "interlis" => true, "io" => true, "jasmin" => true, "java" => true, "js" => true, "jsp" => true, "ldif" => true, "lhs" => true, "lilypond" => true, "lindenscript" => true, "lisp" => true, "logtalk" => true, "lotos" => true, "lotus" => true, "lua" => true, "luban" => true, "make" => true, "maple" => true, "matlab" => true, "maya" => true, "mercury" => true, "miranda" => true, "mod2" => true, "mod3" => true, "modelica" => true, "ms" => true, "mssql" => true, "nasal" => true, "nbc" => true, "nemerle" => true, "netrexx" => true, "nice" => true, "nsis" => true, "nxc" => true, "oberon" => true, "objc" => true, "ocaml" => true, "octave" => true, "oorexx" => true, "os" => true, "oz" => true, "paradox" => true, "pas" => true, "perl" => true, "php" => true, "pike" => true, "pl1" => true, "pov" => true, "pro" => true, "progress" => true, "ps" => true, "ps1" => true, "psl" => true, "pure" => true, "pyrex" => true, "python" => true, "q" => true, "qmake" => true, "qu" => true, "r" => true, "rebol" => true, "rexx" => true, "rnc" => true, "ruby" => true, "s" => true, "sas" => true, "scala" => true, "scilab" => true, "sh" => true, "small" => true, "smalltalk" => true, "sml" => true, "snmp" => true, "snobol" => true, "spec" => true, "spn" => true, "sql" => true, "squirrel" => true, "sybase" => true, "tcl" => true, "tcsh" => true, "test_re" => true, "tex" => true, "ttcn3" => true, "txt" => true, "vala" => true, "vb" => true, "verilog" => true, "vhd" => true, "xml" => true, "xpp" => true, "yaiff" => true, "znn" => true, ); #Ensure that the requested language is actually supported $lang = $_POST["lang"]; if( array_key_exists ( $lang, $supported ) ) { $handle = fopen( "process.txt", "w" ); if( $handle ) { fwrite( $handle, $_POST["code"] ); fclose( $handle ); $options = "q"; if( isset( $_POST["numbered"] ) ) { $options .= "l"; } #Run highlight, take process.txt as input of the chosen language, #and output horstmann-reformatted html (page title "Highlighted Source Code") to the standard output stream (PHP will print whatever is on the output stream) system( "highlight -$options -i process.txt -S $lang -o /dev/stdout -O html -F horstmann -T \"Highlighted Source Code\"" ); unlink("process.txt"); } else { echo "Error; Couldn't open process.txt for writing."; } } else { echo "Error; bad language."; } ?> [/php]
[QUOTE=BlkDucky;34198474]I think that's the Mac equivalent font, actually. It seems quite popular as a programming font. [I]For some reason.[/I][/QUOTE] it's monaco and it rocks [editline]24th January 2012[/editline] and no it's not a comic sans equivalent wtf
Sorry, you need to Log In to post a reply to this thread.