1
Vote

Adding hyperlinks to the formatter

description

Love the app! I made a small change to display URLs as hyperlinks. Quite crude but does the job for the URLs in the JSON I am working with.

Added a new if block to the end of the ProcessObject function and a new function called FormatHyperlink between ProcessObject and FormatLiteral as below:
 function ProcessObject(obj, indent, addComma, isArray, isPropertyContent){
...
  }else if(type == 'undefined'){
    html += FormatLiteral("undefined", "", comma, indent, isArray, "Null");
// Start of new IF block...
  }else if(obj.toString().search("^(http:|https:|ftp:|ftps:|sftp:)") == 0){
    html += FormatHyperlink(obj.toString().split("\\").join("\\\\").split('"').join('\\"'), "\"", comma, indent, isArray, "");
// ... end of new IF block.
  }else{
    html += FormatLiteral(obj.toString().split("\\").join("\\\\").split('"').join('\\"'), "\"", comma, indent, isArray, "String");
  }
  return html;
}
// Start of new function ...
function FormatHyperlink(literal, quote, comma, indent, isArray, style){
  if(typeof literal == 'string')
    literal = literal.split("<").join("&lt;").split(">").join("&gt;");
  var str = "<a href="+quote+literal+quote+" target="+quote+"_blank"+quote+">"+quote+literal+quote+comma+"</a>";
  if(isArray) str = GetRow(indent, str);
  return str;
}
// ... end of new function.
function FormatLiteral(literal, quote, comma, indent, isArray, style){
...

comments