|
453 | 453 | fs.stat
|
454 | 454 | ================================================ */
|
455 | 455 |
|
456 |
| - function addDocument(text,language,fileName,path,css) { |
| 456 | + function addDocument(text,language,fileName,path,css,extension) { |
457 | 457 | var tab=document.createElement('li');
|
458 | 458 | // var css='';
|
459 | 459 | tab.textContent=fileName;
|
460 | 460 | // if(language=='markdown') var css=`${path}/${fileName.replace(/\..*$/,'')}/styles.css`;
|
461 | 461 |
|
462 |
| - tab.data={text, language, fileName, path, item: 0, highlighted: 1 , css}; |
| 462 | + tab.data={text, language, fileName, path, item: 0, highlighted: 1 , css,extension}; |
463 | 463 | tab.onclick=doTab;
|
464 | 464 |
|
465 | 465 | var close=document.createElement('button');
|
466 |
| - close.innerHTML=`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="8" height="8" viewBox="0, 0, 24, 24"><path d="M3.141,24 L-0,24 L10.332,11.935 L-0,0 L3.401,0 L12,9.06 L20.924,0 L24,0 L13.581,11.935 L24,24 L20.664,24 L12,14.33 z" fill="#000000"/></svg>`; // '⨉'; // ✖️ |
| 466 | + // close.innerHTML=`<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="8" height="8" viewBox="0, 0, 24, 24"><path d="M3.141,24 L-0,24 L10.332,11.935 L-0,0 L3.401,0 L12,9.06 L20.924,0 L24,0 L13.581,11.935 L24,24 L20.664,24 L12,14.33 z" fill="#000000"/></svg>`; // '⨉'; // ✖️ |
| 467 | + close.innerHTML='×'; |
467 | 468 | close.onclick=closeTab.bind(tab,tab);
|
468 |
| - close.id='tab-close'; |
| 469 | + close.className='tab-close'; |
469 | 470 | var refresh=document.createElement('button');
|
470 | 471 | refresh.innerHTML='↻';
|
471 | 472 | refresh.onclick=refreshTab.bind(tab);
|
472 |
| - refresh.id='tab-refresh'; |
| 473 | + refresh.className='tab-refresh'; |
473 | 474 |
|
474 | 475 | // Add to DOM
|
475 | 476 | tab.appendChild(close);
|
|
641 | 642 | if(!title.length) return;
|
642 | 643 |
|
643 | 644 | li.insertAdjacentHTML('beforeend',`<span>${title}</span>`);
|
644 |
| - if(value.match(headingMiniscule)) li.classList.add('subtitle'); |
| 645 | + if(data.language=='markdown' && value.match(headingMiniscule)) li.classList.add('subtitle'); |
645 | 646 | li.next=li.previous=undefined;
|
646 | 647 | if(previous) {
|
647 | 648 | previous.next=li;
|
|
669 | 670 | if(!selected) selected=li;
|
670 | 671 | });
|
671 | 672 |
|
672 |
| - |
673 |
| - |
674 | 673 | if(selected) selected.click();
|
675 | 674 | }
|
676 | 675 | else showItem(data.text,data.fileName,true);
|
|
707 | 706 | var language=['js','javascript','sql','php'].indexOf(data.language)>-1;
|
708 | 707 | elements.codeElement.textContent=item;
|
709 | 708 |
|
710 |
| - elements.codeElement.classList.forEach(className=>{if(className.startsWith('language-')) elements.codeElement.classList.remove(className);}); |
| 709 | + elements.codeElement. classList.forEach(className=>{if(className.startsWith('language-')) elements.codeElement.classList.remove(className);}); |
711 | 710 | elements.codeElement.classList.add(`language-${data.language}`);
|
712 | 711 | lineNumbers.style.display='block';
|
713 | 712 | elements.codeElement.style.display='block';
|
|
732 | 731 |
|
733 | 732 | div.innerHTML=innerHTML;
|
734 | 733 |
|
| 734 | +// var doEtc = false; if(doEtc) |
| 735 | + div.querySelectorAll('pre').forEach(pre=>{ |
| 736 | + var code = pre.querySelector('code'); |
| 737 | + // var codeDiv = document.createElement('div'); |
| 738 | + var html = code.innerHTML.replace(/ /g,'\t'); |
| 739 | + var language = code.className.match(/\blanguage-(.*)\b/)[1]; |
| 740 | + code.innerHTML=Prism.highlight(html, Prism.languages[language], language); |
| 741 | + // codeDiv.innerHTML=Prism.highlight(html, Prism.languages[language], language); |
| 742 | + // lineNumbers=jx.addLineNumbers(codeDiv); |
| 743 | + // code.parentNode.replaceChild(codeDiv,code); |
| 744 | + }); |
735 | 745 |
|
736 | 746 | var h2=div.querySelector('h1,h2,h3');
|
737 | 747 | // var h2=div.querySelector('h2');
|
|
766 | 776 | },false);
|
767 | 777 | });
|
768 | 778 |
|
769 |
| - |
770 | 779 | lineNumbers.style.display='none';
|
771 | 780 | elements.codeElement.style.display='none';
|
772 | 781 | elements.mdElement.style.display='block';
|
@@ -837,14 +846,44 @@ console.log(fileName);
|
837 | 846 | else result=openPath(fileName,remember);
|
838 | 847 | return result;
|
839 | 848 |
|
| 849 | + function virtualDocument(pathName) { |
| 850 | + var {path,fileName,extension,css}=pathDetails(pathName); |
| 851 | + fsp.stat(pathName) |
| 852 | + .then(()=>{ |
| 853 | + console.log(pathName); |
| 854 | + return load(`${path}/${fileName}`); |
| 855 | + }) |
| 856 | + .then(data=>{ |
| 857 | + data=JSON.parse(data); |
| 858 | + var md=[]; |
| 859 | + fetch(data.data.url) |
| 860 | + .then(response=>{ |
| 861 | + console.log(response); |
| 862 | + return response.json(); |
| 863 | + }) |
| 864 | + .then(images=>{ |
| 865 | + images.forEach(image=>{ |
| 866 | + md.push(`#\t${image.title}`); |
| 867 | + md.push(``); |
| 868 | + }); |
| 869 | + data = md.join('\n\n'); |
| 870 | + addDocument(data,extensions['md'],fileName,path,'','md'); |
| 871 | + }); |
| 872 | + |
| 873 | +// doSlides(images,'div#slides'); |
| 874 | + }); |
| 875 | + } |
| 876 | + |
840 | 877 | function openPath(pathName,remember=false) {
|
| 878 | + var {path,fileName,extension,css}=pathDetails(pathName); |
| 879 | + if(extension=='dpf') return virtualDocument(pathName); |
841 | 880 | return fsp.stat(pathName)
|
842 | 881 | .then(()=>{
|
843 |
| - var {path,fileName,extension,css}=pathDetails(pathName); |
| 882 | +// var {path,fileName,extension,css}=pathDetails(pathName); |
844 | 883 | return fsp.stat(css).catch(()=>css='')
|
845 | 884 | .then(()=>load(`${path}/${fileName}`))
|
846 | 885 | .then(data=> {
|
847 |
| - addDocument(data,extensions[extension],fileName,path,css); |
| 886 | + addDocument(data,extensions[extension],fileName,path,css,extension); |
848 | 887 | })
|
849 | 888 | .then(()=>{
|
850 | 889 | updateDocuments();
|
@@ -905,7 +944,7 @@ console.log(fileName);
|
905 | 944 | })
|
906 | 945 | .then((text)=>{
|
907 | 946 | if(cancelled) return;
|
908 |
| - addDocument(data,extensions[extension],fileName,path,css); |
| 947 | + addDocument(data,extensions[extension],fileName,path,css,extension); |
909 | 948 | })
|
910 | 949 | .then(()=>{
|
911 | 950 | if(cancelled || !remember) return;
|
|
0 commit comments