|
60 | 60 | </div> |
61 | 61 |
|
62 | 62 | <div id=view> |
| 63 | + |
63 | 64 | <div class='fn item'> |
64 | 65 | <div class=line> |
65 | 66 | </div> |
|
70 | 71 | <div class=args> |
71 | 72 | </div> |
72 | 73 | </div> |
| 74 | + |
73 | 75 | <div class='label item'> |
74 | 76 | </div> |
75 | | - </div> |
| 77 | + |
| 78 | + <div class='html item'> |
| 79 | + <div class=line> |
| 80 | + </div> |
| 81 | + <div class=name> |
| 82 | + </div> |
| 83 | + <div class=id> |
| 84 | + </div> |
| 85 | + <div class=class> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + |
| 89 | + </div view> |
76 | 90 |
|
77 | 91 | </template> |
78 | 92 |
|
|
224 | 238 | console.log(list); |
225 | 239 | view.replaceChildren(); |
226 | 240 |
|
| 241 | + list.forEach(o=>{ |
227 | 242 |
|
| 243 | + var node = ui.html.cloneNode(true); |
| 244 | + $(node,'.line').textContent = o.line; |
| 245 | + $(node,'.name').textContent = o.name; |
| 246 | + if(o.attrs.id){ |
| 247 | + $(node,'.id').textContent = o.attrs.id; |
| 248 | + }else{ |
| 249 | + $(node,'.id').remove(); |
| 250 | + } |
| 251 | + if(o.attrs.class){ |
| 252 | + $(node,'.class').textContent = o.attrs.class; |
| 253 | + }else{ |
| 254 | + $(node,'.class').remove(); |
| 255 | + } |
| 256 | + |
| 257 | + }); |
228 | 258 |
|
229 | 259 | }//html |
230 | 260 |
|
|
338 | 368 | if(!valid(name))return; |
339 | 369 |
|
340 | 370 | var args = parse.fn.args(txt,i1); |
341 | | - var indent = parse.fn.indent(txt,i1); |
| 371 | + var indent = parse.indent(txt,i1); |
342 | 372 |
|
343 | 373 | return {index:i1,name,args,indent}; |
344 | 374 |
|
|
371 | 401 | if(!valid(name))return; |
372 | 402 |
|
373 | 403 | var args = parse.fn.args(txt,i1); |
374 | | - var indent = parse.fn.indent(txt,i1); |
| 404 | + var indent = parse.indent(txt,i1); |
375 | 405 |
|
376 | 406 | return {index:i1,name,args,indent}; |
377 | 407 |
|
|
389 | 419 | }//args |
390 | 420 |
|
391 | 421 |
|
392 | | - parse.fn.indent = function(txt,i1){ |
| 422 | + parse.indent = function(txt,i1){ |
393 | 423 |
|
394 | 424 | var i2 = txt.lastIndexOf('\n',i1); |
395 | 425 | var i3 = txt.indexOf('\n',i1); |
|
474 | 504 |
|
475 | 505 | parse.html = function(txt){ |
476 | 506 |
|
| 507 | + var list = []; |
477 | 508 | var regex = /<\/?[a-z][a-z0-9]*\b[^>]*>/gi; |
478 | 509 |
|
479 | 510 | while(true){ |
|
485 | 516 | var tag = match[0]; |
486 | 517 |
|
487 | 518 | if(!tag.startsWith('</')){ |
488 | | - console.log(tag); |
489 | | -/* |
490 | | - var i1 = tagname.indexOf(' '); |
491 | | - var name = tagname.slice(2,i1); |
492 | | - var i2 = tagname.indexOf('>'); |
493 | | - var attrs = tagname.slice(i1+1,i2); |
494 | | -*/ |
| 519 | + //console.log(tag); |
495 | 520 | var match = tag.match(/^<\s*([a-z0-9\-]+)/i); |
496 | 521 | var name = match ? match[1].toLowerCase() : ''; |
497 | 522 | if(!name)debugger; |
498 | 523 | if(name){ |
499 | 524 | var parser = new DOMParser(); |
500 | 525 | var doc = parser.parseFromString(tag,'text/html'); |
501 | 526 | var element = doc.querySelector(name); |
502 | | - var attributes = {}; |
| 527 | + var attrs = {}; |
503 | 528 |
|
504 | 529 | for(var i=0;i<element.attributes.length;i++){ |
505 | 530 |
|
506 | | - var attr = element.attributes[i]; |
507 | | - attributes[attr.name] = (attr.value==='' ? true : attr.value); |
| 531 | + var attr = element.attributes[i]; |
| 532 | + attrs[attr.name] = (attr.value==='' ? true : attr.value); |
508 | 533 |
|
509 | 534 | }//for |
510 | 535 |
|
511 | | - console.log(name,attributes); |
| 536 | + //console.log(name,attributes); |
| 537 | + var line = lineno(txt,index); |
| 538 | + var indent = parse.indent(txt,index); |
| 539 | + |
| 540 | + var o = { |
| 541 | + index, |
| 542 | + line, |
| 543 | + indent, |
| 544 | + name, |
| 545 | + attrs |
| 546 | + }; |
| 547 | + list.push(o); |
512 | 548 | } |
513 | 549 |
|
514 | 550 |
|
|
518 | 554 |
|
519 | 555 | }//while |
520 | 556 |
|
| 557 | + return list; |
| 558 | + |
521 | 559 |
|
522 | 560 | }//html |
523 | 561 |
|
|
0 commit comments