prismjs-terminal
Advanced tools
Comparing version 1.0.0 to 1.2.0
@@ -16,4 +16,5 @@ export type StyleFn = (s: string) => string; | ||
padding?: number; | ||
lineNumbers?: boolean; | ||
} | ||
export declare const highlight: (code: string, { language, theme, minWidth, maxWidth, padding, }?: PrismJSTerminalOpts) => string; | ||
export declare const highlight: (code: string, { language, theme, minWidth, maxWidth, padding, lineNumbers, }?: PrismJSTerminalOpts) => string; | ||
export declare const highlightFile: (filename: string, opts?: PrismJSTerminalOpts) => Promise<string>; | ||
@@ -20,0 +21,0 @@ export declare const highlightFileSync: (filename: string, opts?: PrismJSTerminalOpts) => string; |
@@ -58,4 +58,7 @@ import chalk from 'chalk'; | ||
}; | ||
const blockStyle = (code, c, { minWidth = 0, maxWidth = process.stdout.columns || 80, padding = 1, }) => { | ||
const lines = code.replace(/\n$/m, '').split('\n'); | ||
/* c8 ignore start */ | ||
const trimTrailingCR = (c) => c.endsWith('\n') ? c.substring(0, c.length - 1) : c; | ||
/* c8 ignore stop */ | ||
const blockStyle = (code, c, { minWidth = 0, maxWidth = process.stdout.columns || 80, padding = 1, lineNumbers = false, }) => { | ||
const lines = trimTrailingCR(code).split('\n'); | ||
const lens = []; | ||
@@ -69,2 +72,3 @@ let max = minWidth; | ||
} | ||
const npad = lineNumbers ? String(lines.length).length : 0; | ||
for (let i = 0; i < lens.length; i++) { | ||
@@ -74,3 +78,6 @@ const len = lens[i]; | ||
const r = pad > 0 ? ' '.repeat(pad) : ''; | ||
const l = ' '.repeat(padding); | ||
const l = ' '.repeat(padding) + | ||
(lineNumbers | ||
? applyStyles(String(i + 1).padStart(npad) + ' ', 'lineNumber', [], c) | ||
: ''); | ||
lines[i] = l + lines[i] + r; | ||
@@ -81,3 +88,3 @@ } | ||
}; | ||
export const highlight = (code, { language = 'tsx', theme = 'xonokai', minWidth, maxWidth, padding, } = {}) => { | ||
export const highlight = (code, { language = 'tsx', theme = 'xonokai', minWidth, maxWidth, padding, lineNumbers, } = {}) => { | ||
const t = typeof theme === 'string' ? themes[theme] : theme; | ||
@@ -88,3 +95,3 @@ if (!t) { | ||
const c = compileTheme(t); | ||
return blockStyle(stringify(Prism.tokenize(code, Prism.languages[language]), c), c, { minWidth, maxWidth, padding }); | ||
return blockStyle(stringify(Prism.tokenize(code, Prism.languages[language]), c), c, { minWidth, maxWidth, padding, lineNumbers }); | ||
}; | ||
@@ -91,0 +98,0 @@ const detectLanguage = (filename) => { |
@@ -6,2 +6,3 @@ // Port of GHColors PrismJS theme | ||
_: chalk.hex('#393A34').bgHex('#fff'), | ||
lineNumber: chalk.dim, | ||
'comment, prolog, doctype, cdata': chalk.hex('#999988').italic, | ||
@@ -8,0 +9,0 @@ namespace: chalk.dim, |
@@ -11,2 +11,3 @@ // Inspired by vim Moria theme | ||
_: chalk.ansi256(252).bgAnsi256(234), | ||
lineNumber: chalk.hex('#8fa5d1'), | ||
punctuation: chalk.hex('#93CDFF'), | ||
@@ -13,0 +14,0 @@ 'prolog, doctype, cdata': chalk.dim.bold, |
@@ -8,2 +8,3 @@ // Port of prism-dark theme | ||
_: chalk.white.bgHex('#231E19'), | ||
lineNumber: chalk.dim, | ||
'comment, prolog, doctype, cdata': chalk.hex('#997F66'), | ||
@@ -10,0 +11,0 @@ 'punctuation, namespace': chalk.dim, |
@@ -7,3 +7,3 @@ // Port of xonokai PrismJS theme | ||
_: chalk.hex('#76d9e6').bgHex('#2a2a2a'), | ||
namespace: chalk.dim, | ||
'namespace, lineNumber': chalk.dim, | ||
'comment, prolog, doctype, cdata': chalk.hex('#6f705e'), | ||
@@ -10,0 +10,0 @@ 'operator, boolean, number': chalk.hex('#a77afe'), |
{ | ||
"name": "prismjs-terminal", | ||
"version": "1.0.0", | ||
"version": "1.2.0", | ||
"description": "PrismaJS syntax highlighting for the terminal", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -29,2 +29,5 @@ # prismjs-terminal | ||
The `lineNumber` style rule will apply to line numbers, if they | ||
are used. | ||
The semantics are similar to CSS, where a nested property will be | ||
@@ -95,2 +98,4 @@ applied to nodes within that nesting stack with a higher | ||
block. Defaults to `1`. | ||
- `lineNumbers` Whether or not to prepend a line number to each | ||
line. Defaults to `false`. | ||
@@ -97,0 +102,0 @@ - `highlight(code: string, opts?: PrismJSTerminalOpts): string` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56293
455
133