generated at
markdown-button

daiiz
このボタンを生やしてクリックすればScrapboxページをMarkdownに変換できる
変換したいときだけボタンを書けばいい
ボタン自身も変換後のMarkdownコードに含まれてしまうのはなんとかしたい
html-button tex-button を作りたくなってきた

button.js
function main(){var m=function(b){b=b.replace(/&/g,"&amp;");b=b.replace(/</g,"&lt;");b=b.replace(/>/g,"&gt;");b=b.replace(/"/g,"&quot;");return b=b.replace(/'/g,"&#39;")},n=function(b){b=void 0===b?0:b;for(var a="",g=1;g<b;g++)a+=" ";return a},p=function(b){b=void 0===b?"":b;var a=document.createElement("div");a.innerHTML=b;b=a.querySelectorAll("strong");for(var g=0;g<b.length;g++){for(var c=b[g],e=+c.className.split("level-")[1],d=c.innerHTML,e=void 0===e?1:e,e=6-e,f="",h=0;h<e;h++)f+="#";c.innerHTML= f+" "+d}return a.innerHTML},q=function(b){b=void 0===b?"":b;var a=document.createElement("div");a.innerHTML=b;b=a.querySelectorAll("a");for(var g=0;g<b.length;g++){var c=b[g],e=c.innerText.trim(),d=c.href,e="["+e+"]("+d+")",f=c.querySelector("img");null!==f&&(e="[![Image]("+f.src+")]("+d+")");c.innerText=e}return a.innerText},f=document.querySelector(".lines"),r=f.querySelector(".line-title .text").innerText,f=f.querySelectorAll(".line");var pageTexts=[];for(var l=1;l<f.length;l++){for(var d=f[l].querySelector(".text").cloneNode(!0), h=d.querySelectorAll("span.empty-char-index"),a=0;a<h.length;a++){var k=h[a];k.innerText=""}h=d.querySelectorAll("span.backquote");for(a=0;a<h.length;a++)k=h[a],k.innerText="`";a=d.innerHTML.replace(/<span>/g,"");a=a.replace(/<span.+?>/g,"").replace(/<\/span>/g,"");a=a.replace(/<br.+?>/g,"");a=a.replace(/\n/gi,"").replace(/\t/gi,"").trim();a=p(a);a=q(a);d=d.querySelector(".indent-mark");null!==d&&(k=+d.style.width.split("em")[0]/1.5,a=n(k)+"- "+a);null===d&&0<a.length&&"#"!==a[0]&&(a+="<br>");pageTexts.push(a)}(function(b, a){b=void 0===b?"Title":b;a=void 0===a?[]:a;for(var d="# "+b+"\n",c=0;c<a.length;c++)d+="\n"+a[c];print(m(d))} )(r,pageTexts)}; const print = body => { const bom = new Uint8Array([0xEF, 0xBB, 0xBF]) const url = URL.createObjectURL(new Blob([bom, body], { type: "text/plain", })) window.open(url) } main()


button.old.js
(function(){var m=function(b){b=b.replace(/&/g,"&amp;");b=b.replace(/</g,"&lt;");b=b.replace(/>/g,"&gt;");b=b.replace(/"/g,"&quot;");return b=b.replace(/'/g,"&#39;")},n=function(b){b=void 0===b?0:b;for(var a="",g=1;g<b;g++)a+=" ";return a},p=function(b){b=void 0===b?"":b;var a=document.createElement("div");a.innerHTML=b;b=a.querySelectorAll("strong");for(var g=0;g<b.length;g++){for(var c=b[g],e=+c.className.split("level-")[1],d=c.innerHTML,e=void 0===e?1:e,e=6-e,f="",h=0;h<e;h++)f+="#";c.innerHTML= f+" "+d}return a.innerHTML},q=function(b){b=void 0===b?"":b;var a=document.createElement("div");a.innerHTML=b;b=a.querySelectorAll("a");for(var g=0;g<b.length;g++){var c=b[g],e=c.innerText.trim(),d=c.href,e="["+e+"]("+d+")",f=c.querySelector("img");null!==f&&(e="[![Image]("+f.src+")]("+d+")");c.innerText=e}return a.innerText},f=document.querySelector(".lines"),r=f.querySelector(".line-title .text").innerText,f=f.querySelectorAll(".line");pageTexts=[];for(var l=1;l<f.length;l++){for(var d=f[l].querySelector(".text").cloneNode(!0), h=d.querySelectorAll("span.empty-char-index"),a=0;a<h.length;a++){var k=h[a];k.innerText=""}h=d.querySelectorAll("span.backquote");for(a=0;a<h.length;a++)k=h[a],k.innerText="`";a=d.innerHTML.replace(/<span>/g,"");a=a.replace(/<span.+?>/g,"").replace(/<\/span>/g,"");a=a.replace(/<br.+?>/g,"");a=a.replace(/\n/gi,"").replace(/\t/gi,"").trim();a=p(a);a=q(a);d=d.querySelector(".indent-mark");null!==d&&(k=+d.style.width.split("em")[0]/1.5,a=n(k)+"- "+a);null===d&&0<a.length&&"#"!==a[0]&&(a+="<br>");pageTexts.push(a)}(function(b, a){b=void 0===b?"Title":b;a=void 0===a?[]:a;for(var d="# "+b+"\n",c=0;c<a.length;c++)d+="\n"+a[c];c=window.open();c.document.open();c.document.write("<title>"+b+"</title>");c.document.write("<pre>");c.document.write(m(d));c.document.write("</pre>");c.document.close()})(r,pageTexts)})();