UNPKG

markdown-it-attribution

Version:
4 lines (3 loc) 3.14 kB
/*! markdown-it-attribution 0.1.3 https://github.com/dweidner/markdown-it-attribution @license MIT */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).markdownitAttribution=e()}}(function(){return function i(l,a,u){function c(n,e){if(!a[n]){if(!l[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(f)return f(n,!0);var r=new Error("Cannot find module '"+n+"'");throw r.code="MODULE_NOT_FOUND",r}var o=a[n]={exports:{}};l[n][0].call(o.exports,function(e){return c(l[n][1][e]||e)},o,o.exports,i,l,a,u)}return a[n].exports}for(var f="function"==typeof require&&require,e=0;e<u.length;e++)c(u[e]);return c}({1:[function(e,n,t){n.exports=function(e,w){var q=/https?:\/\/[^\s/$.?#()].[^\s()]*/i,x="blockquote_open",N="blockquote_close",n=e.utils.assign;function u(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e}function O(e){return!e||0===e.length||0===e.trim().length}function T(e,n,t){for(var r=0,o=n.length;r<o;r++)e.splice(t+r,0,n[r])}function A(e,n,t){n=u(n)?n:0;var r=(t=u(t)?t:e.length-1)-n;return e.splice(n,r).length}function i(e,n){for(var t in n)if(r=n,o=t,Object.prototype.hasOwnProperty.call(r,o)&&n[t]!==e[t])return!1;var r,o;return!0}function C(e,n,t){for(var r=t=u(t)?t:0,o=e.length;r<o;r++)if(i(e[r],n))return r;return-1}function M(e,n){if(function(e,n){return e.slice(0,n.length)===n}(e,n))return 0;var t=n.length,r=e.indexOf("\n"+n,t+1);return t<r?r+1:-1}function S(e,n,t,r,o){t=u(t)?t:0,r=u(r)?r:0,o=u(o)?o:e.length;for(var i=r;i<o;i++){var l=e[i],a=l.content;if("inline"===l.type&&l.level===t+2&&0!==a.length)if(-1!==M(a,n))return i}return-1}w=n({},{classNameContainer:"c-blockquote",classNameAttribution:"c-blockquote__attribution",marker:"—",removeMarker:!0},w),e.core.ruler.after("block","attribution",function(e){for(var n,t=e.tokens,r=0,o=t.length;r<o;r++){var i=C(t,{type:x},r);if(-1!==i){var l=t[i].level,a=C(t,{type:N,level:l},i+1);if(-1!==a){var u=S(t,w.marker,l,i+1,a);if(-1!==u){for(var c=i;c<=a;c++)t[c].level++;var f=t[u],s=f.content,v=M(s,w.marker),p=0<v?s.slice(0,v).replace(/\s+$/,""):null,b=0<v?s.slice(v):s;O(f.content=p)&&(a-=A(t,u-1,u+2));var k=t[i],d=(n=void 0,null!==(n=b.match(q))?n.shift():null);O(d)||k.attrSet("cite",d);var h=new e.Token("blockquote_attribution_open","figcaption",1);h.block=!0,h.level=l+1;var g=new e.Token("inline","",0);g.children=[],g.level=l+2,g.content=w.removeMarker?b.slice(w.marker.length).replace(/^\s+/,""):b;var m=new e.Token("blockquote_attribution_close","figcaption",-1);m.block=!0,m.level=l+1,O(w.classNameAttribution)||h.attrSet("class",w.classNameAttribution),T(t,[h,g,m],a+1);var y=new e.Token("blockquote_container_open","figure",1);y.block=!0,y.level=l;var _=new e.Token("blockquote_container_close","figure",-1);_.block=!0,_.level=l,O(w.classNameContainer)||y.attrSet("class",w.classNameContainer),T(t,[_],a+4),T(t,[y],i),r=a+5,o+=4}}}}})}},{}]},{},[1])(1)}); //# sourceMappingURL=markdown-it-attribution.min.js.map