unified-doc
Version:
unified document APIs.
3 lines (2 loc) • 4.53 kB
JavaScript
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t,r=e(require("unified-doc-search-micromatch")),n=e(require("vfile")),i=e(require("hast-util-raw")),u=e(require("hast-util-to-html")),a=e(require("hast-util-to-mdast")),o=e(require("hast-util-to-xast")),s=e(require("mdast-util-gfm")),c=e(require("mdast-util-to-markdown")),l=e(require("mime-types")),f=e(require("xast-util-to-xml")),d=e(require("hast-util-to-string")),p=e(require("deepmerge")),h=e(require("hast-util-sanitize")),m=e(require("hast-util-sanitize/lib/github.json")),v=e(require("rehype-parse")),g=e(require("rehype-stringify")),y=e(require("remark-parse")),x=e(require("remark-rehype")),q=e(require("unified")),k=e(require("unified-doc-parse-code-block")),b=e(require("unified-doc-parse-csv")),P=e(require("unified-doc-util-mark")),w=O;function O(e){if("string"==typeof e)return function(e){return function(t){return Boolean(t&&t.type===e)}}(e);if(null==e)return z;if("object"==typeof e)return("length"in e?C:j)(e);if("function"==typeof e)return e;throw new Error("Expected function, string, or object as test")}function j(e){return function(t){var r;for(r in e)if(t[r]!==e[r])return!1;return!0}}function C(e){var t=function(e){for(var t=[],r=e.length,n=-1;++n<r;)t[n]=O(e[n]);return t}(e),r=t.length;return function(){for(var e=-1;++e<r;)if(t[e].apply(this,arguments))return!0;return!1}}function z(){return!0}function A(e){return"head"!==e.tagName}function S(e){return d((t=e,r=A,n||(n=r,r={}),u=null==(u=r.cascade)||u,i=w(n),function e(t,r,n){var a,o,s,c;return i(t,r,n)?(a=Object.keys(t).reduce(function(e,r){return"children"!==r&&(e[r]=t[r]),e},{}),t.children&&(a.children=(o=t.children,s=function(r,n){return e(r,n,t)},c=[],Array.isArray(o)?(o.forEach(function(e,t,r){var n=s.call(void 0,e,t,r);Array.isArray(n)?c.push.apply(c,n):null!=n&&c.push(n)}),c):c),u&&0!==t.children.length&&0===a.children.length)?null:a):null}(t,null,null)));var t,r,n,i,u}function E(e){return l.lookup(e)||"text/plain"}function M(){return(M=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var N=((t={})["text/csv"]=[[b,{header:!0}]],t["text/html"]=[v],t["text/markdown"]=[y,x],t),R=function(e){return function(){var t=arguments;return function(r){return e.apply(void 0,[r].concat([].slice.call(t)))}}};function B(e,t){t.data.textContent=S(e)}module.exports=function(e){void 0===e&&(e={});var t=e.compiler,l=e.marks,d=void 0===l?[]:l,v=e.parsers,y=void 0===v?{}:v,x=e.postPlugins,b=void 0===x?[]:x,w=e.prePlugins,O=void 0===w?[]:w,j=e.sanitizeSchema,C=void 0===j?{}:j,z=e.searchAlgorithm,A=void 0===z?r:z,L=e.searchOptions,Q=void 0===L?{}:L,D=n({contents:e.content,basename:e.filename}),F=function(e){void 0===e&&(e={});var t=e.compiler,r=void 0===t?g:t,n=e.marks,i=void 0===n?[]:n,u=e.parsers,a=e.postPlugins,o=void 0===a?[]:a,s=e.prePlugins,c=void 0===s?[]:s,l=e.sanitizeSchema,f=e.vfile,d=M({},N,void 0===u?N:u),v=[[k,{language:f.extname.slice(1)}]],y=q(),x=E(f.basename);function b(){return y.processSync(f)}return y.use(d[x]||v),y.use(c),y.use(R(P),i),y.use(function(){return B}),y.use(o),l&&y.use(R(h),p(m,l)),y.use(r),{compile:b,parse:function(){return y.runSync(y.parse(f))},textContent:function(){return f.data.textContent||b(),f.data.textContent}}}({compiler:t,marks:d,parsers:y,postPlugins:b,prePlugins:O,sanitizeSchema:C,vfile:D});return{compile:function(){return F.compile()},file:function(e){return function(e){var t,r=e.extension,n=void 0===r?null:r,l=e.hast,d=void 0===l?null:l,p=e.vfile,h=n;switch(n){case".html":t=u(d);break;case".md":t=c(a(d),{extensions:[s.toMarkdown()]});break;case".txt":t=S(d);break;case".xml":var m=i({type:"element",tagName:"html",children:[d]});t=f(o(m));break;default:t=p.contents,h=p.extname}return{content:t,extension:h,name:""+p.stem+h,stem:p.stem,type:E(h)}}({extension:e,hast:this.parse(),vfile:D})},parse:function(){return F.parse()},search:function(e,t){void 0===t&&(t={});var r=Q.minQueryLength,n=Q.snippetOffsetPadding,i=void 0===n?100:n;if(e.length<(void 0===r?1:r))return[];var u=this.textContent();return function(e){var t=e.content,r=e.snippetOffsetPadding;return e.searchResults.map(function(e){var n=e.start,i=e.end,u=e.value;return M({},e,{snippet:[t.slice(Math.max(0,n-r),n),u,t.slice(i,Math.min(t.length,i+r))]})})}({content:u,searchResults:A(u,e,t),snippetOffsetPadding:i})},textContent:function(){return F.textContent()}}};
//# sourceMappingURL=index.js.map