JSFiddle - React, Tailwind, and code Playground

by Joshua

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<textarea>
:::
        apple:::
            rating:10
            color:red
        orange:::
            color:orange
            rating:orange
    description:dskfhj(*&(#@%@#%U& // this is a comment
</textarea>

CSS

textarea {
    display:block;
    width:100%; height:300px;
    text-rendering: optimizeSpeed;
}

JavaScript

var el = document.getElementsByTagName('textarea')[0];
console.clear();

var ia2json = function(input){
    this.input = input;
    this.output = '';
    this.settings = {
        tab_width: 4,
        regexp: {
            quo: "'''((?:[^'\\\\]|\\\\. |'{1,2}(?!'))*)'''",
            com: '[ \s]*//.*[ \s]*\n',
            pad: '[\t ]*',
            key: '[a-zA-Z0-9-_]+',
            obj: ':::',
            arr: '::',
            val: ':',
            str: '[^\n]+'
        }
    };
    
    this.regexp = function(str){
        return new RegExp(str, 'g');
    }
    this.regexp_beg = function(str){
        return new RegExp('^'+str, 'g');
    }
    this.match = function(regexp, str){
        var match = str.match(this.regexp(regexp));
        return match==null ? false : match[0];
    }
    this.prepare_input = function(){
        this.input = this.input
            .replace(/\r/g, '')
            + '\n';
    }
    
    this.remove_comments = function(){
        this.input = this.input.replace(this.regexp(this.settings.regexp.com), '');
    }
    this.encode_strings = function(){
        this.input = this.input.replace(
            this.regexp(this.settings.regexp.quo),
            function(v, g){
                return encodeURIComponent(v)
            }
        );
    }
    this.encode_quote = (function(){
        var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
            meta = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' };
    
        function escaper(a) {
          var c = meta[a];
          return typeof c === 'string' ? c : '\\u'+('0000' + a.charCodeAt(0).toString(16)).slice(-4);
        }
    
        return function quote(string){
          escapable.lastIndex = 0;
          return string.replace(escapable, escaper);
        };
      })();
    this.parse_line = function(line){
        var parts = {},
           ...