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 3.0.11 to 4.0.0

lib/utils/get-theme.js

16

bin/html.js
#!/usr/bin/env node
import fs, { createReadStream } from "node:fs";
import concat from 'concat-stream';
import { createReadStream } from 'node:fs';
import envPaths from "env-paths";
import { parse } from "yaml";
import cliHtml from '../index.js';
const paths = envPaths("cli-html", {
suffix: "",
});
let fileContent = "";
try {
fileContent = fs.readFileSync(`${paths.config}/theme.yml`, "utf8");
} catch {}
const theme = parse(fileContent) || {};
const input = process.argv.length > 2

@@ -13,3 +25,3 @@ ? createReadStream(process.argv[2])

input.pipe(concat((html) => {
process.stdout.write(cliHtml(html.toString()));
process.stdout.write(cliHtml(html.toString(), theme));
}));

4

index.js

@@ -7,3 +7,3 @@ import { parse } from 'parse5';

const htmlToCli = (rawHTML) => {
const htmlToCli = (rawHTML, theme = {}) => {
const document = parse(rawHTML);

@@ -16,3 +16,3 @@

const clobalConfig = getGlobalConfig(document);
const clobalConfig = getGlobalConfig(document, theme);

@@ -19,0 +19,0 @@ return `\n${indentify(' ')(

@@ -92,3 +92,3 @@ import { getAttribute } from '../utils.js';

: topBlock,
value: wrapFunction(value.block.value, tag),
value: wrapFunction(value.block.value, tag, context),
marginBottom:

@@ -95,0 +95,0 @@ value.block.marginBottom && value.block.marginBottom > bottomBlock

@@ -33,3 +33,2 @@ import { blockTag } from './tag-helpers/block-tag.js';

import { figure } from './tags/figure.js';
import { font } from './tags/font.js';
import {

@@ -52,3 +51,5 @@ h1, h2, h3, h4, h5, h6,

em,
i as index,
font,
// eslint-disable-next-line unicorn/prevent-abbreviations
i,
ins,

@@ -156,3 +157,3 @@ italic,

html,
i: index,
i,
img,

@@ -159,0 +160,0 @@ input,

@@ -7,52 +7,27 @@ import ansiEscapes from 'ansi-escapes';

import { getAttribute } from '../utils.js';
import findParrentTag from '../utils/find-parrent-tag.js';
export const a = inlineTag((value, tag) => {
export const a = inlineTag((value, tag, context) => {
const rawHref = getAttribute(tag, 'href', null);
const inHeader = findParrentTag(tag, ['h1', 'h2', 'h3']);
const cleeanUrls = [
// eslint-disable-next-line no-script-url
'javascript:',
'vbscript:',
'vbscript:',
'data:',
const schemes = [
'file://',
'http://',
'https://',
'mailto:',
'ftp://',
'ftps://',
'sftp://',
'ssh://',
'dav://',
'tel:',
'sms:',
'callto:',
'cid:',
'xmpp:',
'skype:',
'sip:',
'sips:',
'mms:',
'rtmp:',
'rtmpt:',
'rtmps:',
'rtmpts:',
'magnet:',
'#',
'git://',
];
const href = !rawHref
|| (cleeanUrls.some((url) => rawHref.startsWith(url)))
? null
: rawHref;
const href = !rawHref || schemes.some((url) => rawHref.startsWith(url)) ? rawHref : null;
const title = getAttribute(tag, 'title', null);
const linkText = context.theme.a(value);
let linkText = (inHeader ? chalk.whiteBright : chalk.blue)(value);
const linkValue = stdout && href ? ansiEscapes.link(linkText, href) : linkText;
linkText = title ? `${linkText} - ${title}` : linkText;
linkText = (inHeader ? chalk.whiteBright : chalk.blue)(linkText);
const linkValue = stdout && href
? ansiEscapes.link(linkText, href)
: linkText;
return linkValue;
});

@@ -31,3 +31,3 @@ import chalk from 'chalk';

export const figcaption = blockTag(
(value) => chalk.bgGreen.bold(` ${value} `),
(value, tag, context) => context.theme.figcaption(` ${value} `),
{

@@ -34,0 +34,0 @@ marginTop: 1,

@@ -9,6 +9,6 @@ import chalk from 'chalk';

compose(
(value) => indentify(chalk.black('│ '))(value),
(value) => (value),
(value, tag) => indentify(context.theme.blockquote('│ '))(value),
(value, tag) => value,
),
{ marginTop: 1, marginBottom: 1 },
)(tag, { ...context, lineWidth: context.lineWidth - 2 });

@@ -9,3 +9,3 @@ import chalk from 'chalk';

export const code = (tag, context) => inlineTag((value, tag) => {
export const code = (tag, context) => inlineTag((value, tag, globalContext) => {
const classAttributes = getAttribute(tag, 'class', '').split(' ');

@@ -34,6 +34,6 @@

})
: chalk.red(content);
: context.theme.code(content);
if (tag.parentNode.nodeName !== 'pre') {
return chalk.bgBlack(codeValue);
return context.theme.inlineCode(codeValue);
}

@@ -47,3 +47,3 @@

const codeContent = codeValueLines.map(
(codeLine, index) => `${chalk.blackBright.dim(
(codeLine, index) => `${context.theme.codeNumbers(
`${index + 1}`.padStart(codeLinesLength, ' '),

@@ -54,3 +54,5 @@ )} ${indentify(

)(
wrapAnsi(codeLine, context.lineWidth - pad.length - 1, { trim: false }),
wrapAnsi(codeLine, context.lineWidth - pad.length - 1, {
trim: false,
}),
)}`,

@@ -57,0 +59,0 @@ );

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

import chalk from 'chalk';
import compose from 'compose-function';

@@ -8,3 +7,3 @@

export const dt = (tag, context) => blockTag(
compose((value) => chalk.bold.blue(value)),
compose((value) => context.theme.dt(value)),
{ marginTop: 1, marginBottom: 1 },

@@ -11,0 +10,0 @@ )(tag, { ...context, lineWidth: context.lineWidth - 1 });

@@ -1,28 +0,44 @@

import chalk from 'chalk';
import { blockTag } from '../tag-helpers/block-tag.js';
export const h1 = blockTag((value) => chalk.red.bold(`# ${value} `), {
marginTop: 2,
marginBottom: 1,
});
export const h2 = blockTag((value) => chalk.blue.bold(`## ${value} `), {
marginTop: 1,
marginBottom: 1,
});
export const h3 = blockTag((value) => chalk.blue.bold(`### ${value} `), {
marginTop: 1,
marginBottom: 1,
});
export const h4 = blockTag((value) => chalk.cyan.bold(`#### ${value}`), {
marginTop: 1,
marginBottom: 1,
});
export const h5 = blockTag((value) => chalk.cyan(`##### ${value}`), {
marginTop: 1,
marginBottom: 1,
});
export const h6 = blockTag((value) => chalk.cyan(`###### ${value}`), {
marginTop: 1,
marginBottom: 1,
});
export const h1 = blockTag(
(value, tag, context) => context.theme.h1(`# ${value} `),
{
marginTop: 2,
marginBottom: 1,
},
);
export const h2 = blockTag(
(value, tag, context) => context.theme.h2(`## ${value} `),
{
marginTop: 1,
marginBottom: 1,
},
);
export const h3 = blockTag(
(value, tag, context) => context.theme.h3(`### ${value} `),
{
marginTop: 1,
marginBottom: 1,
},
);
export const h4 = blockTag(
(value, tag, context) => context.theme.h4(`#### ${value}`),
{
marginTop: 1,
marginBottom: 1,
},
);
export const h5 = blockTag(
(value, tag, context) => context.theme.h5(`##### ${value}`),
{
marginTop: 1,
marginBottom: 1,
},
);
export const h6 = blockTag(
(value, tag, context) => context.theme.h6(`###### ${value}`),
{
marginTop: 1,
marginBottom: 1,
},
);

@@ -1,3 +0,1 @@

import chalk from 'chalk';
import inlineTag from '../tag-helpers/inline-tag.js';

@@ -9,12 +7,12 @@

export const del = inlineTag((value) => chalk.bgRed.black(value));
export const ins = inlineTag((value) => chalk.bgGreen.black(value));
export const italic = inlineTag((value) => chalk.italic(value));
export const strikethrough = inlineTag((value) => chalk.strikethrough(value));
export const underline = inlineTag((value) => chalk.underline(value));
export const bold = inlineTag((value) => chalk.bold(value));
export const samp = inlineTag((value) => chalk.yellowBright(value));
export const kbd = inlineTag((value) => chalk.bgBlack(value));
export const variableTag = inlineTag((value) => chalk.blue.italic(value));
export const mark = inlineTag((value) => chalk.bgYellow.black(value));
export const del = inlineTag((value, tag, context) => context.theme.del(value));
export const ins = inlineTag((value, tag, context) => context.theme.ins(value));
export const italic = inlineTag((value, tag, context) => context.theme.italic(value));
export const strikethrough = inlineTag((value, tag, context) => context.theme.strike(value));
export const underline = inlineTag((value, tag, context) => context.theme.underline(value));
export const bold = inlineTag((value, tag, context) => context.theme.bold(value));
export const samp = inlineTag((value, tag, context) => context.theme.samp(value));
export const kbd = inlineTag((value, tag, context) => context.theme.kbd(value));
export const variableTag = inlineTag((value, tag, context) => context.theme.var(value));
export const mark = inlineTag((value, tag, context) => context.theme.mark(value));

@@ -27,2 +25,3 @@ export const b = bold;

export const em = italic;
// eslint-disable-next-line unicorn/prevent-abbreviations
export const i = italic;

@@ -43,1 +42,2 @@ export const cite = italic;

export const wbr = noStyle;
export const font = noStyle;

@@ -6,4 +6,6 @@ import { camelCase } from 'change-case';

import { getMetaTags } from './get-meta-tags.js';
import { getTheme } from './get-theme.js';
export const getGlobalConfig = (document) => {
export const getGlobalConfig = (document, customTheme) => {
const theme = getTheme(customTheme);
const config = {

@@ -13,2 +15,3 @@ pre: false,

fontAttrs: true,
theme,
};

@@ -25,3 +28,5 @@

metaAttributeName = camelCase(metaAttributeName.replace('cli-render-', ''));
metaAttributeName = camelCase(
metaAttributeName.replace('cli-render-', ''),
);

@@ -28,0 +33,0 @@ config[metaAttributeName] = metaAttributeValue === 'true';

{
"name": "cli-html",
"version": "3.0.11",
"version": "4.0.0",
"description": "Render HTML to Terminal",

@@ -38,2 +38,3 @@ "main": "index.js",

"chalk": "^5.2.0",
"chalk-string": "^2.0.0",
"change-case": "^4.1.2",

@@ -45,2 +46,3 @@ "cli-highlight": "^2.1.11",

"concat-stream": "^2.0.0",
"env-paths": "^3.0.0",
"he": "^1.2.0",

@@ -56,3 +58,4 @@ "inline-style-parser": "^0.1.1",

"term-size": "^3.0.1",
"wrap-ansi": "^8.1.0"
"wrap-ansi": "^8.1.0",
"yaml": "^2.3.1"
},

@@ -59,0 +62,0 @@ "devDependencies": {

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