UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

132 lines (131 loc) 3.46 kB
"use client"; import { ccount as f } from "../../ccount/index.js"; import { ok as k } from "../../devlop/lib/default.js"; import { unicodeWhitespace as p, unicodePunctuation as d } from "../../micromark-util-character/index.js"; import { findAndReplace as g } from "../../mdast-util-find-and-replace/lib/index.js"; const u = "phrasing", a = ["autolink", "link", "image", "label"]; function b() { return { transforms: [y], enter: { literalAutolink: w, literalAutolinkEmail: s, literalAutolinkHttp: s, literalAutolinkWww: s }, exit: { literalAutolink: L, literalAutolinkEmail: m, literalAutolinkHttp: x, literalAutolinkWww: A } }; } function I() { return { unsafe: [ { character: "@", before: "[+\\-.\\w]", after: "[\\-.\\w]", inConstruct: u, notInConstruct: a }, { character: ".", before: "[Ww]", after: "[\\-.\\w]", inConstruct: u, notInConstruct: a }, { character: ":", before: "[ps]", after: "\\/", inConstruct: u, notInConstruct: a } ] }; } function w(t) { this.enter({ type: "link", title: null, url: "", children: [] }, t); } function s(t) { this.config.enter.autolinkProtocol.call(this, t); } function x(t) { this.config.exit.autolinkProtocol.call(this, t); } function A(t) { this.config.exit.data.call(this, t); const e = this.stack[this.stack.length - 1]; k(e.type === "link"), e.url = "http://" + this.sliceSerialize(t); } function m(t) { this.config.exit.autolinkEmail.call(this, t); } function L(t) { this.exit(t); } function y(t) { g( t, [ [/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, P], [new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)", "gu"), E] ], { ignore: ["link", "linkReference"] } ); } function P(t, e, i, n, o) { let l = ""; if (!h(o) || (/^w/i.test(e) && (i = e + i, e = "", l = "http://"), !W(i))) return !1; const r = _(i + n); if (!r[0]) return !1; const c = { type: "link", title: null, url: l + e + r[0], children: [{ type: "text", value: e + r[0] }] }; return r[1] ? [c, { type: "text", value: r[1] }] : c; } function E(t, e, i, n) { return ( // Not an expected previous character. !h(n, !0) || // Label ends in not allowed character. /[-\d_]$/.test(i) ? !1 : { type: "link", title: null, url: "mailto:" + e + "@" + i, children: [{ type: "text", value: e + "@" + i }] } ); } function W(t) { const e = t.split("."); return !(e.length < 2 || e[e.length - 1] && (/_/.test(e[e.length - 1]) || !/[a-zA-Z\d]/.test(e[e.length - 1])) || e[e.length - 2] && (/_/.test(e[e.length - 2]) || !/[a-zA-Z\d]/.test(e[e.length - 2]))); } function _(t) { const e = /[!"&'),.:;<>?\]}]+$/.exec(t); if (!e) return [t, void 0]; t = t.slice(0, e.index); let i = e[0], n = i.indexOf(")"); const o = f(t, "("); let l = f(t, ")"); for (; n !== -1 && o > l; ) t += i.slice(0, n + 1), i = i.slice(n + 1), n = i.indexOf(")"), l++; return [t, i]; } function h(t, e) { const i = t.input.charCodeAt(t.index - 1); return (t.index === 0 || p(i) || d(i)) && // If it’s an email, the previous character should not be a slash. (!e || i !== 47); } export { b as gfmAutolinkLiteralFromMarkdown, I as gfmAutolinkLiteralToMarkdown };