Skip to content

Commit c5ddb95

Browse files
save file
1 parent 0ca437a commit c5ddb95

1 file changed

Lines changed: 58 additions & 15 deletions

File tree

utils/editors/markdown-editor/html/output-md/v2.0/output-md-v2.0.html

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
<div id=output class=markdown-body>
8585
</div>
8686

87+
<div id=npm-output class='_6d9832ac _704c034e'>
88+
<div id=readme>
89+
</div>
90+
</div>
91+
8792
<web-editor component mode=html style='display:none'></web-editor>
8893

8994
</div>
@@ -127,6 +132,7 @@
127132
var output;
128133
var chk = {};
129134

135+
var npm_output;
130136
var editor;
131137

132138

@@ -251,6 +257,7 @@
251257

252258

253259
output = $(shadow,'#output');
260+
npm_output = $(shadow,'#npm-output');
254261

255262

256263
}//initdom
@@ -322,6 +329,11 @@
322329
}
323330
cur.txt = txt;
324331

332+
if(chk.npm.checked){
333+
display.npm(html);
334+
return;
335+
}
336+
325337
var opts = {
326338
linkTarget : '_blank',
327339
};
@@ -334,51 +346,82 @@
334346

335347
var html = md.render(txt);
336348

337-
if(chk.npm.checked){
338-
display.npm(html);
339-
}else{
340-
display[cur.mode](html);
341-
}
349+
display[cur.mode](html);
342350

343351
}//show
344352

345353

346354
display.md = function(html){
347355
debug('display.md');
348-
output.classList.remove('_6d9832ac','_704c034e');
356+
show('output');
357+
349358
output.innerHTML = html;
350359

351360
$(shadow,'#stylesheet').textContent = css.github;
352361

353-
output.style.display = '';
354-
editor.__host.style.display = 'none';
355362

356363
}//md
357364

358365

359-
display.npm = function(html){
366+
display.npm = async function(txt){
360367
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;
363371

364372
$(shadow,'#stylesheet').textContent = css.npm;
365373

366-
output.style.display = '';
367-
editor.__host.style.display = 'none';
374+
show('npm');
368375

369376
}//npm
370377

371378

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+
372389
display.html = function(html){
373390
debug('display.html');
374391
editor.set(html);
375392

376-
output.style.display = 'none';
377-
editor.__host.style.display = '';
393+
show('editor');
378394

379395
}//html
380396

381397

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+
382425
//:
383426

384427

0 commit comments

Comments
 (0)