|
84 | 84 | <div id=output class=markdown-body> |
85 | 85 | </div> |
86 | 86 |
|
| 87 | + <div id=npm-output class='_6d9832ac _704c034e'> |
| 88 | + <div id=readme> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + |
87 | 92 | <web-editor component mode=html style='display:none'></web-editor> |
88 | 93 |
|
89 | 94 | </div> |
|
127 | 132 | var output; |
128 | 133 | var chk = {}; |
129 | 134 |
|
| 135 | + var npm_output; |
130 | 136 | var editor; |
131 | 137 |
|
132 | 138 |
|
|
251 | 257 |
|
252 | 258 |
|
253 | 259 | output = $(shadow,'#output'); |
| 260 | + npm_output = $(shadow,'#npm-output'); |
254 | 261 |
|
255 | 262 |
|
256 | 263 | }//initdom |
|
322 | 329 | } |
323 | 330 | cur.txt = txt; |
324 | 331 |
|
| 332 | + if(chk.npm.checked){ |
| 333 | + display.npm(html); |
| 334 | + return; |
| 335 | + } |
| 336 | + |
325 | 337 | var opts = { |
326 | 338 | linkTarget : '_blank', |
327 | 339 | }; |
|
334 | 346 |
|
335 | 347 | var html = md.render(txt); |
336 | 348 |
|
337 | | - if(chk.npm.checked){ |
338 | | - display.npm(html); |
339 | | - }else{ |
340 | | - display[cur.mode](html); |
341 | | - } |
| 349 | + display[cur.mode](html); |
342 | 350 |
|
343 | 351 | }//show |
344 | 352 |
|
345 | 353 |
|
346 | 354 | display.md = function(html){ |
347 | 355 | debug('display.md'); |
348 | | - output.classList.remove('_6d9832ac','_704c034e'); |
| 356 | + show('output'); |
| 357 | + |
349 | 358 | output.innerHTML = html; |
350 | 359 |
|
351 | 360 | $(shadow,'#stylesheet').textContent = css.github; |
352 | 361 |
|
353 | | - output.style.display = ''; |
354 | | - editor.__host.style.display = 'none'; |
355 | 362 |
|
356 | 363 | }//md |
357 | 364 |
|
358 | 365 |
|
359 | | - display.npm = function(html){ |
| 366 | + display.npm = async function(txt){ |
360 | 367 | debug('display.npm'); |
361 | | - output.classList.add('_6d9832ac','_704c034e'); |
362 | | - output.innerHTML = html; |
| 368 | + var html = await github_markdown(txt); |
| 369 | + |
| 370 | + npm_output.innerHTML = html; |
363 | 371 |
|
364 | 372 | $(shadow,'#stylesheet').textContent = css.npm; |
365 | 373 |
|
366 | | - output.style.display = ''; |
367 | | - editor.__host.style.display = 'none'; |
| 374 | + show('npm'); |
368 | 375 |
|
369 | 376 | }//npm |
370 | 377 |
|
371 | 378 |
|
| 379 | + async function github_markdown(txt){ |
| 380 | + |
| 381 | + var body = txt; |
| 382 | + var res = await fetch('https://api.github.com/markdown/raw',{method:'post',body}); |
| 383 | + var txt = await res.text(); |
| 384 | + return txt; |
| 385 | + |
| 386 | + }//get |
| 387 | + |
| 388 | + |
372 | 389 | display.html = function(html){ |
373 | 390 | debug('display.html'); |
374 | 391 | editor.set(html); |
375 | 392 |
|
376 | | - output.style.display = 'none'; |
377 | | - editor.__host.style.display = ''; |
| 393 | + show('editor'); |
378 | 394 |
|
379 | 395 | }//html |
380 | 396 |
|
381 | 397 |
|
| 398 | + function show(id){ |
| 399 | + |
| 400 | + switch(id){ |
| 401 | + |
| 402 | + case 'output' : |
| 403 | + output.style.display = ''; |
| 404 | + npm_output.style.display = 'none'; |
| 405 | + editor.__host.style.display = 'none'; |
| 406 | + break; |
| 407 | + |
| 408 | + case 'npm' : |
| 409 | + output.style.display = 'none'; |
| 410 | + npm_output.style.display = ''; |
| 411 | + editor.__host.style.display = 'none'; |
| 412 | + break; |
| 413 | + |
| 414 | + case 'editor' : |
| 415 | + output.style.display = 'none'; |
| 416 | + npm_output.style.display = 'none'; |
| 417 | + editor.__host.style.display = ''; |
| 418 | + break; |
| 419 | + |
| 420 | + }//switch |
| 421 | + |
| 422 | + }//show |
| 423 | + |
| 424 | + |
382 | 425 | //: |
383 | 426 |
|
384 | 427 |
|
|
0 commit comments