open source syntax highlighter tool? [closed] - open-source

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm looking for an open source, cross platform (Windows & Linux at least) command line tool to take some code (C++, but multiple languages would be sweet), and spit out valid a XHTML representation of that code, with syntax highlighting included.
Ideally the XHTML should just wrap the code with <span> and <div> tags with different classes so I can supply the CSS code and change the colouration, but that's an optional extra.
Does anyone know of such an application?

I can recommend Pygments. It's easy to work with and supports a lot of languages. It does what you want, i.e., it wraps the code in <span> tags:
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
code = 'print "Hello World"'
print highlight(code, PythonLexer(), HtmlFormatter())
gives
<div class="highlight">
<pre><span class="k">print</span> <span class="s">"Hello World"</span></pre>
</div>
and you can then use one of the supplied style sheets of make your own.
You can also call it via it's pygmentize script. The script can format the output in different ways: HTML, LaTeX, ANSI color terminal output.

Vim can save any code it highlights to "colored" HTML (it runs on several platforms). There is GNU hightlight too. And tons of others.

There is very good one, driven by XML, fast and opensource: http://sourceforge.net/projects/colorer/

I don't recall if GeSHi has a command-line program but even if it doesn't, it shouldn't be hard to whip one up. It does a great job of taking code and generating pretty, coloured HTML/XHTML, even with line numbers (or every X line numbers, even) and other helpful features.

Enscript looks like what you are asking for :
spit HTML (or PS, or RTF) from ascii files
It includes features for `pretty-printing' (language-sensitive code highlighting) in several programming languages.

Not sure how helpful this will be, but my team uses doxygen to produce documentation, which happens to provide color syntax highlighting on our code views as well as a side bonus. Never really needed it, but it does it.

If you're ok with using ruby, you want coderay.

I'll add my own one to the list, it colors C# but could be adapted for C, C++ and Java.
It produces the inline styles by default and a pre tag.
The source is there in C#, you'll need to grab mono/monodevelop and compile it as as a console app, so it's not shrink wrapped in that respect.

Related

Learning (X)HTML using the DTD [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm thinking of learning (X)HTML.
I have read on the web about w3schools and discussions on the subject and intend to stay away from it (or at most use it as a reference).
I think it is best when learning programming languages to go to the original source (php.net, python.org, mysql.com, ...).
I tried to read the (X)HTML 4/5 spec but gave up soon after starting. The next best thing as far as I can tell is the DTD.
What are your opinions in this kind if learning and can you recommend alternatives?
Also is there a DTD or something like a DTD for HTML 5 yet?
HTML is more than the DTD. Learning HTML from DTD is like learning C from include files — you just don't do it.
The DTD just specifies a few simple grammar rules. You can use it to roughly validate your code but it's limited. And it definitely knows nothing about semantics.
It's a guess-work. It's like, you have:
<html>
<body>
and now the DTD only says you can choose one of: <h1>, <h2>, …, <ul>, <ol>, …, <p>, …
Well, sometimes it gives a brief description of what particular elements or attributes mean (in comments). But that's all. It doesn't explain what is the purpose of given element, what are the alternatives and which one should fit the particular task better.
Also, remember that HTML is rarely used alone these days. You at least have to know CSS as well (unless you're going to write some ugly soup — then please don't even start), and CSS is not fit for DTD.
The specs are the most important documents for you but they are not fit for learning either. The spec is the thing you start to use after you catch all the basics already, and where you check your understanding of them. But the HTML and CSS specs alone are not enough either. There's WCAG at least. And a fair bit of common sense.
I think the one tutorial you could start with is the one from Mozilla. It's not perfect either and you will need to read much more before you start writing good HTML.
There's plenty of resources out there. Many great books and websites. Don't learn from the spec, it's very dry. You can't learn from the DTD - it's just a bunch of code outlining what elements can contain what, and so on. Here's a few things to check out:
http://jessey.net/simon/xhtml_tutorial/
http://diveintohtml5.info
http://www.kirupa.com/html5/introduction_html.htm
https://developer.mozilla.org/en-US/docs/HTML/Introduction
And yes, I do(!) think that you can learn from w3schools. It's another good resource.

Does it bother anyone else that the code tag doesn't print the containing text as a literal? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
It seems like this should be rectified in HTML5 or at least the spec should specify that the <code> tag does this.
As of now if you have tags inside the code tag, it considers those DOM elements.
There should be a way to write tags without having to escape them. Am I missing something or is this ridiculous that they haven’t thought of this?
This kind of feature was thought of, even before HTML 2.0 was published, the use case being met by the <xmp> and <listing> elements rather than <code>, but by the time HTML 2.0 was finalised, the elements were already deprecated because it causes problems - how do you put </xmp> inside your escaped code?
Having said that, <xmp> is pretty consistently implemented these days, and came reasonably close to being made valid in HTML5. The quotes below come from HTML5 editor Ian Hickson's comments on Bug 12235 - Make <xmp> conforming.
Proposal: allow <xmp> as an element with the same semantics as <pre>
but keeping the special parsing rules in HTML.
Pros: Experienced authors who are writing specs, HTML tutorials,
programming language blogs, or other pages containing snippets of code
that can be expected to contain < and & characters get to save the
time of escaping their <s and &s.
Cons: Complicates the language, introduces yet another polyglot
difference, may be mistreated as a security feature, a pain to use if
you have to later add markup inside the block (e.g. to highlight a
section), doesn't support characters outside the character encoding of
the page (as it can't get entities).
I agree with Henri that this is a tough call.
--
Status: Rejected Change
Description: no spec change
Rationale: I'm
going to say no on this, mostly driven by the simplicity argument.
It's a tough call, though. There's some good arguments on both sides.
Finally, I should note that the behaviour of <code> can't change. Doing so now would break many, many web pages.

diff to html (diff2html) program [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm looking for a "diff to html" program, which would generate a static html page from a given diff/patch file.
I've googled for it of course, but apart from some scripts I've found there's no "real project" (e.g. no package in Debian/Ubuntu).
Have I missed something? Can you recommend anything?
You can use diff2html.py that is able to create a side-by-side diff in a static html page, from an unified diff input. The script is written in python.
cat foo.diff | python diff2html.py > foo.html
pygments has syntax highlighting for diff (and for lots of other languages), and can be used as a library or a command-line program. Is that the sort of thing you're looking for? If not please clarify the question...
Something along the lines of:
vim test.diff -c TOhtml -c ":saveas test.html" -c ":q" -c ":q"
works well, and you can change the color-scheme of the diff by changing the color scheme in vi.
http://www.sourceforge.net/projects/diff2html
how about Text-Diff-HTML, difflib.HtmlDiff, CSDiff?
Have you tried http://prettydiff.com/ as it ignores differences in white space and comments.
[Disclaimer: this is my site]
There's also 2html in Vim, which works very well, and it's built-in: it takes a file that Vim knows how to highlight its syntax, and creates an HTML with the correct formatting.
To use it, just open the wanted file with Vim, and source the 2html script. It will open the converted file in a new buffer, which can be saved. Here:
vim example.diff
and then in Vim,
:so /usr/share/vim/vim72/syntax/2html.vim
:wqa
The best I've found that produces nice side-by-side diffs is this script:
http://tools.ietf.org/tools/rfcdiff/
Although it's designed to be used on RFCs it works with any text file.
This project also has nice output, but I'm not sure if it can be used without subversion:
http://code.google.com/p/coderev/
I use htmlize in Emacs. Doesn't come with Emacs, and assumes you're using Emacs. Relies on the syntax highlighting of Emacs's Diff mode. Only good for doing one file at a time. Does the right thing for me.
I found coderev, demo looks nice

Best Way To Format An HTML Email? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am implementing a comment control that allows a person to select comments and have them sent to specified departments. The email needs to be formatted in a specific way, and I was wondering what the best way to do this would be.
Should I just hard code all of the style information into one massive method, or should I try and create a separate file and read it in, and then replace certain tags with the relevant information?
Find and use some kind of template library, if possible. This will make each email a template which will then be much easier to maintain than the hardcoded form.
Campaign monitor has some great, well-tested free templates:
http://www.campaignmonitor.com/templates/
Make sure whatever you use will display well in all clients.
A great guide:
http://www.campaignmonitor.com/blog/archives/2008/05/2008_email_design_guidelines.html
In addition to using some sort of template, as tedious as it is, inline styles are the most cross-client compatible way of styling HTML emails. Not every email client will fetch an external stylesheet and many don't do so well with an embedded style section.
That being the case, I would choose a fairly simple set of style rules for the email in order to ensure that it looks the same in different email clients and try not to rely too heavily on images as many client will require that extra click to show content.
I would use a template approach. It wouldn't he hard to create a simple regex template system, replacing something like #somevar# with the value for 'somevar'. You could also use a premade template system, like Smarty for PHP. I think that would be the cleanest approach.
Alex
I've used XLST templates in the past to format emails. Generally emails are best constructed using tables and inline CSS. Note that outlook 2007 does not support background images :(
Definitely use templates. I have done it with text templates using custom tags like so:
<p>Dear |FIRST_NAME|,
But I really cannot recommend this; it is a world of pain. The second time I did it (an html email appender for log4net) I used an xslt to transform the object (in this case a log4net message) into an html email. Much neater.
Note that certain clients (e.g. Lotus Notes) do not support XHTML, so use plain old HTML 1.0, with no css, and you should be ok.

JSON editor/formatter? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've got some JSON data, but it's all on one line. Does anyone know of a web or Windows editor that will format (e.g. indent and insert new lines) this data for me, so I can read it better? Preferably one that uses a GUI to display the JSON—instead of a command-line tool that outputs a reformatted document, for example.
I have recently created JSON Editor Online, a tool to easily edit and format JSON online. JSON is displayed in a clear, editable treeview and in formatted plain text.
http://jsoneditoronline.org/
Have you tried this?
http://jsonformat.com/
You can download http://www.thomasfrank.se/json_editor.html and run it locally on your own data, although it is an editor rather than a formatter.
http://www.jsonlint.com/ is also a useful validation and reformatting tool.
On windows I go for: http://jsonviewer.codeplex.com/
Handy for pulling raw JSON responses from Firebug and parsing it for me.
I use http://curiousconcept.com/jsonformatter to format computer generated jsons. It makes it much readable.
Remember that JSON is just a Javascript Object Literal with fancy clothes. You should be able to use any Javascript Beautifier to clean it up.
I like this one here:
http://freeformatter.com/json-formatter.html
The validation process is flexible if your doc does not adhere to the RFC standards. It also creates a tree with collapsible nodes which is cool when you want to work in a small area of the json tree
Here's what I do: use the Aptana Eclipse Javascript Editor, which will check your syntax as you type. There's only one trick: you have to wrap your json in a tiny bit of javascript to make the whole thing a valid javascript file, and eliminate those red and yellow syntax errors.
So, the outer-most {} becomes: x={}; ( with all your json stuff in the middle ).
Now you just have to strip-off the x= and the ; before parsing as JSON.
I do this in a function that wraps the jQuery ajax function:
function get_json_file(url,options,callback){
var opts = {dataType:"text"};
opts.url = url;
$.extend(opts,options);
opts.success=function(data){
var json = data.substring(data.indexOf('{'),data.lastIndexOf('}')+1);
var obj = JSON.parse(json);
callback(obj);
};
$.ajax(opts);
}
It's a bit crazy, but it's worth it to effectively have a really good syntax-checking JSON editor in eclipse.