progress on migrating to heex templates and font-icons
This commit is contained in:
parent
d43daafdb7
commit
3eff955672
21793 changed files with 2161968 additions and 16895 deletions
assets_old/node_modules/posthtml-render/lib
67
assets_old/node_modules/posthtml-render/lib/index.d.ts
generated
vendored
Normal file
67
assets_old/node_modules/posthtml-render/lib/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
declare namespace render {
|
||||
type Options = {
|
||||
/**
|
||||
* Custom single tags (selfClosing).
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
singleTags: string[] | RegExp[];
|
||||
|
||||
/**
|
||||
* Closing format for single tag.
|
||||
*
|
||||
* Formats:
|
||||
*
|
||||
* tag: `<br></br>`, slash: `<br />`, default: `<br>`
|
||||
*
|
||||
*/
|
||||
closingSingleTag: 'tag' | 'slash';
|
||||
|
||||
/**
|
||||
* If all attributes should be quoted.
|
||||
* Otherwise attributes will be unquoted when allowed.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
quoteAllAttributes: boolean;
|
||||
|
||||
/**
|
||||
* Quote style
|
||||
*
|
||||
* 0 - Smart quotes
|
||||
* <img src="https://example.com/example.png" onload='testFunc("test")'>
|
||||
* 1 - Single quotes
|
||||
* <img src='https://example.com/example.png' onload='testFunc("test")'>
|
||||
* 2 - double quotes
|
||||
* <img src="https://example.com/example.png" onload="testFunc("test")">
|
||||
*
|
||||
* @default 2
|
||||
*/
|
||||
quoteStyle: 0 | 1 | 2
|
||||
};
|
||||
|
||||
// PostHTML Tree
|
||||
type Tree = Node[];
|
||||
type Node = NodeText | NodeTag;
|
||||
type NodeText = string;
|
||||
type NodeTag = {
|
||||
tag: string;
|
||||
attrs?: Attributes;
|
||||
content?: Node[];
|
||||
};
|
||||
|
||||
type Attributes = Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render PostHTML Tree to HTML
|
||||
* @param tree PostHTML Tree
|
||||
* @param options Render options
|
||||
* @returns HTML
|
||||
*/
|
||||
declare function render(
|
||||
tree: render.Tree,
|
||||
options?: Partial<render.Options>
|
||||
): string;
|
||||
|
||||
export = render;
|
222
assets_old/node_modules/posthtml-render/lib/index.js
generated
vendored
Normal file
222
assets_old/node_modules/posthtml-render/lib/index.js
generated
vendored
Normal file
|
@ -0,0 +1,222 @@
|
|||
const SINGLE_TAGS = [
|
||||
'area',
|
||||
'base',
|
||||
'br',
|
||||
'col',
|
||||
'command',
|
||||
'embed',
|
||||
'hr',
|
||||
'img',
|
||||
'input',
|
||||
'keygen',
|
||||
'link',
|
||||
'menuitem',
|
||||
'meta',
|
||||
'param',
|
||||
'source',
|
||||
'track',
|
||||
'wbr'
|
||||
];
|
||||
|
||||
const ATTRIBUTE_QUOTES_REQUIRED = /[\t\n\f\r "'`=<>]/;
|
||||
|
||||
/** Render PostHTML Tree to HTML
|
||||
*
|
||||
* @param {Array|Object} tree PostHTML Tree @param {Object} options Options
|
||||
*
|
||||
* @return {String} HTML
|
||||
*/
|
||||
function render(tree, options) {
|
||||
/** Options
|
||||
*
|
||||
* @type {Object}
|
||||
*
|
||||
* @prop {Array<String|RegExp>} singleTags Custom single tags (selfClosing)
|
||||
* @prop {String} closingSingleTag Closing format for single tag @prop
|
||||
* @prop {Boolean} quoteAllAttributes If all attributes should be quoted.
|
||||
* Otherwise attributes will be unquoted when allowed.
|
||||
* @prop {Boolean} replaceQuote Replaces quotes in attribute values with `"e;`
|
||||
*
|
||||
* Formats:
|
||||
*
|
||||
* ``` tag: `<br></br>` ```, slash: `<br />` ```, ```default: `<br>` ```
|
||||
*/
|
||||
options = options || {};
|
||||
|
||||
const singleTags = options.singleTags ? SINGLE_TAGS.concat(options.singleTags) : SINGLE_TAGS;
|
||||
const singleRegExp = singleTags.filter(tag => {
|
||||
return tag instanceof RegExp;
|
||||
});
|
||||
|
||||
const {closingSingleTag} = options;
|
||||
let {quoteAllAttributes} = options;
|
||||
if (quoteAllAttributes === undefined) {
|
||||
quoteAllAttributes = true;
|
||||
}
|
||||
|
||||
let {replaceQuote} = options;
|
||||
if (replaceQuote === undefined) {
|
||||
replaceQuote = true;
|
||||
}
|
||||
|
||||
let {quoteStyle} = options;
|
||||
if (quoteStyle === undefined) {
|
||||
quoteStyle = 2;
|
||||
}
|
||||
|
||||
return html(tree);
|
||||
|
||||
/** @private */
|
||||
function isSingleTag(tag) {
|
||||
if (singleRegExp.length > 0) {
|
||||
return singleRegExp.some(reg => reg.test(tag));
|
||||
}
|
||||
|
||||
if (!singleTags.includes(tag.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @private */
|
||||
function attrs(object) {
|
||||
let attr = '';
|
||||
|
||||
for (const key in object) {
|
||||
if (typeof object[key] === 'string') {
|
||||
if (quoteAllAttributes || object[key].match(ATTRIBUTE_QUOTES_REQUIRED)) {
|
||||
let attrValue = object[key];
|
||||
|
||||
if (replaceQuote) {
|
||||
attrValue = object[key].replace(/"/g, '"');
|
||||
}
|
||||
|
||||
attr += makeAttr(key, attrValue, quoteStyle);
|
||||
} else if (object[key] === '') {
|
||||
attr += ' ' + key;
|
||||
} else {
|
||||
attr += ' ' + key + '=' + object[key];
|
||||
}
|
||||
} else if (object[key] === true) {
|
||||
attr += ' ' + key;
|
||||
} else if (typeof object[key] === 'number') {
|
||||
attr += makeAttr(key, object[key], quoteStyle);
|
||||
}
|
||||
}
|
||||
|
||||
return attr;
|
||||
}
|
||||
|
||||
/** @private */
|
||||
function traverse(tree, cb) {
|
||||
if (tree !== undefined) {
|
||||
for (let i = 0, {length} = tree; i < length; i++) {
|
||||
traverse(cb(tree[i]), cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @private */
|
||||
function makeAttr(key, attrValue, quoteStyle = 1) {
|
||||
if (quoteStyle === 1) {
|
||||
// Single Quote
|
||||
return ` ${key}='${attrValue}'`;
|
||||
}
|
||||
|
||||
if (quoteStyle === 2) {
|
||||
// Double Quote
|
||||
return ` ${key}="${attrValue}"`;
|
||||
}
|
||||
|
||||
// Smart Quote
|
||||
if (attrValue.includes('"')) {
|
||||
return ` ${key}='${attrValue}'`;
|
||||
}
|
||||
|
||||
return ` ${key}="${attrValue}"`;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTML Stringifier
|
||||
*
|
||||
* @param {Array|Object} tree PostHTML Tree
|
||||
*
|
||||
* @return {String} result HTML
|
||||
*/
|
||||
function html(tree) {
|
||||
let result = '';
|
||||
|
||||
if (!Array.isArray(tree)) {
|
||||
tree = [tree];
|
||||
}
|
||||
|
||||
traverse(tree, node => {
|
||||
// Undefined, null, '', [], NaN
|
||||
if (node === undefined ||
|
||||
node === null ||
|
||||
node === false ||
|
||||
node.length === 0 ||
|
||||
Number.isNaN(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Treat as new root tree if node is an array
|
||||
if (Array.isArray(node)) {
|
||||
result += html(node);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof node === 'string' || typeof node === 'number') {
|
||||
result += node;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip node
|
||||
if (node.tag === false) {
|
||||
result += html(node.content);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const tag = node.tag || 'div';
|
||||
|
||||
result += '<' + tag;
|
||||
|
||||
if (node.attrs) {
|
||||
result += attrs(node.attrs);
|
||||
}
|
||||
|
||||
if (isSingleTag(tag)) {
|
||||
switch (closingSingleTag) {
|
||||
case 'tag':
|
||||
result += '></' + tag + '>';
|
||||
|
||||
break;
|
||||
case 'slash':
|
||||
result += ' />';
|
||||
|
||||
break;
|
||||
default:
|
||||
result += '>';
|
||||
}
|
||||
|
||||
result += html(node.content);
|
||||
} else {
|
||||
result += '>' + html(node.content) + '</' + tag + '>';
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @module posthtml-render
|
||||
*
|
||||
* @version 1.1.5
|
||||
* @license MIT
|
||||
*/
|
||||
module.exports = render;
|
Loading…
Add table
Add a link
Reference in a new issue