`;
}
tablecell(e) {
let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `${n}>
`;
}
strong({ tokens: e }) {
return `${this.parser.parseInline(e)}`;
}
em({ tokens: e }) {
return `${this.parser.parseInline(e)}`;
}
codespan({ text: e }) {
return `${O(e, !0)}`;
}
br(e) {
return " ";
}
del({ tokens: e }) {
return `${this.parser.parseInline(e)}`;
}
link({ href: e, title: t, tokens: n }) {
let s = this.parser.parseInline(n), r = Y(e);
if (r === null) return s;
e = r;
let i = '" + s + "", i;
}
image({ href: e, title: t, text: n, tokens: s }) {
s && (n = this.parser.parseInline(s, this.parser.textRenderer));
let r = Y(e);
if (r === null) return O(n);
e = r;
let i = `", i;
}
text(e) {
return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : O(e.text);
}
};
var L = class {
strong({ text: e }) {
return e;
}
em({ text: e }) {
return e;
}
codespan({ text: e }) {
return e;
}
del({ text: e }) {
return e;
}
html({ text: e }) {
return e;
}
text({ text: e }) {
return e;
}
link({ text: e }) {
return "" + e;
}
image({ text: e }) {
return "" + e;
}
br() {
return "";
}
checkbox({ raw: e }) {
return e;
}
};
var b = class l {
options;
renderer;
textRenderer;
constructor(e){
this.options = e || R, this.options.renderer = this.options.renderer || new P, this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new L;
}
static parse(e, t) {
return new l(t).parse(e);
}
static parseInline(e, t) {
return new l(t).parseInline(e);
}
parse(e) {
this.renderer.parser = this;
let t = "";
for(let n = 0; n < e.length; n++){
let s = e[n];
if (this.options.extensions?.renderers?.[s.type]) {
let i = s, o = this.options.extensions.renderers[i.type].call({
parser: this
}, i);
if (o !== !1 || ![
"space",
"hr",
"heading",
"code",
"table",
"blockquote",
"list",
"checkbox",
"html",
"def",
"paragraph",
"text"
].includes(i.type)) {
t += o || "";
continue;
}
}
let r = s;
switch(r.type){
case "space":
{
t += this.renderer.space(r);
break;
}
case "hr":
{
t += this.renderer.hr(r);
break;
}
case "heading":
{
t += this.renderer.heading(r);
break;
}
case "code":
{
t += this.renderer.code(r);
break;
}
case "table":
{
t += this.renderer.table(r);
break;
}
case "blockquote":
{
t += this.renderer.blockquote(r);
break;
}
case "list":
{
t += this.renderer.list(r);
break;
}
case "checkbox":
{
t += this.renderer.checkbox(r);
break;
}
case "html":
{
t += this.renderer.html(r);
break;
}
case "def":
{
t += this.renderer.def(r);
break;
}
case "paragraph":
{
t += this.renderer.paragraph(r);
break;
}
case "text":
{
t += this.renderer.text(r);
break;
}
default:
{
let i = 'Token with "' + r.type + '" type was not found.';
if (this.options.silent) return console.error(i), "";
throw new Error(i);
}
}
}
return t;
}
parseInline(e, t = this.renderer) {
this.renderer.parser = this;
let n = "";
for(let s = 0; s < e.length; s++){
let r = e[s];
if (this.options.extensions?.renderers?.[r.type]) {
let o = this.options.extensions.renderers[r.type].call({
parser: this
}, r);
if (o !== !1 || ![
"escape",
"html",
"link",
"image",
"checkbox",
"strong",
"em",
"codespan",
"br",
"del",
"text"
].includes(r.type)) {
n += o || "";
continue;
}
}
let i = r;
switch(i.type){
case "escape":
{
n += t.text(i);
break;
}
case "html":
{
n += t.html(i);
break;
}
case "link":
{
n += t.link(i);
break;
}
case "image":
{
n += t.image(i);
break;
}
case "checkbox":
{
n += t.checkbox(i);
break;
}
case "strong":
{
n += t.strong(i);
break;
}
case "em":
{
n += t.em(i);
break;
}
case "codespan":
{
n += t.codespan(i);
break;
}
case "br":
{
n += t.br(i);
break;
}
case "del":
{
n += t.del(i);
break;
}
case "text":
{
n += t.text(i);
break;
}
default:
{
let o = 'Token with "' + i.type + '" type was not found.';
if (this.options.silent) return console.error(o), "";
throw new Error(o);
}
}
}
return n;
}
};
var S = class {
options;
block;
constructor(e){
this.options = e || R;
}
static passThroughHooks = new Set([
"preprocess",
"postprocess",
"processAllTokens",
"emStrongMask"
]);
static passThroughHooksRespectAsync = new Set([
"preprocess",
"postprocess",
"processAllTokens"
]);
preprocess(e) {
return e;
}
postprocess(e) {
return e;
}
processAllTokens(e) {
return e;
}
emStrongMask(e) {
return e;
}
provideLexer(e = this.block) {
return e ? x.lex : x.lexInline;
}
provideParser(e = this.block) {
return e ? b.parse : b.parseInline;
}
};
var Z = class {
defaults = C();
options = this.setOptions;
parse = this.parseMarkdown(!0);
parseInline = this.parseMarkdown(!1);
Parser = b;
Renderer = P;
TextRenderer = L;
Lexer = x;
Tokenizer = y;
Hooks = S;
constructor(...e){
this.use(...e);
}
walkTokens(e, t) {
let n = [];
for (let s of e)switch(n = n.concat(t.call(this, s)), s.type){
case "table":
{
let r = s;
for (let i of r.header)n = n.concat(this.walkTokens(i.tokens, t));
for (let i of r.rows)for (let o of i)n = n.concat(this.walkTokens(o.tokens, t));
break;
}
case "list":
{
let r = s;
n = n.concat(this.walkTokens(r.items, t));
break;
}
default:
{
let r = s;
this.defaults.extensions?.childTokens?.[r.type] ? this.defaults.extensions.childTokens[r.type].forEach((i)=>{
let o = r[i].flat(1 / 0);
n = n.concat(this.walkTokens(o, t));
}) : r.tokens && (n = n.concat(this.walkTokens(r.tokens, t)));
}
}
return n;
}
use(...e) {
let t = this.defaults.extensions || {
renderers: {},
childTokens: {}
};
return e.forEach((n)=>{
let s = {
...n
};
if (s.async = this.defaults.async || s.async || !1, n.extensions && (n.extensions.forEach((r)=>{
if (!r.name) throw new Error("extension name required");
if ("renderer" in r) {
let i = t.renderers[r.name];
i ? t.renderers[r.name] = function(...o) {
let p = r.renderer.apply(this, o);
return p === !1 && (p = i.apply(this, o)), p;
} : t.renderers[r.name] = r.renderer;
}
if ("tokenizer" in r) {
if (!r.level || r.level !== "block" && r.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
let i = t[r.level];
i ? i.unshift(r.tokenizer) : t[r.level] = [
r.tokenizer
], r.start && (r.level === "block" ? t.startBlock ? t.startBlock.push(r.start) : t.startBlock = [
r.start
] : r.level === "inline" && (t.startInline ? t.startInline.push(r.start) : t.startInline = [
r.start
]));
}
"childTokens" in r && r.childTokens && (t.childTokens[r.name] = r.childTokens);
}), s.extensions = t), n.renderer) {
let r = this.defaults.renderer || new P(this.defaults);
for(let i in n.renderer){
if (!(i in r)) throw new Error(`renderer '${i}' does not exist`);
if ([
"options",
"parser"
].includes(i)) continue;
let o = i, p = n.renderer[o], a = r[o];
r[o] = (...u)=>{
let c = p.apply(r, u);
return c === !1 && (c = a.apply(r, u)), c || "";
};
}
s.renderer = r;
}
if (n.tokenizer) {
let r = this.defaults.tokenizer || new y(this.defaults);
for(let i in n.tokenizer){
if (!(i in r)) throw new Error(`tokenizer '${i}' does not exist`);
if ([
"options",
"rules",
"lexer"
].includes(i)) continue;
let o = i, p = n.tokenizer[o], a = r[o];
r[o] = (...u)=>{
let c = p.apply(r, u);
return c === !1 && (c = a.apply(r, u)), c;
};
}
s.tokenizer = r;
}
if (n.hooks) {
let r = this.defaults.hooks || new S;
for(let i in n.hooks){
if (!(i in r)) throw new Error(`hook '${i}' does not exist`);
if ([
"options",
"block"
].includes(i)) continue;
let o = i, p = n.hooks[o], a = r[o];
S.passThroughHooks.has(i) ? r[o] = (u)=>{
if (this.defaults.async && S.passThroughHooksRespectAsync.has(i)) return (async ()=>{
let h = await p.call(r, u);
return a.call(r, h);
})();
let c = p.call(r, u);
return a.call(r, c);
} : r[o] = (...u)=>{
if (this.defaults.async) return (async ()=>{
let h = await p.apply(r, u);
return h === !1 && (h = await a.apply(r, u)), h;
})();
let c = p.apply(r, u);
return c === !1 && (c = a.apply(r, u)), c;
};
}
s.hooks = r;
}
if (n.walkTokens) {
let r = this.defaults.walkTokens, i = n.walkTokens;
s.walkTokens = function(o) {
let p = [];
return p.push(i.call(this, o)), r && (p = p.concat(r.call(this, o))), p;
};
}
this.defaults = {
...this.defaults,
...s
};
}), this;
}
setOptions(e) {
return this.defaults = {
...this.defaults,
...e
}, this;
}
lexer(e, t) {
return x.lex(e, t ?? this.defaults);
}
parser(e, t) {
return b.parse(e, t ?? this.defaults);
}
parseMarkdown(e) {
return (n, s)=>{
let r = {
...s
}, i = {
...this.defaults,
...r
}, o = this.onError(!!i.silent, !!i.async);
if (this.defaults.async === !0 && r.async === !1) return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
if (typeof n > "u" || n === null) return o(new Error("marked(): input parameter is undefined or null"));
if (typeof n != "string") return o(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
if (i.hooks && (i.hooks.options = i, i.hooks.block = e), i.async) return (async ()=>{
let p = i.hooks ? await i.hooks.preprocess(n) : n, u = await (i.hooks ? await i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(p, i), c = i.hooks ? await i.hooks.processAllTokens(u) : u;
i.walkTokens && await Promise.all(this.walkTokens(c, i.walkTokens));
let d = await (i.hooks ? await i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(c, i);
return i.hooks ? await i.hooks.postprocess(d) : d;
})().catch(o);
try {
i.hooks && (n = i.hooks.preprocess(n));
let a = (i.hooks ? i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(n, i);
i.hooks && (a = i.hooks.processAllTokens(a)), i.walkTokens && this.walkTokens(a, i.walkTokens);
let c = (i.hooks ? i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(a, i);
return i.hooks && (c = i.hooks.postprocess(c)), c;
} catch (p) {
return o(p);
}
};
}
onError(e, t) {
return (n)=>{
if (n.message += `
Please report this to https://github.com/markedjs/marked.`, e) {
let s = "
An error occurred:
" + O(n.message + "", !0) + "
";
return t ? Promise.resolve(s) : s;
}
if (t) return Promise.reject(n);
throw n;
};
}
};
var E = new Z;
function f(l, e) {
return E.parse(l, e);
}
f.options = f.setOptions = function(l) {
return E.setOptions(l), f.defaults = E.defaults, j(f.defaults), f;
};
f.getDefaults = C;
f.defaults = R;
function kt(...l) {
return E.use(...l), f.defaults = E.defaults, j(f.defaults), f;
}
f.use = kt;
f.walkTokens = function(l, e) {
return E.walkTokens(l, e);
};
f.parseInline = E.parseInline;
f.Parser = b;
f.parser = b.parse;
f.Renderer = P;
f.TextRenderer = L;
f.Lexer = x;
f.lexer = x.lex;
f.Tokenizer = y;
f.Hooks = S;
f.parse = f;
var nn = f.options, rn = f.setOptions, sn = f.walkTokens, on = f.parseInline, an = f, ln = b.parse, pn = x.lex;
;
}),
"[project]/node_modules/parse-srcset/src/parse-srcset.js [app-ssr] (ecmascript)", ((__turbopack_context__, module, exports) => {
/**
* Srcset Parser
*
* By Alex Bell | MIT License
*
* JS Parser for the string value that appears in markup
*
* @returns Array [{url: _, d: _, w: _, h:_}, ...]
*
* Based super duper closely on the reference algorithm at:
* https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-srcset-attribute
*
* Most comments are copied in directly from the spec
* (except for comments in parens).
*/ (function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
((r)=>r !== undefined && __turbopack_context__.v(r))(factory());
} else if (("TURBOPACK compile-time value", "object") === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.parseSrcset = factory();
}
})(/*TURBOPACK member replacement*/ __turbopack_context__.e, function() {
// 1. Let input be the value passed to this algorithm.
return function(input) {
// UTILITY FUNCTIONS
// Manual is faster than RegEx
// http://bjorn.tipling.com/state-and-regular-expressions-in-javascript
// http://jsperf.com/whitespace-character/5
function isSpace(c) {
return c === "\u0020" || // space
c === "\u0009" || // horizontal tab
c === "\u000A" || // new line
c === "\u000C" || // form feed
c === "\u000D"; // carriage return
}
function collectCharacters(regEx) {
var chars, match = regEx.exec(input.substring(pos));
if (match) {
chars = match[0];
pos += chars.length;
return chars;
}
}
var inputLength = input.length, // (Don't use \s, to avoid matching non-breaking space)
regexLeadingSpaces = /^[ \t\n\r\u000c]+/, regexLeadingCommasOrSpaces = /^[, \t\n\r\u000c]+/, regexLeadingNotSpaces = /^[^ \t\n\r\u000c]+/, regexTrailingCommas = /[,]+$/, regexNonNegativeInteger = /^\d+$/, // ( Positive or negative or unsigned integers or decimals, without or without exponents.
// Must include at least one digit.
// According to spec tests any decimal point must be followed by a digit.
// No leading plus sign is allowed.)
// https://html.spec.whatwg.org/multipage/infrastructure.html#valid-floating-point-number
regexFloatingPoint = /^-?(?:[0-9]+|[0-9]*\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/, url, descriptors, currentDescriptor, state, c, // 2. Let position be a pointer into input, initially pointing at the start
// of the string.
pos = 0, // 3. Let candidates be an initially empty source set.
candidates = [];
// 4. Splitting loop: Collect a sequence of characters that are space
// characters or U+002C COMMA characters. If any U+002C COMMA characters
// were collected, that is a parse error.
while(true){
collectCharacters(regexLeadingCommasOrSpaces);
// 5. If position is past the end of input, return candidates and abort these steps.
if (pos >= inputLength) {
return candidates; // (we're done, this is the sole return path)
}
// 6. Collect a sequence of characters that are not space characters,
// and let that be url.
url = collectCharacters(regexLeadingNotSpaces);
// 7. Let descriptors be a new empty list.
descriptors = [];
// 8. If url ends with a U+002C COMMA character (,), follow these substeps:
// (1). Remove all trailing U+002C COMMA characters from url. If this removed
// more than one character, that is a parse error.
if (url.slice(-1) === ",") {
url = url.replace(regexTrailingCommas, "");
// (Jump ahead to step 9 to skip tokenization and just push the candidate).
parseDescriptors();
// Otherwise, follow these substeps:
} else {
tokenize();
} // (close else of step 8)
// 16. Return to the step labeled splitting loop.
} // (Close of big while loop.)
/**
* Tokenizes descriptor properties prior to parsing
* Returns undefined.
*/ function tokenize() {
// 8.1. Descriptor tokeniser: Skip whitespace
collectCharacters(regexLeadingSpaces);
// 8.2. Let current descriptor be the empty string.
currentDescriptor = "";
// 8.3. Let state be in descriptor.
state = "in descriptor";
while(true){
// 8.4. Let c be the character at position.
c = input.charAt(pos);
// Do the following depending on the value of state.
// For the purpose of this step, "EOF" is a special character representing
// that position is past the end of input.
// In descriptor
if (state === "in descriptor") {
// Do the following, depending on the value of c:
// Space character
// If current descriptor is not empty, append current descriptor to
// descriptors and let current descriptor be the empty string.
// Set state to after descriptor.
if (isSpace(c)) {
if (currentDescriptor) {
descriptors.push(currentDescriptor);
currentDescriptor = "";
state = "after descriptor";
}
// U+002C COMMA (,)
// Advance position to the next character in input. If current descriptor
// is not empty, append current descriptor to descriptors. Jump to the step
// labeled descriptor parser.
} else if (c === ",") {
pos += 1;
if (currentDescriptor) {
descriptors.push(currentDescriptor);
}
parseDescriptors();
return;
// U+0028 LEFT PARENTHESIS (()
// Append c to current descriptor. Set state to in parens.
} else if (c === "\u0028") {
currentDescriptor = currentDescriptor + c;
state = "in parens";
// EOF
// If current descriptor is not empty, append current descriptor to
// descriptors. Jump to the step labeled descriptor parser.
} else if (c === "") {
if (currentDescriptor) {
descriptors.push(currentDescriptor);
}
parseDescriptors();
return;
// Anything else
// Append c to current descriptor.
} else {
currentDescriptor = currentDescriptor + c;
}
// (end "in descriptor"
// In parens
} else if (state === "in parens") {
// U+0029 RIGHT PARENTHESIS ())
// Append c to current descriptor. Set state to in descriptor.
if (c === ")") {
currentDescriptor = currentDescriptor + c;
state = "in descriptor";
// EOF
// Append current descriptor to descriptors. Jump to the step labeled
// descriptor parser.
} else if (c === "") {
descriptors.push(currentDescriptor);
parseDescriptors();
return;
// Anything else
// Append c to current descriptor.
} else {
currentDescriptor = currentDescriptor + c;
}
// After descriptor
} else if (state === "after descriptor") {
// Do the following, depending on the value of c:
// Space character: Stay in this state.
if (isSpace(c)) {
// EOF: Jump to the step labeled descriptor parser.
} else if (c === "") {
parseDescriptors();
return;
// Anything else
// Set state to in descriptor. Set position to the previous character in input.
} else {
state = "in descriptor";
pos -= 1;
}
}
// Advance position to the next character in input.
pos += 1;
// Repeat this step.
} // (close while true loop)
}
/**
* Adds descriptor properties to a candidate, pushes to the candidates array
* @return undefined
*/ // Declared outside of the while loop so that it's only created once.
function parseDescriptors() {
// 9. Descriptor parser: Let error be no.
var pError = false, // 10. Let width be absent.
// 11. Let density be absent.
// 12. Let future-compat-h be absent. (We're implementing it now as h)
w, d, h, i, candidate = {}, desc, lastChar, value, intVal, floatVal;
// 13. For each descriptor in descriptors, run the appropriate set of steps
// from the following list:
for(i = 0; i < descriptors.length; i++){
desc = descriptors[i];
lastChar = desc[desc.length - 1];
value = desc.substring(0, desc.length - 1);
intVal = parseInt(value, 10);
floatVal = parseFloat(value);
// If the descriptor consists of a valid non-negative integer followed by
// a U+0077 LATIN SMALL LETTER W character
if (regexNonNegativeInteger.test(value) && lastChar === "w") {
// If width and density are not both absent, then let error be yes.
if (w || d) {
pError = true;
}
// Apply the rules for parsing non-negative integers to the descriptor.
// If the result is zero, let error be yes.
// Otherwise, let width be the result.
if (intVal === 0) {
pError = true;
} else {
w = intVal;
}
// If the descriptor consists of a valid floating-point number followed by
// a U+0078 LATIN SMALL LETTER X character
} else if (regexFloatingPoint.test(value) && lastChar === "x") {
// If width, density and future-compat-h are not all absent, then let error
// be yes.
if (w || d || h) {
pError = true;
}
// Apply the rules for parsing floating-point number values to the descriptor.
// If the result is less than zero, let error be yes. Otherwise, let density
// be the result.
if (floatVal < 0) {
pError = true;
} else {
d = floatVal;
}
// If the descriptor consists of a valid non-negative integer followed by
// a U+0068 LATIN SMALL LETTER H character
} else if (regexNonNegativeInteger.test(value) && lastChar === "h") {
// If height and density are not both absent, then let error be yes.
if (h || d) {
pError = true;
}
// Apply the rules for parsing non-negative integers to the descriptor.
// If the result is zero, let error be yes. Otherwise, let future-compat-h
// be the result.
if (intVal === 0) {
pError = true;
} else {
h = intVal;
}
// Anything else, Let error be yes.
} else {
pError = true;
}
} // (close step 13 for loop)
// 15. If error is still no, then append a new image source to candidates whose
// URL is url, associated with a width width if not absent and a pixel
// density density if not absent. Otherwise, there is a parse error.
if (!pError) {
candidate.url = url;
if (w) {
candidate.w = w;
}
if (d) {
candidate.d = d;
}
if (h) {
candidate.h = h;
}
candidates.push(candidate);
} else if (console && console.log) {
console.log("Invalid srcset descriptor found in '" + input + "' at '" + desc + "'.");
}
} // (close parseDescriptors fn)
};
});
}),
"[project]/node_modules/sanitize-html/index.js [app-ssr] (ecmascript)", ((__turbopack_context__, module, exports) => {
const htmlparser = __turbopack_context__.r("[project]/node_modules/htmlparser2/dist/index.js [app-ssr] (ecmascript)");
const escapeStringRegexp = __turbopack_context__.r("[project]/node_modules/escape-string-regexp/index.js [app-ssr] (ecmascript)");
const { isPlainObject } = __turbopack_context__.r("[project]/node_modules/is-plain-object/dist/is-plain-object.js [app-ssr] (ecmascript)");
const deepmerge = __turbopack_context__.r("[project]/node_modules/deepmerge/dist/cjs.js [app-ssr] (ecmascript)");
const parseSrcset = __turbopack_context__.r("[project]/node_modules/parse-srcset/src/parse-srcset.js [app-ssr] (ecmascript)");
const { parse: postcssParse } = __turbopack_context__.r("[externals]/postcss [external] (postcss, cjs, [project]/node_modules/postcss)");
const { naughtyHref: launderNaughtyHref } = __turbopack_context__.r("[project]/node_modules/launder/index.js [app-ssr] (ecmascript)");
// Tags that can conceivably represent stand-alone media.
const mediaTags = [
'img',
'audio',
'video',
'picture',
'svg',
'object',
'map',
'iframe',
'embed'
];
// Tags that are inherently vulnerable to being used in XSS attacks.
const vulnerableTags = [
'script',
'style'
];
function each(obj, cb) {
if (obj) {
Object.keys(obj).forEach(function(key) {
cb(obj[key], key);
});
}
}
// Avoid false positives with .__proto__, .hasOwnProperty, etc.
function has(obj, key) {
return ({}).hasOwnProperty.call(obj, key);
}
// Returns those elements of `a` for which `cb(a)` returns truthy
function filter(a, cb) {
const n = [];
each(a, function(v) {
if (cb(v)) {
n.push(v);
}
});
return n;
}
function isEmptyObject(obj) {
for(const key in obj){
if (has(obj, key)) {
return false;
}
}
return true;
}
function stringifySrcset(parsedSrcset) {
return parsedSrcset.map(function(part) {
if (!part.url) {
throw new Error('URL missing');
}
return part.url + (part.w ? ` ${part.w}w` : '') + (part.h ? ` ${part.h}h` : '') + (part.d ? ` ${part.d}x` : '');
}).join(', ');
}
module.exports = sanitizeHtml;
// A valid attribute name.
// We use a tolerant definition based on the set of strings defined by
// html.spec.whatwg.org/multipage/parsing.html#before-attribute-name-state
// and html.spec.whatwg.org/multipage/parsing.html#attribute-name-state .
// The characters accepted are ones which can be appended to the attribute
// name buffer without triggering a parse error:
// * unexpected-equals-sign-before-attribute-name
// * unexpected-null-character
// * unexpected-character-in-attribute-name
// We exclude the empty string because it's impossible to get to the after
// attribute name state with an empty attribute name buffer.
const VALID_HTML_ATTRIBUTE_NAME = /^[^\0\t\n\f\r /<=>]+$/;
// Ignore the _recursing flag; it's there for recursive
// invocation as a guard against this exploit:
// https://github.com/fb55/htmlparser2/issues/105
function sanitizeHtml(html, options, _recursing) {
if (html == null) {
return '';
}
if (typeof html === 'number') {
html = html.toString();
}
let result = '';
// Used for hot swapping the result variable with an empty string
// in order to "capture" the text written to it.
let tempResult = '';
function Frame(tag, attribs) {
const that = this;
this.tag = tag;
this.attribs = attribs || {};
this.tagPosition = result.length;
this.text = ''; // Node inner text
this.openingTagLength = 0;
this.mediaChildren = [];
this.updateParentNodeText = function() {
if (stack.length) {
const parentFrame = stack[stack.length - 1];
parentFrame.text += that.text;
}
};
this.updateParentNodeMediaChildren = function() {
if (stack.length && mediaTags.includes(this.tag)) {
const parentFrame = stack[stack.length - 1];
parentFrame.mediaChildren.push(this.tag);
}
};
}
options = Object.assign({}, sanitizeHtml.defaults, options);
options.parser = Object.assign({}, htmlParserDefaults, options.parser);
const tagAllowed = function(name) {
return options.allowedTags === false || (options.allowedTags || []).indexOf(name) > -1;
};
// vulnerableTags
vulnerableTags.forEach(function(tag) {
if (tagAllowed(tag) && !options.allowVulnerableTags) {
console.warn(`\n\n⚠️ Your \`allowedTags\` option includes, \`${tag}\`, which is inherently\nvulnerable to XSS attacks. Please remove it from \`allowedTags\`.\nOr, to disable this warning, add the \`allowVulnerableTags\` option\nand ensure you are accounting for this risk.\n\n`);
}
});
// Tags that contain something other than HTML, or where discarding
// the text when the tag is disallowed makes sense for other reasons.
// If we are not allowing these tags, we should drop their content too.
// For other tags you would drop the tag but keep its content.
// `xmp` is included because htmlparser2 treats it as a raw-text element,
// so markup inside is parsed as text on input but would otherwise be
// re-emitted unescaped via the `ontext` branch below, allowing XSS bypass
// when `xmp` is disallowed (which is the default).
const nonTextTagsArray = options.nonTextTags || [
'script',
'style',
'textarea',
'option',
'xmp'
];
let allowedAttributesMap;
let allowedAttributesGlobMap;
if (options.allowedAttributes) {
allowedAttributesMap = {};
allowedAttributesGlobMap = {};
each(options.allowedAttributes, function(attributes, tag) {
allowedAttributesMap[tag] = [];
const globRegex = [];
attributes.forEach(function(obj) {
if (typeof obj === 'string' && obj.indexOf('*') >= 0) {
globRegex.push(escapeStringRegexp(obj).replace(/\\\*/g, '.*'));
} else {
allowedAttributesMap[tag].push(obj);
}
});
if (globRegex.length) {
allowedAttributesGlobMap[tag] = new RegExp('^(' + globRegex.join('|') + ')$');
}
});
}
const allowedClassesMap = {};
const allowedClassesGlobMap = {};
const allowedClassesRegexMap = {};
each(options.allowedClasses, function(classes, tag) {
// Implicitly allows the class attribute
if (allowedAttributesMap) {
if (!has(allowedAttributesMap, tag)) {
allowedAttributesMap[tag] = [];
}
allowedAttributesMap[tag].push('class');
}
allowedClassesMap[tag] = classes;
if (Array.isArray(classes)) {
const globRegex = [];
allowedClassesMap[tag] = [];
allowedClassesRegexMap[tag] = [];
classes.forEach(function(obj) {
if (typeof obj === 'string' && obj.indexOf('*') >= 0) {
globRegex.push(escapeStringRegexp(obj).replace(/\\\*/g, '.*'));
} else if (obj instanceof RegExp) {
allowedClassesRegexMap[tag].push(obj);
} else {
allowedClassesMap[tag].push(obj);
}
});
if (globRegex.length) {
allowedClassesGlobMap[tag] = new RegExp('^(' + globRegex.join('|') + ')$');
}
}
});
const transformTagsMap = {};
let transformTagsAll;
each(options.transformTags, function(transform, tag) {
let transFun;
if (typeof transform === 'function') {
transFun = transform;
} else if (typeof transform === 'string') {
transFun = sanitizeHtml.simpleTransform(transform);
}
if (tag === '*') {
transformTagsAll = transFun;
} else {
transformTagsMap[tag] = transFun;
}
});
let depth;
let stack;
let skipMap;
let transformMap;
let skipText;
let skipTextDepth;
let addedText = false;
initializeState();
const parser = new htmlparser.Parser({
onopentag: function(name, attribs) {
if (options.onOpenTag) {
options.onOpenTag(name, attribs);
}
// If `enforceHtmlBoundary` is `true` and this has found the opening
// `html` tag, reset the state.
if (options.enforceHtmlBoundary && name === 'html') {
initializeState();
}
if (skipText) {
skipTextDepth++;
return;
}
const frame = new Frame(name, attribs);
stack.push(frame);
let skip = false;
const hasText = !!frame.text;
let transformedTag;
if (has(transformTagsMap, name)) {
transformedTag = transformTagsMap[name](name, attribs);
frame.attribs = attribs = transformedTag.attribs;
if (transformedTag.text !== undefined) {
frame.innerText = transformedTag.text;
}
if (name !== transformedTag.tagName) {
frame.name = name = transformedTag.tagName;
transformMap[depth] = transformedTag.tagName;
}
}
if (transformTagsAll) {
transformedTag = transformTagsAll(name, attribs);
frame.attribs = attribs = transformedTag.attribs;
if (name !== transformedTag.tagName) {
frame.name = name = transformedTag.tagName;
transformMap[depth] = transformedTag.tagName;
}
}
if (!tagAllowed(name) || options.disallowedTagsMode === 'recursiveEscape' && !isEmptyObject(skipMap) || options.nestingLimit != null && depth >= options.nestingLimit) {
skip = true;
skipMap[depth] = true;
if (options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') {
if (nonTextTagsArray.indexOf(name) !== -1) {
skipText = true;
skipTextDepth = 1;
}
}
}
depth++;
if (skip) {
if (options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') {
// We want the contents but not this tag
if (frame.innerText && !hasText) {
const escaped = escapeHtml(frame.innerText);
if (options.textFilter) {
result += options.textFilter(escaped, name);
} else {
result += escaped;
}
addedText = true;
}
return;
}
tempResult = result;
result = '';
}
result += '<' + name;
if (name === 'script') {
if (options.allowedScriptHostnames || options.allowedScriptDomains) {
frame.innerText = '';
}
}
const isBeingEscaped = skip && (options.disallowedTagsMode === 'escape' || options.disallowedTagsMode === 'recursiveEscape');
const shouldPreserveEscapedAttributes = isBeingEscaped && options.preserveEscapedAttributes;
if (shouldPreserveEscapedAttributes) {
each(attribs, function(value, a) {
result += ' ' + a + '="' + escapeHtml(value || '', true) + '"';
});
} else if (!allowedAttributesMap || has(allowedAttributesMap, name) || allowedAttributesMap['*']) {
each(attribs, function(value, a) {
if (!VALID_HTML_ATTRIBUTE_NAME.test(a)) {
// This prevents part of an attribute name in the output from being
// interpreted as the end of an attribute, or end of a tag.
delete frame.attribs[a];
return;
}
// If the value is empty, check if the attribute is
// in the allowedEmptyAttributes array.
// If it is not in the allowedEmptyAttributes array,
// and it is a known non-boolean attribute, delete it
// List taken from https://html.spec.whatwg.org/multipage/indices.html#attributes-3
if (value === '' && !options.allowedEmptyAttributes.includes(a) && (options.nonBooleanAttributes.includes(a) || options.nonBooleanAttributes.includes('*'))) {
delete frame.attribs[a];
return;
}
// check allowedAttributesMap for the element and attribute and modify the value
// as necessary if there are specific values defined.
let passedAllowedAttributesMapCheck = false;
if (!allowedAttributesMap || has(allowedAttributesMap, name) && allowedAttributesMap[name].indexOf(a) !== -1 || allowedAttributesMap['*'] && allowedAttributesMap['*'].indexOf(a) !== -1 || has(allowedAttributesGlobMap, name) && allowedAttributesGlobMap[name].test(a) || allowedAttributesGlobMap['*'] && allowedAttributesGlobMap['*'].test(a)) {
passedAllowedAttributesMapCheck = true;
} else if (allowedAttributesMap && allowedAttributesMap[name]) {
for (const o of allowedAttributesMap[name]){
if (isPlainObject(o) && o.name && o.name === a) {
passedAllowedAttributesMapCheck = true;
let newValue = '';
if (o.multiple === true) {
// verify the values that are allowed
const splitStrArray = value.split(' ');
for (const s of splitStrArray){
if (o.values.indexOf(s) !== -1) {
if (newValue === '') {
newValue = s;
} else {
newValue += ' ' + s;
}
}
}
} else if (o.values.indexOf(value) >= 0) {
// verified an allowed value matches the entire attribute value
newValue = value;
}
value = newValue;
}
}
}
if (passedAllowedAttributesMapCheck) {
if (options.allowedSchemesAppliedToAttributes.indexOf(a) !== -1) {
if (naughtyHref(name, value)) {
delete frame.attribs[a];
return;
}
}
if (name === 'script' && a === 'src') {
let allowed = true;
try {
const parsed = parseUrl(value);
if (options.allowedScriptHostnames || options.allowedScriptDomains) {
const allowedHostname = (options.allowedScriptHostnames || []).find(function(hostname) {
return hostname === parsed.url.hostname;
});
const allowedDomain = (options.allowedScriptDomains || []).find(function(domain) {
return parsed.url.hostname === domain || parsed.url.hostname.endsWith(`.${domain}`);
});
allowed = allowedHostname || allowedDomain;
}
} catch (e) {
allowed = false;
}
if (!allowed) {
delete frame.attribs[a];
return;
}
}
if (name === 'iframe' && a === 'src') {
let allowed = true;
try {
const parsed = parseUrl(value);
if (parsed.isRelativeUrl) {
// default value of allowIframeRelativeUrls is true
// unless allowedIframeHostnames or allowedIframeDomains specified
allowed = has(options, 'allowIframeRelativeUrls') ? options.allowIframeRelativeUrls : !options.allowedIframeHostnames && !options.allowedIframeDomains;
} else if (options.allowedIframeHostnames || options.allowedIframeDomains) {
const allowedHostname = (options.allowedIframeHostnames || []).find(function(hostname) {
return hostname === parsed.url.hostname;
});
const allowedDomain = (options.allowedIframeDomains || []).find(function(domain) {
return parsed.url.hostname === domain || parsed.url.hostname.endsWith(`.${domain}`);
});
allowed = allowedHostname || allowedDomain;
}
} catch (e) {
// Unparseable iframe src
allowed = false;
}
if (!allowed) {
delete frame.attribs[a];
return;
}
}
if (a === 'srcset' || a === 'imagesrcset') {
try {
let parsed = parseSrcset(value);
parsed.forEach(function(value) {
if (naughtyHref(a, value.url)) {
value.evil = true;
}
});
parsed = filter(parsed, function(v) {
return !v.evil;
});
if (!parsed.length) {
delete frame.attribs[a];
return;
} else {
value = stringifySrcset(filter(parsed, function(v) {
return !v.evil;
}));
frame.attribs[a] = value;
}
} catch (e) {
// Unparseable srcset
delete frame.attribs[a];
return;
}
}
if (a === 'class') {
const allowedSpecificClasses = allowedClassesMap[name];
const allowedWildcardClasses = allowedClassesMap['*'];
const allowedSpecificClassesGlob = allowedClassesGlobMap[name];
const allowedSpecificClassesRegex = allowedClassesRegexMap[name];
const allowedWildcardClassesRegex = allowedClassesRegexMap['*'];
const allowedWildcardClassesGlob = allowedClassesGlobMap['*'];
const allowedClassesGlobs = [
allowedSpecificClassesGlob,
allowedWildcardClassesGlob
].concat(allowedSpecificClassesRegex, allowedWildcardClassesRegex).filter(function(t) {
return t;
});
if (allowedSpecificClasses && allowedWildcardClasses) {
value = filterClasses(value, deepmerge(allowedSpecificClasses, allowedWildcardClasses), allowedClassesGlobs);
} else {
value = filterClasses(value, allowedSpecificClasses || allowedWildcardClasses, allowedClassesGlobs);
}
if (!value.length) {
delete frame.attribs[a];
return;
}
}
if (a === 'style') {
if (options.parseStyleAttributes) {
try {
const abstractSyntaxTree = postcssParse(name + ' {' + value + '}', {
map: false
});
const filteredAST = filterCss(abstractSyntaxTree, options.allowedStyles);
value = stringifyStyleAttributes(filteredAST);
if (value.length === 0) {
delete frame.attribs[a];
return;
}
} catch (e) {
if ("TURBOPACK compile-time falsy", 0) //TURBOPACK unreachable
;
delete frame.attribs[a];
return;
}
} else if (options.allowedStyles) {
throw new Error('allowedStyles option cannot be used together with parseStyleAttributes: false.');
}
}
result += ' ' + a;
if (value && value.length) {
result += '="' + escapeHtml(value, true) + '"';
} else if (options.allowedEmptyAttributes.includes(a)) {
result += '=""';
}
} else {
delete frame.attribs[a];
}
});
}
if (options.selfClosing.indexOf(name) !== -1) {
result += ' />';
} else {
result += '>';
if (frame.innerText && !hasText) {
const escaped = escapeHtml(frame.innerText);
if (options.textFilter) {
result += options.textFilter(escaped, name);
} else {
result += escaped;
}
addedText = true;
}
}
if (skip) {
result = tempResult + escapeHtml(result);
tempResult = '';
}
frame.openingTagLength = result.length - frame.tagPosition;
},
ontext: function(text) {
if (skipText) {
return;
}
const lastFrame = stack[stack.length - 1];
let tag;
if (lastFrame) {
tag = lastFrame.tag;
// If inner text was set by transform function then let's use it
text = lastFrame.innerText !== undefined ? lastFrame.innerText : text;
}
if (options.disallowedTagsMode === 'completelyDiscard' && !tagAllowed(tag)) {
text = '';
} else if (tag && tagAllowed(tag) && (options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && (tag === 'script' || tag === 'style')) {
// htmlparser2 gives us these as-is. Escaping them ruins the content. Allowing
// script tags is, by definition, game over for XSS protection, so if that's
// your concern, don't allow them. The same is essentially true for style tags
// which have their own collection of XSS vectors.
result += text;
} else if (tag && tagAllowed(tag) && (options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && (tag === 'textarea' || tag === 'xmp')) {
// ` solidus mis-close). We therefore ALWAYS escape this
// content rather than passing it through. Escaping unconditionally also
// closes the related SVG/MathML foreign-content bypass (where the HTML5
// parser treats