Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cli-html

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-html - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

examples/lists.html

3

index.js

@@ -13,4 +13,5 @@ const parse5 = require('parse5');

// console.dir(
// filterAst(document.childNodes[0].childNodes[1]).childNodes,
// filterAst(document.childNodes[0].childNodes[1].childNodes[0]),
// { depth: null },

@@ -17,0 +18,0 @@ // );

/* eslint-disable unicorn/consistent-function-scoping */
const tags = require('../tags');
const { getAttribute } = require('../utils');

@@ -14,3 +15,3 @@ const { concatTwoTags: concatTwoBlockTags } = require('../concat');

let liItemNumber = 1;
let liItemNumber = parseInt(getAttribute(tag, 'start', '1'), 10);
const value = tag.childNodes.reduce((accumulator, node) => {

@@ -75,3 +76,3 @@ if (!tags[node.nodeName]) {

: '';
preBlock = !context.pre
preBlock = (!context || !context.pre)
? `${preBlock}\n`

@@ -83,3 +84,3 @@ : `${preBlock}`;

: '';
postBlock = !context.pre
postBlock = (!context || !context.pre)
? `\n${postBlock}`

@@ -86,0 +87,0 @@ : `${postBlock}`;

@@ -10,8 +10,8 @@ const ansiStyles = require('ansi-colors');

const hr = () => ({
pre: '',
pre: '\n',
value: ansiStyles.gray(hrLine('─')),
post: '',
type: 'inline',
post: '\n',
type: 'block',
});
module.exports.hr = hr;

@@ -8,30 +8,28 @@ const supportsHyperlinks = require('supports-hyperlinks');

const {
getAttribute,
} = require('../utils');
const link = inlineTag(
(value, tag) => {
const hrefAttribute = tag.attrs
.find((attribute_) => attribute_.name === 'href');
const rawHref = getAttribute(tag, 'href', null);
const href = (
hrefAttribute
&& hrefAttribute.value
rawHref
// eslint-disable-next-line no-script-url
&& !hrefAttribute.value.startsWith('javascript:')
&& !rawHref.startsWith('javascript:')
)
? hrefAttribute.value
? rawHref
: null;
const titleAttribute = tag.attrs
.find((attribute_) => attribute_.name === 'title');
const title = getAttribute(tag, 'title', null);
const title = (
titleAttribute
&& titleAttribute.value
)
? titleAttribute.value
: false;
let linkText = ansiStyles.blue(value);
const linkText = ansiStyles.blue.underline(value + (title !== false
? ` - ${title}`
: ''));
linkText = title
? `${linkText} - ${title}`
: linkText;
linkText = ansiStyles.underline.blue(linkText);
const linkValue = (supportsHyperlinks.stdout && href)

@@ -42,3 +40,2 @@ // eslint-disable-next-line security/detect-non-literal-fs-filename

return linkValue;

@@ -45,0 +42,0 @@ },

const ansiStyles = require('ansi-colors');
const compose = require('compose-function');
const blockTag = require('../tag-helpers/blockTag');
const { indentify } = require('../utils');
const {
indentify,
getAttribute,
} = require('../utils');
const {
getListSymbol,
getListType,
getListItemNumber,
} = require('../utils/list');
const ol = (tag, context) => {

@@ -12,5 +21,5 @@ const newContext = {

compact: true,
listType: getAttribute(tag, 'type', undefined),
};
// console.log('^^^%%--', newContext);

@@ -20,3 +29,6 @@ return blockTag(

(value) => indentify(' ')(value),
), { pre: context.compact ? '' : '\n', post: context.compact ? '' : '\n' },
), {
pre: context.compact ? '' : '\n',
post: context.compact ? '' : '\n',
},
)(tag, newContext);

@@ -31,5 +43,5 @@ };

compact: true,
listType: getListType(getAttribute(tag, 'type', null), context.listType),
};
// console.log('^^^%%--', newContext);

@@ -39,3 +51,6 @@ return blockTag(

(value) => indentify(' ')(value),
), { pre: context.compact ? '' : '\n', post: context.compact ? '' : '\n' },
), {
pre: context.compact ? '' : '\n',
post: context.compact ? '' : '\n',
},
)(tag, newContext);

@@ -48,9 +63,16 @@ };

compose(
(value) => `${ansiStyles.blue(`${context.liItemNumber}.`)} ${indentify(' ')(value)}`.replace(/ {3}/, ''),
(value) => `${
ansiStyles.blue(`${getListItemNumber(context.liItemNumber, context.listType)}.`)
} ${
indentify(' ')(value)
}`.replace(/ {3}/, ''),
),
)(tag, { ...context, lineWidth: context.lineWidth - 3 });
}
return blockTag(
compose(
(value) => `${indentify(' ')(value)}`.replace(/ {2}/, ansiStyles.red('• ')),
(value) => `${
indentify(' ')(value)
}`.replace(/ {2}/, `${ansiStyles.red(getListSymbol(context.listType))} `),
),

@@ -57,0 +79,0 @@ )(tag, { ...context, lineWidth: context.lineWidth - 2 });

@@ -0,1 +1,2 @@

const Table = require('cli-table3');

@@ -7,5 +8,12 @@ const compose = require('compose-function');

const ansiStyles = require('ansi-colors');
const { filterAst } = require('../utils');
const ansiAlign = require('ansi-align');
const longestLine = require('longest-line');
const { concatTwoTags } = require('../concat');
const { indentify } = require('../utils');
const {
indentify,
getAttribute,
filterAst,
} = require('../utils');

@@ -20,13 +28,19 @@

const td = blockTag();
const th = blockTag((value) => ansiStyles.bold.red(value));
const caption = blockTag();
const captions = blockTag(
compose(
(value) => ansiStyles.bold.blue(value),
(value) => indentify((' '))(value),
),
);
const captions = (tag, context) => {
void 0;
return blockTag(
compose(
(value) => ansiStyles.bold.blue(value),
(value) => indentify((''))(value),
),
)(tag, context);
};
const trVals = (tr) => {
const theadTds = !tr
const theadTds = (!tr || !tr.childNodes)
? null

@@ -37,7 +51,23 @@ : tr.childNodes.filter((tag) => ['td', 'th'].includes(tag.nodeName));

? null
: theadTds.map((tag, context) => td(tag, context)).map((value) => (
(value && value.value)
? value.value
: ''));
: theadTds.map(
(tag, context) => {
const det = tag.nodeName === 'td'
? td(tag, context)
: th(tag, context);
const hAlign = getAttribute(tag, 'align', 'right');
const vAlign = getAttribute(tag, 'valign', 'top');
const colSpan = parseInt(getAttribute(tag, 'colspan', '1'), 10);
return {
content: det.value,
hAlign,
vAlign,
colSpan,
};
},
);
return theadTdsValue;

@@ -65,37 +95,65 @@ };

const captionsValue = captions(captionTag);
const captionsValue = captions(captionTag, context);
const tableArray = [];
const thead = tag.childNodes.find((child) => child.nodeName === 'thead');
const theadTr = !thead
const theadTr = (!thead || !thead.childNodes)
? null
: thead.childNodes.filter((child) => child.nodeName === 'tr');
: thead.childNodes.find((child) => child.nodeName === 'tr');
const theadTdsValue = theadTr
? (theadTr.map(trVals))
: [];
const theadsValue = !theadTr
? null
: trVals(theadTr);
const table = new Table({
head: theadTdsValue[0],
});
if (theadsValue && theadsValue[0]) {
tableArray.push(theadsValue);
}
const trs = tag.childNodes.filter((child) => ['tbody'].includes(child.nodeName));
trs.map(tbodyVals).map((value) => table.push(...value));
trs.map(tbodyVals).map((value) => tableArray.push(...value));
const tfoot = tag.childNodes.find((child) => child.nodeName === 'tfoot');
const tfootTr = !tfoot
const tfootTr = (!tfoot || !tfoot.childNodes)
? null
: tfoot.childNodes.find((child) => child.nodeName === 'tr');
const tfootdsValue = trVals(tfootTr);
const tfootdsValue = !tfootTr
? null
: trVals(tfootTr);
if (tfootdsValue) {
table.push(tfootdsValue);
if (tfootdsValue && tfootdsValue[0]) {
tableArray.push(tfootdsValue);
}
const table = new Table({
});
// console.log('--))==', tableArray);
table.push(...tableArray);
const tableString = table.toString();
const longestLineInTable = longestLine(tableString);
if (captionsValue && captionsValue.value) {
captionsValue.value = `${
captionsValue.value
}\n${
' '.repeat(longestLineInTable)
}`;
captionsValue.value = ansiAlign(captionsValue.value);
}
return {
pre: '\n',
value: concatTwoTags(captionsValue, { value: table.toString() }).value,
value: concatTwoTags(captionsValue, { value: tableString }).value,
post: '\n',

@@ -102,0 +160,0 @@ type: 'block',

@@ -34,1 +34,17 @@ const filterAst = (ast) => {

module.exports.indentify = indentify;
const getAttribute = (tag, attributeName, defaultValue) => {
if (!tag || !tag.attrs || !tag.attrs[0]) {
return defaultValue;
}
const attribute = tag.attrs.find((attribute) => attribute.name === attributeName);
if (!attribute) {
return defaultValue;
}
return attribute.value;
};
module.exports.getAttribute = getAttribute;
{
"name": "cli-html",
"version": "1.1.0",
"version": "1.2.0",
"description": "There will be cli module who render HTML to Terminal",

@@ -44,5 +44,8 @@ "main": "index.js",

"languages-aliases": "^2.0.5",
"longest-line": "0.0.3",
"normalize-html-whitespace": "^1.0.0",
"number-to-alphabet": "^1.0.0",
"parse5": "^5.1.0",
"parse5-htmlparser2-tree-adapter": "^5.1.1",
"romanize": "^1.1.1",
"supports-hyperlinks": "^2.0.0",

@@ -49,0 +52,0 @@ "wrap-ansi": "^6.2.0"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc