@nextcloud/vue
Version:
Nextcloud vue components
1,644 lines • 115 kB
JavaScript
import '../assets/NcRichText-RvICaxkO.css';
import rehypeExternalLinks from "rehype-external-links";
import rehype2react from "rehype-react";
import breaks from "remark-breaks";
import remarkParse from "remark-parse";
import remark2rehype from "remark-rehype";
import remarkUnlinkProtocols from "remark-unlink-protocols";
import { unified } from "unified";
import { resolveComponent, createElementBlock, createCommentVNode, openBlock, normalizeClass, Fragment, renderList, createBlock, defineComponent, unref, withCtx, createVNode, ref, h } from "vue";
import { RouterLink } from "vue-router";
import { N as NcCheckboxRadioSwitch } from "./NcCheckboxRadioSwitch-BCSKF7Tk.mjs";
import { getCurrentUser } from "@nextcloud/auth";
import axios from "@nextcloud/axios";
import { generateOcsUrl } from "@nextcloud/router";
import { getSharingToken } from "@nextcloud/sharing/public";
import { f as NcReferenceWidget } from "./referencePickerModal-DmD3-xYB.mjs";
import { l as logger } from "./logger-D3RVzcfQ.mjs";
import { U as URL_PATTERN, g as getRoute, p as parseUrl, r as remarkAutolink } from "./autolink-U5pBzLgI.mjs";
import { _ as _export_sfc } from "./_plugin-vue_export-helper-1tPrXgE0.mjs";
import { N as NcButton } from "./NcButton-Dc8V4Urj.mjs";
import { N as NcIconSvgWrapper } from "./NcIconSvgWrapper-BvLanNaW.mjs";
import { u as useCopy } from "./useCopy-7FVrniF_.mjs";
import { c as createElementId } from "./createElementId-DhjFt1I9.mjs";
import { u } from "unist-builder";
import { visit, EXIT as EXIT$1, SKIP as SKIP$1 } from "unist-util-visit";
const _sfc_main$2 = {
name: "NcReferenceList",
components: {
NcReferenceWidget
},
/* eslint vue/require-prop-comment: warn -- TODO: Add a proper doc block about what this props do */
props: {
text: {
type: String,
default: ""
},
referenceData: {
type: Array,
default: null
},
limit: {
type: Number,
default: 1
},
displayFallback: {
type: Boolean,
default: false
},
interactive: {
type: Boolean,
default: true
},
interactiveOptIn: {
type: Boolean,
default: false
}
},
emits: ["loaded"],
data() {
return {
references: null,
loading: true
};
},
computed: {
isVisible() {
return this.loading || this.displayedReferences.length !== 0;
},
values() {
if (this.referenceData) {
return this.referenceData;
}
if (this.displayFallback && !this.loading && !this.references) {
return [this.fallbackReference];
}
return this.references ? Object.values(this.references) : [];
},
firstReference() {
return this.values[0] ?? null;
},
displayedReferences() {
return this.values.filter(Boolean).slice(0, this.limit);
},
fallbackReference() {
return {
accessible: true,
openGraphObject: {
id: this.text,
link: this.text,
name: this.text
},
richObjectType: "open-graph"
};
}
},
watch: {
text: "fetch"
},
mounted() {
this.fetch();
},
methods: {
fetch() {
this.loading = true;
if (this.referenceData) {
this.references = null;
this.loading = false;
return;
}
if (!new RegExp(URL_PATTERN).exec(this.text)) {
this.references = null;
this.loading = false;
return;
}
this.resolve().then((response) => {
this.references = response.data.ocs.data.references;
this.loading = false;
this.$emit("loaded");
}).catch((error) => {
logger.error("[NcReferenceList] Failed to extract references", { error });
this.loading = false;
this.$emit("loaded");
});
},
resolve() {
const match = new RegExp(URL_PATTERN).exec(this.text.trim());
const isPublic = getCurrentUser() === null;
if (this.limit === 1 && match) {
return isPublic ? axios.get(generateOcsUrl("references/resolvePublic") + `?reference=${encodeURIComponent(match[0])}&sharingToken=${getSharingToken()}`) : axios.get(generateOcsUrl("references/resolve") + `?reference=${encodeURIComponent(match[0])}`);
}
return isPublic ? axios.post(generateOcsUrl("references/extractPublic"), {
text: this.text,
resolve: true,
limit: this.limit,
sharingToken: getSharingToken()
}) : axios.post(generateOcsUrl("references/extract"), {
text: this.text,
resolve: true,
limit: this.limit
});
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_NcReferenceWidget = resolveComponent("NcReferenceWidget");
return $options.isVisible ? (openBlock(), createElementBlock("div", {
key: 0,
class: normalizeClass(["widgets--list", { "icon-loading": $data.loading }])
}, [
(openBlock(true), createElementBlock(Fragment, null, renderList($options.displayedReferences, (reference) => {
return openBlock(), createBlock(_component_NcReferenceWidget, {
key: reference.openGraphObject?.id,
reference,
interactive: $props.interactive,
"interactive-opt-in": $props.interactiveOptIn
}, null, 8, ["reference", "interactive", "interactive-opt-in"]);
}), 128))
], 2)) : createCommentVNode("", true);
}
const NcReferenceList = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render], ["__scopeId", "data-v-cd116174"]]);
function ccount(value, character) {
const source = String(value);
if (typeof character !== "string") {
throw new TypeError("Expected character");
}
let count = 0;
let index = source.indexOf(character);
while (index !== -1) {
count++;
index = source.indexOf(character, index + character.length);
}
return count;
}
function ok$1() {
}
const asciiAlpha = regexCheck(/[A-Za-z]/);
const asciiAlphanumeric = regexCheck(/[\dA-Za-z]/);
function asciiControl(code2) {
return (
// Special whitespace codes (which have negative values), C0 and Control
// character DEL
code2 !== null && (code2 < 32 || code2 === 127)
);
}
function markdownLineEnding(code2) {
return code2 !== null && code2 < -2;
}
function markdownLineEndingOrSpace(code2) {
return code2 !== null && (code2 < 0 || code2 === 32);
}
function markdownSpace(code2) {
return code2 === -2 || code2 === -1 || code2 === 32;
}
const unicodePunctuation = regexCheck(new RegExp("\\p{P}|\\p{S}", "u"));
const unicodeWhitespace = regexCheck(/\s/);
function regexCheck(regex) {
return check;
function check(code2) {
return code2 !== null && code2 > -1 && regex.test(String.fromCharCode(code2));
}
}
function escapeStringRegexp(string) {
if (typeof string !== "string") {
throw new TypeError("Expected a string");
}
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
}
const convert = (
// Note: overloads in JSDoc can’t yet use different `@template`s.
/**
* @type {(
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
* ((test?: Test) => Check)
* )}
*/
/**
* @param {Test} [test]
* @returns {Check}
*/
(function(test) {
if (test === null || test === void 0) {
return ok;
}
if (typeof test === "function") {
return castFactory(test);
}
if (typeof test === "object") {
return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
}
if (typeof test === "string") {
return typeFactory(test);
}
throw new Error("Expected function, string, or object as test");
})
);
function anyFactory(tests) {
const checks = [];
let index = -1;
while (++index < tests.length) {
checks[index] = convert(tests[index]);
}
return castFactory(any);
function any(...parameters) {
let index2 = -1;
while (++index2 < checks.length) {
if (checks[index2].apply(this, parameters)) return true;
}
return false;
}
}
function propsFactory(check) {
const checkAsRecord = (
/** @type {Record<string, unknown>} */
check
);
return castFactory(all2);
function all2(node2) {
const nodeAsRecord = (
/** @type {Record<string, unknown>} */
/** @type {unknown} */
node2
);
let key;
for (key in check) {
if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
}
return true;
}
}
function typeFactory(check) {
return castFactory(type);
function type(node2) {
return node2 && node2.type === check;
}
}
function castFactory(testFunction) {
return check;
function check(value, index, parent) {
return Boolean(
looksLikeANode(value) && testFunction.call(
this,
value,
typeof index === "number" ? index : void 0,
parent || void 0
)
);
}
}
function ok() {
return true;
}
function looksLikeANode(value) {
return value !== null && typeof value === "object" && "type" in value;
}
function color(d) {
return d;
}
const empty = [];
const CONTINUE = true;
const EXIT = false;
const SKIP = "skip";
function visitParents(tree, test, visitor, reverse) {
let check;
{
check = test;
}
const is = convert(check);
const step = 1;
factory(tree, void 0, [])();
function factory(node2, index, parents) {
const value = (
/** @type {Record<string, unknown>} */
node2 && typeof node2 === "object" ? node2 : {}
);
if (typeof value.type === "string") {
const name = (
// `hast`
typeof value.tagName === "string" ? value.tagName : (
// `xast`
typeof value.name === "string" ? value.name : void 0
)
);
Object.defineProperty(visit2, "name", {
value: "node (" + color(node2.type + (name ? "<" + name + ">" : "")) + ")"
});
}
return visit2;
function visit2() {
let result = empty;
let subresult;
let offset;
let grandparents;
if (is(node2, index, parents[parents.length - 1] || void 0)) {
result = toResult(visitor(node2, parents));
if (result[0] === EXIT) {
return result;
}
}
if ("children" in node2 && node2.children) {
const nodeAsParent = (
/** @type {UnistParent} */
node2
);
if (nodeAsParent.children && result[0] !== SKIP) {
offset = -1 + step;
grandparents = parents.concat(nodeAsParent);
while (offset > -1 && offset < nodeAsParent.children.length) {
const child = nodeAsParent.children[offset];
subresult = factory(child, offset, grandparents)();
if (subresult[0] === EXIT) {
return subresult;
}
offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
}
}
}
return result;
}
}
}
function toResult(value) {
if (Array.isArray(value)) {
return value;
}
if (typeof value === "number") {
return [CONTINUE, value];
}
return value === null || value === void 0 ? empty : [value];
}
function findAndReplace(tree, list2, options) {
const settings = options || {};
const ignored = convert(settings.ignore || []);
const pairs = toPairs(list2);
let pairIndex = -1;
while (++pairIndex < pairs.length) {
visitParents(tree, "text", visitor);
}
function visitor(node2, parents) {
let index = -1;
let grandparent;
while (++index < parents.length) {
const parent = parents[index];
const siblings = grandparent ? grandparent.children : void 0;
if (ignored(
parent,
siblings ? siblings.indexOf(parent) : void 0,
grandparent
)) {
return;
}
grandparent = parent;
}
if (grandparent) {
return handler(node2, parents);
}
}
function handler(node2, parents) {
const parent = parents[parents.length - 1];
const find = pairs[pairIndex][0];
const replace2 = pairs[pairIndex][1];
let start = 0;
const siblings = parent.children;
const index = siblings.indexOf(node2);
let change = false;
let nodes = [];
find.lastIndex = 0;
let match = find.exec(node2.value);
while (match) {
const position = match.index;
const matchObject = {
index: match.index,
input: match.input,
stack: [...parents, node2]
};
let value = replace2(...match, matchObject);
if (typeof value === "string") {
value = value.length > 0 ? { type: "text", value } : void 0;
}
if (value === false) {
find.lastIndex = position + 1;
} else {
if (start !== position) {
nodes.push({
type: "text",
value: node2.value.slice(start, position)
});
}
if (Array.isArray(value)) {
nodes.push(...value);
} else if (value) {
nodes.push(value);
}
start = position + match[0].length;
change = true;
}
if (!find.global) {
break;
}
match = find.exec(node2.value);
}
if (change) {
if (start < node2.value.length) {
nodes.push({ type: "text", value: node2.value.slice(start) });
}
parent.children.splice(index, 1, ...nodes);
} else {
nodes = [node2];
}
return index + nodes.length;
}
}
function toPairs(tupleOrList) {
const result = [];
if (!Array.isArray(tupleOrList)) {
throw new TypeError("Expected find and replace tuple or list of tuples");
}
const list2 = !tupleOrList[0] || Array.isArray(tupleOrList[0]) ? tupleOrList : [tupleOrList];
let index = -1;
while (++index < list2.length) {
const tuple = list2[index];
result.push([toExpression(tuple[0]), toFunction(tuple[1])]);
}
return result;
}
function toExpression(find) {
return typeof find === "string" ? new RegExp(escapeStringRegexp(find), "g") : find;
}
function toFunction(replace2) {
return typeof replace2 === "function" ? replace2 : function() {
return replace2;
};
}
const inConstruct = "phrasing";
const notInConstruct = ["autolink", "link", "image", "label"];
function gfmAutolinkLiteralFromMarkdown() {
return {
transforms: [transformGfmAutolinkLiterals],
enter: {
literalAutolink: enterLiteralAutolink,
literalAutolinkEmail: enterLiteralAutolinkValue,
literalAutolinkHttp: enterLiteralAutolinkValue,
literalAutolinkWww: enterLiteralAutolinkValue
},
exit: {
literalAutolink: exitLiteralAutolink,
literalAutolinkEmail: exitLiteralAutolinkEmail,
literalAutolinkHttp: exitLiteralAutolinkHttp,
literalAutolinkWww: exitLiteralAutolinkWww
}
};
}
function gfmAutolinkLiteralToMarkdown() {
return {
unsafe: [
{
character: "@",
before: "[+\\-.\\w]",
after: "[\\-.\\w]",
inConstruct,
notInConstruct
},
{
character: ".",
before: "[Ww]",
after: "[\\-.\\w]",
inConstruct,
notInConstruct
},
{
character: ":",
before: "[ps]",
after: "\\/",
inConstruct,
notInConstruct
}
]
};
}
function enterLiteralAutolink(token) {
this.enter({ type: "link", title: null, url: "", children: [] }, token);
}
function enterLiteralAutolinkValue(token) {
this.config.enter.autolinkProtocol.call(this, token);
}
function exitLiteralAutolinkHttp(token) {
this.config.exit.autolinkProtocol.call(this, token);
}
function exitLiteralAutolinkWww(token) {
this.config.exit.data.call(this, token);
const node2 = this.stack[this.stack.length - 1];
ok$1(node2.type === "link");
node2.url = "http://" + this.sliceSerialize(token);
}
function exitLiteralAutolinkEmail(token) {
this.config.exit.autolinkEmail.call(this, token);
}
function exitLiteralAutolink(token) {
this.exit(token);
}
function transformGfmAutolinkLiterals(tree) {
findAndReplace(
tree,
[
[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
[/([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/g, findEmail]
],
{ ignore: ["link", "linkReference"] }
);
}
function findUrl(_, protocol, domain2, path2, match) {
let prefix = "";
if (!previous(match)) {
return false;
}
if (/^w/i.test(protocol)) {
domain2 = protocol + domain2;
protocol = "";
prefix = "http://";
}
if (!isCorrectDomain(domain2)) {
return false;
}
const parts = splitUrl(domain2 + path2);
if (!parts[0]) return false;
const result = {
type: "link",
title: null,
url: prefix + protocol + parts[0],
children: [{ type: "text", value: protocol + parts[0] }]
};
if (parts[1]) {
return [result, { type: "text", value: parts[1] }];
}
return result;
}
function findEmail(_, atext, label, match) {
if (
// Not an expected previous character.
!previous(match, true) || // Label ends in not allowed character.
/[-\d_]$/.test(label)
) {
return false;
}
return {
type: "link",
title: null,
url: "mailto:" + atext + "@" + label,
children: [{ type: "text", value: atext + "@" + label }]
};
}
function isCorrectDomain(domain2) {
const parts = domain2.split(".");
if (parts.length < 2 || parts[parts.length - 1] && (/_/.test(parts[parts.length - 1]) || !/[a-zA-Z\d]/.test(parts[parts.length - 1])) || parts[parts.length - 2] && (/_/.test(parts[parts.length - 2]) || !/[a-zA-Z\d]/.test(parts[parts.length - 2]))) {
return false;
}
return true;
}
function splitUrl(url) {
const trailExec = /[!"&'),.:;<>?\]}]+$/.exec(url);
if (!trailExec) {
return [url, void 0];
}
url = url.slice(0, trailExec.index);
let trail2 = trailExec[0];
let closingParenIndex = trail2.indexOf(")");
const openingParens = ccount(url, "(");
let closingParens = ccount(url, ")");
while (closingParenIndex !== -1 && openingParens > closingParens) {
url += trail2.slice(0, closingParenIndex + 1);
trail2 = trail2.slice(closingParenIndex + 1);
closingParenIndex = trail2.indexOf(")");
closingParens++;
}
return [url, trail2];
}
function previous(match, email) {
const code2 = match.input.charCodeAt(match.index - 1);
return (match.index === 0 || unicodeWhitespace(code2) || unicodePunctuation(code2)) && (!email || code2 !== 47);
}
function normalizeIdentifier(value) {
return value.replace(/[\t\n\r ]+/g, " ").replace(/^ | $/g, "").toLowerCase().toUpperCase();
}
footnoteReference.peek = footnoteReferencePeek;
function enterFootnoteCallString() {
this.buffer();
}
function enterFootnoteCall(token) {
this.enter({ type: "footnoteReference", identifier: "", label: "" }, token);
}
function enterFootnoteDefinitionLabelString() {
this.buffer();
}
function enterFootnoteDefinition(token) {
this.enter(
{ type: "footnoteDefinition", identifier: "", label: "", children: [] },
token
);
}
function exitFootnoteCallString(token) {
const label = this.resume();
const node2 = this.stack[this.stack.length - 1];
ok$1(node2.type === "footnoteReference");
node2.identifier = normalizeIdentifier(
this.sliceSerialize(token)
).toLowerCase();
node2.label = label;
}
function exitFootnoteCall(token) {
this.exit(token);
}
function exitFootnoteDefinitionLabelString(token) {
const label = this.resume();
const node2 = this.stack[this.stack.length - 1];
ok$1(node2.type === "footnoteDefinition");
node2.identifier = normalizeIdentifier(
this.sliceSerialize(token)
).toLowerCase();
node2.label = label;
}
function exitFootnoteDefinition(token) {
this.exit(token);
}
function footnoteReferencePeek() {
return "[";
}
function footnoteReference(node2, _, state, info) {
const tracker = state.createTracker(info);
let value = tracker.move("[^");
const exit2 = state.enter("footnoteReference");
const subexit = state.enter("reference");
value += tracker.move(
state.safe(state.associationId(node2), { after: "]", before: value })
);
subexit();
exit2();
value += tracker.move("]");
return value;
}
function gfmFootnoteFromMarkdown() {
return {
enter: {
gfmFootnoteCallString: enterFootnoteCallString,
gfmFootnoteCall: enterFootnoteCall,
gfmFootnoteDefinitionLabelString: enterFootnoteDefinitionLabelString,
gfmFootnoteDefinition: enterFootnoteDefinition
},
exit: {
gfmFootnoteCallString: exitFootnoteCallString,
gfmFootnoteCall: exitFootnoteCall,
gfmFootnoteDefinitionLabelString: exitFootnoteDefinitionLabelString,
gfmFootnoteDefinition: exitFootnoteDefinition
}
};
}
function gfmFootnoteToMarkdown(options) {
let firstLineBlank = false;
if (options && options.firstLineBlank) {
firstLineBlank = true;
}
return {
handlers: { footnoteDefinition, footnoteReference },
// This is on by default already.
unsafe: [{ character: "[", inConstruct: ["label", "phrasing", "reference"] }]
};
function footnoteDefinition(node2, _, state, info) {
const tracker = state.createTracker(info);
let value = tracker.move("[^");
const exit2 = state.enter("footnoteDefinition");
const subexit = state.enter("label");
value += tracker.move(
state.safe(state.associationId(node2), { before: value, after: "]" })
);
subexit();
value += tracker.move("]:");
if (node2.children && node2.children.length > 0) {
tracker.shift(4);
value += tracker.move(
(firstLineBlank ? "\n" : " ") + state.indentLines(
state.containerFlow(node2, tracker.current()),
firstLineBlank ? mapAll : mapExceptFirst
)
);
}
exit2();
return value;
}
}
function mapExceptFirst(line, index, blank) {
return index === 0 ? line : mapAll(line, index, blank);
}
function mapAll(line, index, blank) {
return (blank ? "" : " ") + line;
}
const constructsWithoutStrikethrough = [
"autolink",
"destinationLiteral",
"destinationRaw",
"reference",
"titleQuote",
"titleApostrophe"
];
handleDelete.peek = peekDelete;
function gfmStrikethroughFromMarkdown() {
return {
canContainEols: ["delete"],
enter: { strikethrough: enterStrikethrough },
exit: { strikethrough: exitStrikethrough }
};
}
function gfmStrikethroughToMarkdown() {
return {
unsafe: [
{
character: "~",
inConstruct: "phrasing",
notInConstruct: constructsWithoutStrikethrough
}
],
handlers: { delete: handleDelete }
};
}
function enterStrikethrough(token) {
this.enter({ type: "delete", children: [] }, token);
}
function exitStrikethrough(token) {
this.exit(token);
}
function handleDelete(node2, _, state, info) {
const tracker = state.createTracker(info);
const exit2 = state.enter("strikethrough");
let value = tracker.move("~~");
value += state.containerPhrasing(node2, {
...tracker.current(),
before: value,
after: "~"
});
value += tracker.move("~~");
exit2();
return value;
}
function peekDelete() {
return "~";
}
function defaultStringLength(value) {
return value.length;
}
function markdownTable(table, options) {
const settings = options || {};
const align = (settings.align || []).concat();
const stringLength = settings.stringLength || defaultStringLength;
const alignments = [];
const cellMatrix = [];
const sizeMatrix = [];
const longestCellByColumn = [];
let mostCellsPerRow = 0;
let rowIndex = -1;
while (++rowIndex < table.length) {
const row2 = [];
const sizes2 = [];
let columnIndex2 = -1;
if (table[rowIndex].length > mostCellsPerRow) {
mostCellsPerRow = table[rowIndex].length;
}
while (++columnIndex2 < table[rowIndex].length) {
const cell = serialize(table[rowIndex][columnIndex2]);
if (settings.alignDelimiters !== false) {
const size = stringLength(cell);
sizes2[columnIndex2] = size;
if (longestCellByColumn[columnIndex2] === void 0 || size > longestCellByColumn[columnIndex2]) {
longestCellByColumn[columnIndex2] = size;
}
}
row2.push(cell);
}
cellMatrix[rowIndex] = row2;
sizeMatrix[rowIndex] = sizes2;
}
let columnIndex = -1;
if (typeof align === "object" && "length" in align) {
while (++columnIndex < mostCellsPerRow) {
alignments[columnIndex] = toAlignment(align[columnIndex]);
}
} else {
const code2 = toAlignment(align);
while (++columnIndex < mostCellsPerRow) {
alignments[columnIndex] = code2;
}
}
columnIndex = -1;
const row = [];
const sizes = [];
while (++columnIndex < mostCellsPerRow) {
const code2 = alignments[columnIndex];
let before = "";
let after = "";
if (code2 === 99) {
before = ":";
after = ":";
} else if (code2 === 108) {
before = ":";
} else if (code2 === 114) {
after = ":";
}
let size = settings.alignDelimiters === false ? 1 : Math.max(
1,
longestCellByColumn[columnIndex] - before.length - after.length
);
const cell = before + "-".repeat(size) + after;
if (settings.alignDelimiters !== false) {
size = before.length + size + after.length;
if (size > longestCellByColumn[columnIndex]) {
longestCellByColumn[columnIndex] = size;
}
sizes[columnIndex] = size;
}
row[columnIndex] = cell;
}
cellMatrix.splice(1, 0, row);
sizeMatrix.splice(1, 0, sizes);
rowIndex = -1;
const lines = [];
while (++rowIndex < cellMatrix.length) {
const row2 = cellMatrix[rowIndex];
const sizes2 = sizeMatrix[rowIndex];
columnIndex = -1;
const line = [];
while (++columnIndex < mostCellsPerRow) {
const cell = row2[columnIndex] || "";
let before = "";
let after = "";
if (settings.alignDelimiters !== false) {
const size = longestCellByColumn[columnIndex] - (sizes2[columnIndex] || 0);
const code2 = alignments[columnIndex];
if (code2 === 114) {
before = " ".repeat(size);
} else if (code2 === 99) {
if (size % 2) {
before = " ".repeat(size / 2 + 0.5);
after = " ".repeat(size / 2 - 0.5);
} else {
before = " ".repeat(size / 2);
after = before;
}
} else {
after = " ".repeat(size);
}
}
if (settings.delimiterStart !== false && !columnIndex) {
line.push("|");
}
if (settings.padding !== false && // Don’t add the opening space if we’re not aligning and the cell is
// empty: there will be a closing space.
!(settings.alignDelimiters === false && cell === "") && (settings.delimiterStart !== false || columnIndex)) {
line.push(" ");
}
if (settings.alignDelimiters !== false) {
line.push(before);
}
line.push(cell);
if (settings.alignDelimiters !== false) {
line.push(after);
}
if (settings.padding !== false) {
line.push(" ");
}
if (settings.delimiterEnd !== false || columnIndex !== mostCellsPerRow - 1) {
line.push("|");
}
}
lines.push(
settings.delimiterEnd === false ? line.join("").replace(/ +$/, "") : line.join("")
);
}
return lines.join("\n");
}
function serialize(value) {
return value === null || value === void 0 ? "" : String(value);
}
function toAlignment(value) {
const code2 = typeof value === "string" ? value.codePointAt(0) : 0;
return code2 === 67 || code2 === 99 ? 99 : code2 === 76 || code2 === 108 ? 108 : code2 === 82 || code2 === 114 ? 114 : 0;
}
function blockquote(node2, _, state, info) {
const exit2 = state.enter("blockquote");
const tracker = state.createTracker(info);
tracker.move("> ");
tracker.shift(2);
const value = state.indentLines(
state.containerFlow(node2, tracker.current()),
map$1
);
exit2();
return value;
}
function map$1(line, _, blank) {
return ">" + (blank ? "" : " ") + line;
}
function patternInScope(stack, pattern) {
return listInScope(stack, pattern.inConstruct, true) && !listInScope(stack, pattern.notInConstruct, false);
}
function listInScope(stack, list2, none) {
if (typeof list2 === "string") {
list2 = [list2];
}
if (!list2 || list2.length === 0) {
return none;
}
let index = -1;
while (++index < list2.length) {
if (stack.includes(list2[index])) {
return true;
}
}
return false;
}
function hardBreak(_, _1, state, info) {
let index = -1;
while (++index < state.unsafe.length) {
if (state.unsafe[index].character === "\n" && patternInScope(state.stack, state.unsafe[index])) {
return /[ \t]/.test(info.before) ? "" : " ";
}
}
return "\\\n";
}
function longestStreak(value, substring) {
const source = String(value);
let index = source.indexOf(substring);
let expected = index;
let count = 0;
let max = 0;
if (typeof substring !== "string") {
throw new TypeError("Expected substring");
}
while (index !== -1) {
if (index === expected) {
if (++count > max) {
max = count;
}
} else {
count = 1;
}
expected = index + substring.length;
index = source.indexOf(substring, expected);
}
return max;
}
function formatCodeAsIndented(node2, state) {
return Boolean(
state.options.fences === false && node2.value && // If there’s no info…
!node2.lang && // And there’s a non-whitespace character…
/[^ \r\n]/.test(node2.value) && // And the value doesn’t start or end in a blank…
!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(node2.value)
);
}
function checkFence(state) {
const marker = state.options.fence || "`";
if (marker !== "`" && marker !== "~") {
throw new Error(
"Cannot serialize code with `" + marker + "` for `options.fence`, expected `` ` `` or `~`"
);
}
return marker;
}
function code$1(node2, _, state, info) {
const marker = checkFence(state);
const raw = node2.value || "";
const suffix = marker === "`" ? "GraveAccent" : "Tilde";
if (formatCodeAsIndented(node2, state)) {
const exit3 = state.enter("codeIndented");
const value2 = state.indentLines(raw, map);
exit3();
return value2;
}
const tracker = state.createTracker(info);
const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3));
const exit2 = state.enter("codeFenced");
let value = tracker.move(sequence);
if (node2.lang) {
const subexit = state.enter(`codeFencedLang${suffix}`);
value += tracker.move(
state.safe(node2.lang, {
before: value,
after: " ",
encode: ["`"],
...tracker.current()
})
);
subexit();
}
if (node2.lang && node2.meta) {
const subexit = state.enter(`codeFencedMeta${suffix}`);
value += tracker.move(" ");
value += tracker.move(
state.safe(node2.meta, {
before: value,
after: "\n",
encode: ["`"],
...tracker.current()
})
);
subexit();
}
value += tracker.move("\n");
if (raw) {
value += tracker.move(raw + "\n");
}
value += tracker.move(sequence);
exit2();
return value;
}
function map(line, _, blank) {
return (blank ? "" : " ") + line;
}
function checkQuote(state) {
const marker = state.options.quote || '"';
if (marker !== '"' && marker !== "'") {
throw new Error(
"Cannot serialize title with `" + marker + "` for `options.quote`, expected `\"`, or `'`"
);
}
return marker;
}
function definition(node2, _, state, info) {
const quote = checkQuote(state);
const suffix = quote === '"' ? "Quote" : "Apostrophe";
const exit2 = state.enter("definition");
let subexit = state.enter("label");
const tracker = state.createTracker(info);
let value = tracker.move("[");
value += tracker.move(
state.safe(state.associationId(node2), {
before: value,
after: "]",
...tracker.current()
})
);
value += tracker.move("]: ");
subexit();
if (
// If there’s no url, or…
!node2.url || // If there are control characters or whitespace.
/[\0- \u007F]/.test(node2.url)
) {
subexit = state.enter("destinationLiteral");
value += tracker.move("<");
value += tracker.move(
state.safe(node2.url, { before: value, after: ">", ...tracker.current() })
);
value += tracker.move(">");
} else {
subexit = state.enter("destinationRaw");
value += tracker.move(
state.safe(node2.url, {
before: value,
after: node2.title ? " " : "\n",
...tracker.current()
})
);
}
subexit();
if (node2.title) {
subexit = state.enter(`title${suffix}`);
value += tracker.move(" " + quote);
value += tracker.move(
state.safe(node2.title, {
before: value,
after: quote,
...tracker.current()
})
);
value += tracker.move(quote);
subexit();
}
exit2();
return value;
}
function checkEmphasis(state) {
const marker = state.options.emphasis || "*";
if (marker !== "*" && marker !== "_") {
throw new Error(
"Cannot serialize emphasis with `" + marker + "` for `options.emphasis`, expected `*`, or `_`"
);
}
return marker;
}
function encodeCharacterReference(code2) {
return "&#x" + code2.toString(16).toUpperCase() + ";";
}
function classifyCharacter(code2) {
if (code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)) {
return 1;
}
if (unicodePunctuation(code2)) {
return 2;
}
}
function encodeInfo(outside, inside, marker) {
const outsideKind = classifyCharacter(outside);
const insideKind = classifyCharacter(inside);
if (outsideKind === void 0) {
return insideKind === void 0 ? (
// Letter inside:
// we have to encode *both* letters for `_` as it is looser.
// it already forms for `*` (and GFMs `~`).
marker === "_" ? { inside: true, outside: true } : { inside: false, outside: false }
) : insideKind === 1 ? (
// Whitespace inside: encode both (letter, whitespace).
{ inside: true, outside: true }
) : (
// Punctuation inside: encode outer (letter)
{ inside: false, outside: true }
);
}
if (outsideKind === 1) {
return insideKind === void 0 ? (
// Letter inside: already forms.
{ inside: false, outside: false }
) : insideKind === 1 ? (
// Whitespace inside: encode both (whitespace).
{ inside: true, outside: true }
) : (
// Punctuation inside: already forms.
{ inside: false, outside: false }
);
}
return insideKind === void 0 ? (
// Letter inside: already forms.
{ inside: false, outside: false }
) : insideKind === 1 ? (
// Whitespace inside: encode inner (whitespace).
{ inside: true, outside: false }
) : (
// Punctuation inside: already forms.
{ inside: false, outside: false }
);
}
emphasis.peek = emphasisPeek;
function emphasis(node2, _, state, info) {
const marker = checkEmphasis(state);
const exit2 = state.enter("emphasis");
const tracker = state.createTracker(info);
const before = tracker.move(marker);
let between = tracker.move(
state.containerPhrasing(node2, {
after: marker,
before,
...tracker.current()
})
);
const betweenHead = between.charCodeAt(0);
const open = encodeInfo(
info.before.charCodeAt(info.before.length - 1),
betweenHead,
marker
);
if (open.inside) {
between = encodeCharacterReference(betweenHead) + between.slice(1);
}
const betweenTail = between.charCodeAt(between.length - 1);
const close = encodeInfo(info.after.charCodeAt(0), betweenTail, marker);
if (close.inside) {
between = between.slice(0, -1) + encodeCharacterReference(betweenTail);
}
const after = tracker.move(marker);
exit2();
state.attentionEncodeSurroundingInfo = {
after: close.outside,
before: open.outside
};
return before + between + after;
}
function emphasisPeek(_, _1, state) {
return state.options.emphasis || "*";
}
const emptyOptions$1 = {};
function toString(value, options) {
const settings = emptyOptions$1;
const includeImageAlt = typeof settings.includeImageAlt === "boolean" ? settings.includeImageAlt : true;
const includeHtml = typeof settings.includeHtml === "boolean" ? settings.includeHtml : true;
return one(value, includeImageAlt, includeHtml);
}
function one(value, includeImageAlt, includeHtml) {
if (node(value)) {
if ("value" in value) {
return value.type === "html" && !includeHtml ? "" : value.value;
}
if (includeImageAlt && "alt" in value && value.alt) {
return value.alt;
}
if ("children" in value) {
return all(value.children, includeImageAlt, includeHtml);
}
}
if (Array.isArray(value)) {
return all(value, includeImageAlt, includeHtml);
}
return "";
}
function all(values, includeImageAlt, includeHtml) {
const result = [];
let index = -1;
while (++index < values.length) {
result[index] = one(values[index], includeImageAlt, includeHtml);
}
return result.join("");
}
function node(value) {
return Boolean(value && typeof value === "object");
}
function formatHeadingAsSetext(node2, state) {
let literalWithBreak = false;
visit(node2, function(node3) {
if ("value" in node3 && /\r?\n|\r/.test(node3.value) || node3.type === "break") {
literalWithBreak = true;
return EXIT$1;
}
});
return Boolean(
(!node2.depth || node2.depth < 3) && toString(node2) && (state.options.setext || literalWithBreak)
);
}
function heading(node2, _, state, info) {
const rank = Math.max(Math.min(6, node2.depth || 1), 1);
const tracker = state.createTracker(info);
if (formatHeadingAsSetext(node2, state)) {
const exit3 = state.enter("headingSetext");
const subexit2 = state.enter("phrasing");
const value2 = state.containerPhrasing(node2, {
...tracker.current(),
before: "\n",
after: "\n"
});
subexit2();
exit3();
return value2 + "\n" + (rank === 1 ? "=" : "-").repeat(
// The whole size…
value2.length - // Minus the position of the character after the last EOL (or
// 0 if there is none)…
(Math.max(value2.lastIndexOf("\r"), value2.lastIndexOf("\n")) + 1)
);
}
const sequence = "#".repeat(rank);
const exit2 = state.enter("headingAtx");
const subexit = state.enter("phrasing");
tracker.move(sequence + " ");
let value = state.containerPhrasing(node2, {
before: "# ",
after: "\n",
...tracker.current()
});
if (/^[\t ]/.test(value)) {
value = encodeCharacterReference(value.charCodeAt(0)) + value.slice(1);
}
value = value ? sequence + " " + value : sequence;
if (state.options.closeAtx) {
value += " " + sequence;
}
subexit();
exit2();
return value;
}
html.peek = htmlPeek;
function html(node2) {
return node2.value || "";
}
function htmlPeek() {
return "<";
}
image.peek = imagePeek;
function image(node2, _, state, info) {
const quote = checkQuote(state);
const suffix = quote === '"' ? "Quote" : "Apostrophe";
const exit2 = state.enter("image");
let subexit = state.enter("label");
const tracker = state.createTracker(info);
let value = tracker.move("![");
value += tracker.move(
state.safe(node2.alt, { before: value, after: "]", ...tracker.current() })
);
value += tracker.move("](");
subexit();
if (
// If there’s no url but there is a title…
!node2.url && node2.title || // If there are control characters or whitespace.
/[\0- \u007F]/.test(node2.url)
) {
subexit = state.enter("destinationLiteral");
value += tracker.move("<");
value += tracker.move(
state.safe(node2.url, { before: value, after: ">", ...tracker.current() })
);
value += tracker.move(">");
} else {
subexit = state.enter("destinationRaw");
value += tracker.move(
state.safe(node2.url, {
before: value,
after: node2.title ? " " : ")",
...tracker.current()
})
);
}
subexit();
if (node2.title) {
subexit = state.enter(`title${suffix}`);
value += tracker.move(" " + quote);
value += tracker.move(
state.safe(node2.title, {
before: value,
after: quote,
...tracker.current()
})
);
value += tracker.move(quote);
subexit();
}
value += tracker.move(")");
exit2();
return value;
}
function imagePeek() {
return "!";
}
imageReference.peek = imageReferencePeek;
function imageReference(node2, _, state, info) {
const type = node2.referenceType;
const exit2 = state.enter("imageReference");
let subexit = state.enter("label");
const tracker = state.createTracker(info);
let value = tracker.move("![");
const alt = state.safe(node2.alt, {
before: value,
after: "]",
...tracker.current()
});
value += tracker.move(alt + "][");
subexit();
const stack = state.stack;
state.stack = [];
subexit = state.enter("reference");
const reference = state.safe(state.associationId(node2), {
before: value,
after: "]",
...tracker.current()
});
subexit();
state.stack = stack;
exit2();
if (type === "full" || !alt || alt !== reference) {
value += tracker.move(reference + "]");
} else if (type === "shortcut") {
value = value.slice(0, -1);
} else {
value += tracker.move("]");
}
return value;
}
function imageReferencePeek() {
return "!";
}
inlineCode.peek = inlineCodePeek;
function inlineCode(node2, _, state) {
let value = node2.value || "";
let sequence = "`";
let index = -1;
while (new RegExp("(^|[^`])" + sequence + "([^`]|$)").test(value)) {
sequence += "`";
}
if (/[^ \r\n]/.test(value) && (/^[ \r\n]/.test(value) && /[ \r\n]$/.test(value) || /^`|`$/.test(value))) {
value = " " + value + " ";
}
while (++index < state.unsafe.length) {
const pattern = state.unsafe[index];
const expression = state.compilePattern(pattern);
let match;
if (!pattern.atBreak) continue;
while (match = expression.exec(value)) {
let position = match.index;
if (value.charCodeAt(position) === 10 && value.charCodeAt(position - 1) === 13) {
position--;
}
value = value.slice(0, position) + " " + value.slice(match.index + 1);
}
}
return sequence + value + sequence;
}
function inlineCodePeek() {
return "`";
}
function formatLinkAsAutolink(node2, state) {
const raw = toString(node2);
return Boolean(
!state.options.resourceLink && // If there’s a url…
node2.url && // And there’s a no title…
!node2.title && // And the content of `node` is a single text node…
node2.children && node2.children.length === 1 && node2.children[0].type === "text" && // And if the url is the same as the content…
(raw === node2.url || "mailto:" + raw === node2.url) && // And that starts w/ a protocol…
/^[a-z][a-z+.-]+:/i.test(node2.url) && // And that doesn’t contain ASCII control codes (character escapes and
// references don’t work), space, or angle brackets…
!/[\0- <>\u007F]/.test(node2.url)
);
}
link.peek = linkPeek;
function link(node2, _, state, info) {
const quote = checkQuote(state);
const suffix = quote === '"' ? "Quote" : "Apostrophe";
const tracker = state.createTracker(info);
let exit2;
let subexit;
if (formatLinkAsAutolink(node2, state)) {
const stack = state.stack;
state.stack = [];
exit2 = state.enter("autolink");
let value2 = tracker.move("<");
value2 += tracker.move(
state.containerPhrasing(node2, {
before: value2,
after: ">",
...tracker.current()
})
);
value2 += tracker.move(">");
exit2();
state.stack = stack;
return value2;
}
exit2 = state.enter("link");
subexit = state.enter("label");
let value = tracker.move("[");
value += tracker.move(
state.containerPhrasing(node2, {
before: value,
after: "](",
...tracker.current()
})
);
value += tracker.move("](");
subexit();
if (
// If there’s no url but there is a title…
!node2.url && node2.title || // If there are control characters or whitespace.
/[\0- \u007F]/.test(node2.url)
) {
subexit = state.enter("destinationLiteral");
value += tracker.move("<");
value += tracker.move(
state.safe(node2.url, { before: value, after: ">", ...tracker.current() })
);
value += tracker.move(">");
} else {
subexit = state.enter("destinationRaw");
value += tracker.move(
state.safe(node2.url, {
before: value,
after: node2.title ? " " : ")",
...tracker.current()
})
);
}
subexit();
if (node2.title) {
subexit = state.enter(`title${suffix}`);
value += tracker.move(" " + quote);
value += tracker.move(
state.safe(node2.title, {
before: value,
after: quote,
...tracker.current()
})
);
value += tracker.move(quote);
subexit();
}
value += tracker.move(")");
exit2();
return value;
}
function linkPeek(node2, _, state) {
return formatLinkAsAutolink(node2, state) ? "<" : "[";
}
linkReference.peek = linkReferencePeek;
function linkReference(node2, _, state, info) {
const type = node2.referenceType;
const exit2 = state.enter("linkReference");
let subexit = state.enter("label");
const tracker = state.createTracker(info);
let value = tracker.move("[");
const text2 = state.containerPhrasing(node2, {
before: value,
after: "]",
...tracker.current()
});
value += tracker.move(text2 + "][");
subexit();
const stack = state.stack;
state.stack = [];
subexit = state.enter("reference");
const reference = state.safe(state.associationId(node2), {
before: value,
after: "]",
...tracker.current()
});
subexit();
state.stack = stack;
exit2();
if (type === "full" || !text2 || text2 !== reference) {
value += tracker.move(reference + "]");
} else if (type === "shortcut") {
value = value.slice(0, -1);
} else {
value += tracker.move("]");
}
return value;
}
function linkReferencePeek() {
return "[";
}
function checkBullet(state) {
const marker = state.options.bullet || "*";
if (marker !== "*" && marker !== "+" && marker !== "-") {
throw new Error(
"Cannot serialize items with `" + marker + "` for `options.bullet`, expected `*`, `+`, or `-`"
);
}
return marker;
}
function checkBulletOther(state) {
const bullet = checkBullet(state);
const bulletOther = state.options.bulletOther;
if (!bulletOther) {
return bullet === "*" ? "-" : "*";
}
if (bulletOther !== "*" && bulletOther !== "+" && bulletOther !== "-") {
throw new Error(
"Cannot serialize items with `" + bulletOther + "` for `options.bulletOther`, expected `*`, `+`, or `-`"
);
}
if (bulletOther === bullet) {
throw new Error(
"Expected `bullet` (`" + bullet + "`) and `bulletOther` (`" + bulletOther + "`) to be different"
);
}
return bulletOther;
}
function checkBulletOrdered(state) {
const marker = state.options.bulletOrdered || ".";
if (marker !== "." && marker !== ")") {
throw new Error(
"Cannot serialize items with `" + marker + "` for `options.bulletOrdered`, expected `.` or `)`"
);
}
return marker;
}
function checkRule(state) {
const marker = state.options.rule || "*";
if (marker !== "*" && marker !== "-" && marker !== "_") {
throw new Error(
"Cannot serialize rules with `" + marker + "` for `options.rule`, expected `*`, `-`, or `_`"
);
}
return marker;
}
function list(node2, parent, state, info) {
const exit2 = state.enter("list");
const bulletCurrent = state.bulletCurrent;
let bullet = node2.ordered ? checkBulletOrdered(state) : checkBullet(state);
const bulletOther = node2.ordered ? bullet === "." ? ")" : "." : checkBulletOther(state);
let useDifferentMarker = parent && state.bulletLastUsed ? bullet === state.bulletLastUsed : false;
if (!node2.ordered) {
const firstListItem = node2.children ? node2.children[0] : void 0;
if (
// Bullet could be used as a thematic break marker:
(bullet === "*" || bullet === "-") && // Empty first list item:
firstListItem && (!firstListItem.children || !firstListItem.children[0]) && // Directly in two other list items:
state.stack[state.stack.length - 1] === "list" && state.stack[state.stack.length - 2] === "listItem" && state.stack[state.stack.length - 3] === "list" && state.stack[state.stack.length - 4] === "listItem" && // That are each the first child.
state.indexStack[state.indexStack.length - 1] === 0 && state.indexStack[state.indexStack.length - 2] === 0 && state.indexStack[state.indexStack.length - 3] === 0
) {
useDifferentMarker = true;
}
if (checkRule(state) === bullet && firstListItem) {
let index = -1;
while (++index < node2.children.length) {
const item = node2.children[index];
if (item && item.type === "listItem" && item.children && item.children[0] && item.children[0].type === "thematicBreak") {
useDifferentMarker = true;
break;
}
}
}
}
if (useDifferentMarker) {
bullet = bulletOther;
}
state.bulletCurrent = bullet;
const value = state.containerFlow(node2, info);
state.bulletLastUsed = bullet;
state.bulletCurrent = bulletCurrent;
exit2();
return value;
}
funct