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.
Related
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 9 years ago.
I am now building a simple application, which includes editing the content such as blog. I have a few options such as tinymc, a good html editor, which I planned to use it. but then I find something about markdown, which is easy to use and popular as well nowadays. among the markdown supported editors, EpicEditor is a good choice.For some reasons, WYSIWYGs sucks and complicated. so I decided to use markdown editor.
Then on the node.js server side, I have two choices to store the content, either in markdown or html, as in the cod, it firstly parse the markdown into html, then save it to the database.
app.post('/post', function(req, res){
var currentUser = req.session.user,
html = markdown.makeHtml(req.body.post),
post = new Post(currentUser.name, req.body.title, html);
post.save(function(err){
if(err){
req.flash('error', err);
return res.redirect('/');
}
req.flash('success', 'scc!');
res.redirect('/');
});
});
the advantage of saving html to database is, the app doesn't need to parse from markdown to html when loading the content.
while the advantage of saving markdown to database is, when the user want to edit the content again, it is easier for the client to edit the markdown content.
Generally speaking, it is better to preserve the original input and then transform it (on demand) for the target view. That lets you present the original input back for later editing, and transform from the original input to different formats for different views (for example, if you wanted to put the data in an email, you could leave the markdown as plain text for the text version of the email).
That said, Markdown to HTML can be costly (in terms of CPU) so you might want to convert to HTML when it is input (or when first viewed) and then cache the result (possibly in another column in the same database table as the markdown is stored). You should still keep the original input though.
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.
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
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.
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.