1 |
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).wtfHtml=e()}(this,(function(){"use strict";const t={title:!0,infoboxes:!0,headers:!0,sections:!0,links:!0},e=function(e){let n="";return!0===(e=Object.assign({},t,e)).title&&this._title&&(n+="<title>"+this._title+"</title>\n"),!0===this.isRedirect()?(n+=function(t){let e=t.redirectTo(),n=e.page;return n="./"+n.replace(/ /g,"_"),e.anchor&&(n+="#"+e.anchor),` <div class="redirect">\n ↳ <a class="link" href="./${n}">${e.text}</a>\n </div>`}(this),n):(!0===e.infoboxes&&(n+=this.infoboxes().map((t=>t.html(e))).join("\n")),!0!==e.sections&&!0!==e.paragraphs&&!0!==e.sentences||(n+=this.sections().map((t=>t.html(e))).join("\n")),!0===e.references&&(n+="<h2>References</h2>",n+=this.references().map((t=>t.html(e))).join("\n")),n)},n={headers:!0,images:!0,tables:!0,lists:!0,paragraphs:!0},i=function(t){t=Object.assign({},n,t);let e="";if(!0===t.headers&&this.title()){let t=1+this.depth();e+=" <h"+t+">"+this.title()+"</h"+t+">",e+="\n"}if(!0===t.images){let n=this.images();n.length>0&&(e+=n.map((e=>e.html(t))).join("\n"))}return!0===t.tables&&(e+=this.tables().map((e=>e.html(t))).join("\n")),!0===t.lists&&(e+=this.lists().map((e=>e.html(t))).join("\n")),!0===t.paragraphs&&this.paragraphs().length>0?(e+=' <div class="text">\n',this.paragraphs().forEach((n=>{e+=' <p class="paragraph">\n',e+=" "+n.sentences().map((e=>e.html(t))).join(" "),e+="\n </p>\n"})),e+=" </div>\n"):!0===t.sentences&&(e+=" "+this.sentences().map((e=>e.html(t))).join(" ")),'<div class="section">\n'+e+"</div>\n"},s={sentences:!0},a=function(t){let e="";return!0===(t=Object.assign({},s,t)).sentences&&(e+=this.sentences().map((e=>e.html(t))).join("\n")),e};const l=function(t,e,n){if(!e||!t)return t;"number"==typeof t&&(t=String(t)),e=e.replace(/[\-[\]/{}()*+?.\\^$|]/g,"\\$&");let i=new RegExp("\\b"+e+"\\b");return t=!0===i.test(t)?t.replace(i,n):t.replace(e,n)},r={links:!0,formatting:!0},h=function(t){t=Object.assign({},r,t);let e=this.text();return!0===t.links&&this.links().forEach((t=>{let n=t.text()||t.page(),i=t.html();e=l(e,n,i)})),!0===t.formatting&&(this.bolds().forEach((t=>{e=l(e,t,"<b>"+t+"</b>")})),this.italics().forEach((t=>{e=l(e,t,"<i>"+t+"</i>")}))),'<span class="sentence">'+e+"</span>"},o=function(){let t=this.href();return t=t.replace(/ /g,"_"),`<a class="link" href="${t}">${this.text()||this.page()}</a>`},c={images:!0},d={image:!0,caption:!0,alt:!0,signature:!0,"signature alt":!0},p=function(t){t=Object.assign({},c,t);let e='<table class="infobox">\n';if(e+=" <thead>\n",e+=" </thead>\n",e+=" <tbody>\n",!0===t.images&&this.data.image){if(e+=" <tr>\n",e+=' <td colspan="2" style="text-align:center">\n',e+=" "+this.image().html()+"\n",e+=" </td>\n",this.data.caption||this.data.alt){let n=this.data.caption?this.data.caption.html(t):this.data.alt.html(t);e+=' <td colspan="2" style="text-align:center">\n',e+=" "+n+"\n",e+=" </td>\n"}e+=" </tr>\n"}return Object.keys(this.data).forEach((n=>{if(!0===d[n])return;let i=this.data[n],s=n.replace(/_/g," ");s=s.charAt(0).toUpperCase()+s.substring(1);let a=i.html(t);e+=" <tr>\n",e+=" <td>"+s+"</td>\n",e+=" <td>"+a+"</td>\n",e+=" </tr>\n"})),e+=" </tbody>\n",e+="</table>\n",e},f=function(){return' <img src="'+this.thumbnail()+'" alt="'+this.alt()+'"/>'},m=function(t){let e=' <ul class="list">\n';return this.lines().forEach((n=>{e+=" <li>"+n.html(t)+"</li>\n"})),e+=" </ul>\n",e},u=function(t){if(this.data&&this.data.url&&this.data.title){let e=this.data.title;return!0===t.links&&(e=`<a href="${this.data.url}">${e}</a>`),`<div class="reference">⌃ ${e} </div>`}if(this.data.encyclopedia)return`<div class="reference">⌃ ${this.data.encyclopedia}</div>`;if(this.data.title){let t=this.data.title;return this.data.author&&(t+=this.data.author),this.data.first&&this.data.last&&(t+=this.data.first+" "+this.data.last),`<div class="reference">⌃ ${t}</div>`}return this.inline?`<div class="reference">⌃ ${this.inline.html()}</div>`:""},g=function(t){let e=this.data,n='<table class="table">\n';return n+=" <thead>\n",n+=" <tr>\n",Object.keys(e[0]).forEach((t=>{!0!==/^col[0-9]/.test(t)&&(n+=" <td>"+t+"</td>\n")})),n+=" </tr>\n",n+=" </thead>\n",n+=" <tbody>\n",e.forEach((e=>{n+=" <tr>\n",Object.keys(e).forEach((i=>{let s=e[i].html(t);n+=" <td>"+s+"</td>\n"})),n+=" </tr>\n"})),n+=" </tbody>\n",n+="</table>\n",n};return function(t){t.Doc.prototype.html=e,t.Section.prototype.html=i,t.Paragraph.prototype.html=a,t.Sentence.prototype.html=h,t.Image.prototype.html=f,t.Infobox.prototype.html=p,t.Link.prototype.html=o,t.List.prototype.html=m,t.Reference.prototype.html=u,t.Table.prototype.html=g}}));
|