Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1import { TAG_NAMES as $, NS, hasUnescapedText } from '../common/html.js';2import { escapeText, escapeAttribute } from 'entities/escape';3import { defaultTreeAdapter } from '../tree-adapters/default.js';4// Sets5const VOID_ELEMENTS = new Set([6 $.AREA,7 $.BASE,8 $.BASEFONT,9 $.BGSOUND,10 $.BR,11 $.COL,12 $.EMBED,13 $.FRAME,14 $.HR,15 $.IMG,16 $.INPUT,17 $.KEYGEN,18 $.LINK,19 $.META,20 $.PARAM,21 $.SOURCE,22 $.TRACK,23 $.WBR,24]);25function isVoidElement(node, options) {26 return (options.treeAdapter.isElementNode(node) &&27 options.treeAdapter.getNamespaceURI(node) === NS.HTML &&28 VOID_ELEMENTS.has(options.treeAdapter.getTagName(node)));29}30const defaultOpts = { treeAdapter: defaultTreeAdapter, scriptingEnabled: true };31/**32 * Serializes an AST node to an HTML string.33 *34 * @example35 *36 * ```js37 * const parse5 = require('parse5');38 *39 * const document = parse5.parse('<!DOCTYPE html><html><head></head><body>Hi there!</body></html>');40 *41 * // Serializes a document.42 * const html = parse5.serialize(document);43 *44 * // Serializes the <html> element content.45 * const str = parse5.serialize(document.childNodes[1]);46 *47 * console.log(str); //> '<head></head><body>Hi there!</body>'48 * ```49 *50 * @param node Node to serialize.51 * @param options Serialization options.52 */53export function serialize(node, options) {54 const opts = { ...defaultOpts, ...options };55 if (isVoidElement(node, opts)) {56 return '';57 }58 return serializeChildNodes(node, opts);59}60/**61 * Serializes an AST element node to an HTML string, including the element node.62 *63 * @example64 *65 * ```js66 * const parse5 = require('parse5');67 *68 * const document = parse5.parseFragment('<div>Hello, <b>world</b>!</div>');69 *70 * // Serializes the <div> element.71 * const str = parse5.serializeOuter(document.childNodes[0]);72 *73 * console.log(str); //> '<div>Hello, <b>world</b>!</div>'74 * ```75 *76 * @param node Node to serialize.77 * @param options Serialization options.78 */79export function serializeOuter(node, options) {80 const opts = { ...defaultOpts, ...options };81 return serializeNode(node, opts);82}83function serializeChildNodes(parentNode, options) {84 let html = '';85 // Get container of the child nodes86 const container = options.treeAdapter.isElementNode(parentNode) &&87 options.treeAdapter.getTagName(parentNode) === $.TEMPLATE &&88 options.treeAdapter.getNamespaceURI(parentNode) === NS.HTML89 ? options.treeAdapter.getTemplateContent(parentNode)90 : parentNode;91 const childNodes = options.treeAdapter.getChildNodes(container);92 if (childNodes) {93 for (const currentNode of childNodes) {94 html += serializeNode(currentNode, options);95 }96 }97 return html;98}99function serializeNode(node, options) {100 if (options.treeAdapter.isElementNode(node)) {101 return serializeElement(node, options);102 }103 if (options.treeAdapter.isTextNode(node)) {104 return serializeTextNode(node, options);105 }106 if (options.treeAdapter.isCommentNode(node)) {107 return serializeCommentNode(node, options);108 }109 if (options.treeAdapter.isDocumentTypeNode(node)) {110 return serializeDocumentTypeNode(node, options);111 }112 // Return an empty string for unknown nodes113 return '';114}115function serializeElement(node, options) {116 const tn = options.treeAdapter.getTagName(node);117 return `<${tn}${serializeAttributes(node, options)}>${isVoidElement(node, options) ? '' : `${serializeChildNodes(node, options)}</${tn}>`}`;118}119function serializeAttributes(node, { treeAdapter }) {120 let html = '';121 for (const attr of treeAdapter.getAttrList(node)) {122 html += ' ';123 if (attr.namespace) {124 switch (attr.namespace) {125 case NS.XML: {126 html += `xml:${attr.name}`;127 break;128 }129 case NS.XMLNS: {130 if (attr.name !== 'xmlns') {131 html += 'xmlns:';132 }133 html += attr.name;134 break;135 }136 case NS.XLINK: {137 html += `xlink:${attr.name}`;138 break;139 }140 default: {141 html += `${attr.prefix}:${attr.name}`;142 }143 }144 }145 else {146 html += attr.name;147 }148 html += `="${escapeAttribute(attr.value)}"`;149 }150 return html;151}152function serializeTextNode(node, options) {153 const { treeAdapter } = options;154 const content = treeAdapter.getTextNodeContent(node);155 const parent = treeAdapter.getParentNode(node);156 const parentTn = parent && treeAdapter.isElementNode(parent) && treeAdapter.getTagName(parent);157 return parentTn &&158 treeAdapter.getNamespaceURI(parent) === NS.HTML &&159 hasUnescapedText(parentTn, options.scriptingEnabled)160 ? content161 : escapeText(content);162}163function serializeCommentNode(node, { treeAdapter }) {164 return `<!--${treeAdapter.getCommentNodeContent(node)}-->`;165}166function serializeDocumentTypeNode(node, { treeAdapter }) {167 return `<!DOCTYPE ${treeAdapter.getDocumentTypeNodeName(node)}>`;168}169 