laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
52 lines (51 loc) • 1.53 kB
JavaScript
"use client";
import { checkQuote as a } from "../util/check-quote.js";
import { formatLinkAsAutolink as c } from "../util/format-link-as-autolink.js";
b.peek = p;
function b(o, f, e, m) {
const n = a(e), v = n === '"' ? "Quote" : "Apostrophe", r = e.createTracker(m);
let l, i;
if (c(o, e)) {
const k = e.stack;
e.stack = [], l = e.enter("autolink");
let u = r.move("<");
return u += r.move(
e.containerPhrasing(o, {
before: u,
after: ">",
...r.current()
})
), u += r.move(">"), l(), e.stack = k, u;
}
l = e.enter("link"), i = e.enter("label");
let t = r.move("[");
return t += r.move(
e.containerPhrasing(o, {
before: t,
after: "](",
...r.current()
})
), t += r.move("]("), i(), // If there’s no url but there is a title…
!o.url && o.title || // If there are control characters or whitespace.
/[\0- \u007F]/.test(o.url) ? (i = e.enter("destinationLiteral"), t += r.move("<"), t += r.move(
e.safe(o.url, { before: t, after: ">", ...r.current() })
), t += r.move(">")) : (i = e.enter("destinationRaw"), t += r.move(
e.safe(o.url, {
before: t,
after: o.title ? " " : ")",
...r.current()
})
)), i(), o.title && (i = e.enter(`title${v}`), t += r.move(" " + n), t += r.move(
e.safe(o.title, {
before: t,
after: n,
...r.current()
})
), t += r.move(n), i()), t += r.move(")"), l(), t;
}
function p(o, f, e) {
return c(o, e) ? "<" : "[";
}
export {
b as link
};