JSFiddle - React, Tailwind, and code Playground

by Roman Zhak

JavaScript

var temaplte = "<div class='hjs' alt='name' id='welcome'>Hello, world!</div>";

function parse( tmpl ) {
  var i = 0, len = tmpl.length, symbol, tokens, textNode = '';
    for( ; i < len; i++ ) {
     symbol = tmpl[i];
      if( symbol === '<' ) {
       parseTag( tmpl, ++i );     
        } else {
         textNode += symbol;
        }
    }
}

function parseTag( string, index ) {
  var middle = '', name, props, $$map = {};
    while( string[index] !== '>' ) {
        middle += string[index++]
    }
  props = middle.split(' ');
  $$map[ (name = props.shift()) ] = {};
    props.forEach(function( element ) {
     element = element.split('=');
      $$map[ name ][element[0]] = element[1];   
    }
 console.log($$map)
}


parse(temaplte);