"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var text_format_exports = {};
__export(text_format_exports, {
decodeHTMLEntities: () => decodeHTMLEntities,
escapeHtml: () => escapeHtml,
formatHtmlHeader: () => formatHtmlHeader,
formatTextHeader: () => formatTextHeader,
htmlToText: () => htmlToText,
textToHtml: () => textToHtml
});
module.exports = __toCommonJS(text_format_exports);
var import_html_entities = __toESM(require("./html-entities.cjs"), 1);
function decodeHTMLEntities(str) {
return str.replace(/&(#\d+|#x[a-f0-9]+|[a-z]+\d*);?/gi, (match, entity) => {
if (typeof import_html_entities.default[match] === "string") {
return import_html_entities.default[match];
}
if (entity.charAt(0) !== "#" || match.charAt(match.length - 1) !== ";") {
return match;
}
let codePoint;
if (entity.charAt(1) === "x") {
codePoint = parseInt(entity.substr(2), 16);
} else {
codePoint = parseInt(entity.substr(1), 10);
}
let output = "";
if (codePoint >= 55296 && codePoint <= 57343 || codePoint > 1114111) {
return "\uFFFD";
}
if (codePoint > 65535) {
codePoint -= 65536;
output += String.fromCharCode(codePoint >>> 10 & 1023 | 55296);
codePoint = 56320 | codePoint & 1023;
}
output += String.fromCharCode(codePoint);
return output;
});
}
function escapeHtml(str) {
return str.trim().replace(/[<>"'?&]/g, (c) => {
let hex = c.charCodeAt(0).toString(16);
if (hex.length < 2) {
hex = "0" + hex;
}
return "" + hex.toUpperCase() + ";";
});
}
function textToHtml(str) {
let html = escapeHtml(str).replace(/\n/g, "
");
return "