2 lines
1.4 KiB
JavaScript
2 lines
1.4 KiB
JavaScript
|
|
import{e as b}from"./vendor-escape-string-regexp-BaJN9MlJ.js";import{c as E}from"./vendor-unist-util-is-BPZGFiMU.js";import{v as I}from"./vendor-unist-util-visit-parents-BHoKBdZX.js";function q(e,f,u){const p=E((u||{}).ignore||[]),x=R(f);let d=-1;for(;++d<x.length;)I(e,"text",m);function m(n,r){let c=-1,t;for(;++c<r.length;){const a=r[c],s=t?t.children:void 0;if(p(a,s?s.indexOf(a):void 0,t))return;t=a}if(t)return w(n,r)}function w(n,r){const c=r[r.length-1],t=x[d][0],a=x[d][1];let s=0;const y=c.children.indexOf(n);let v=!1,l=[];t.lastIndex=0;let o=t.exec(n.value);for(;o;){const h=o.index,A={index:o.index,input:o.input,stack:[...r,n]};let i=a(...o,A);if(typeof i=="string"&&(i=i.length>0?{type:"text",value:i}:void 0),i===!1?t.lastIndex=h+1:(s!==h&&l.push({type:"text",value:n.value.slice(s,h)}),Array.isArray(i)?l.push(...i):i&&l.push(i),s=h+o[0].length,v=!0),!t.global)break;o=t.exec(n.value)}return v?(s<n.value.length&&l.push({type:"text",value:n.value.slice(s)}),c.children.splice(y,1,...l)):l=[n],y+l.length}}function R(e){const f=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const u=!e[0]||Array.isArray(e[0])?e:[e];let g=-1;for(;++g<u.length;){const p=u[g];f.push([k(p[0]),P(p[1])])}return f}function k(e){return typeof e=="string"?new RegExp(b(e),"g"):e}function P(e){return typeof e=="function"?e:function(){return e}}export{q as f};
|