nxt-highlightjs 19.0.5 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extras/index.d.ts +152 -5
- package/fesm2022/nxt-highlightjs-extras.mjs +18 -18
- package/fesm2022/nxt-highlightjs-extras.mjs.map +1 -1
- package/fesm2022/nxt-highlightjs-line-numbers.mjs +51 -107
- package/fesm2022/nxt-highlightjs-line-numbers.mjs.map +1 -1
- package/fesm2022/nxt-highlightjs.mjs +324 -49
- package/fesm2022/nxt-highlightjs.mjs.map +1 -1
- package/index.d.ts +196 -3
- package/line-numbers/index.d.ts +21 -5
- package/package.json +7 -7
- package/extras/code-file-location.d.ts +0 -12
- package/extras/code-from-url.d.ts +0 -10
- package/extras/code-loader.d.ts +0 -22
- package/extras/gist.d.ts +0 -20
- package/extras/gist.model.d.ts +0 -95
- package/extras/highlight-extras.module.d.ts +0 -8
- package/extras/public_api.d.ts +0 -5
- package/lib/highlight-auto.d.ts +0 -27
- package/lib/highlight-base.d.ts +0 -27
- package/lib/highlight.d.ts +0 -30
- package/lib/highlight.loader.d.ts +0 -28
- package/lib/highlight.model.d.ts +0 -22
- package/lib/highlight.module.d.ts +0 -8
- package/lib/highlight.service.d.ts +0 -64
- package/lib/loader-errors.d.ts +0 -7
- package/lib/trusted-types.d.ts +0 -1
- package/line-numbers/line-numbers-lib.d.ts +0 -6
- package/line-numbers/line-numbers.d.ts +0 -12
- package/line-numbers/public_api.d.ts +0 -2
- package/public-api.d.ts +0 -7
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, makeEnvironmentProviders, inject, PendingTasks, Injectable, ElementRef, effect, SecurityContext, Directive, input, signal,
|
|
2
|
+
import { InjectionToken, makeEnvironmentProviders, inject, DOCUMENT, PendingTasks, Injectable, ElementRef, effect, SecurityContext, Directive, input, signal, output, booleanAttribute, NgModule } from '@angular/core';
|
|
3
3
|
import { DomSanitizer } from '@angular/platform-browser';
|
|
4
4
|
import { toSignal } from '@angular/core/rxjs-interop';
|
|
5
5
|
import { from } from 'rxjs';
|
|
6
|
-
import { DOCUMENT } from '@angular/common';
|
|
7
6
|
|
|
8
7
|
const NXT_HIGHLIGHT_OPTIONS = new InjectionToken('NXT_HIGHLIGHT_OPTIONS');
|
|
9
8
|
function provideHighlightOptions(options) {
|
|
@@ -24,21 +23,297 @@ var LoaderErrors;
|
|
|
24
23
|
LoaderErrors["NO_FULL_AND_NO_CORE_IMPORTS"] = "Highlight.js library was not imported!";
|
|
25
24
|
})(LoaderErrors || (LoaderErrors = {}));
|
|
26
25
|
|
|
26
|
+
// @ts-nocheck
|
|
27
|
+
const BREAK_LINE_REGEXP = /\r\n|\r|\n/g;
|
|
28
|
+
/**
|
|
29
|
+
* The contents of this file is from highlight.js, with a small modification to HTMLRenderer to make sure spans don't contain line breaks (important to improve performance of line numbers).
|
|
30
|
+
*/
|
|
31
|
+
/** @typedef {{scope?: string, language?: string, children: Node[]} | string} Node */
|
|
32
|
+
/** @typedef {{scope?: string, language?: string, children: Node[]} } DataNode */
|
|
33
|
+
/** @typedef {import('highlight.js').Emitter} Emitter */
|
|
34
|
+
/** */
|
|
35
|
+
/** @returns */
|
|
36
|
+
const newNode = (opts = {}) => {
|
|
37
|
+
/** @type DataNode */
|
|
38
|
+
const result = { children: [] };
|
|
39
|
+
Object.assign(result, opts);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
class TokenTree {
|
|
43
|
+
constructor() {
|
|
44
|
+
/** @type DataNode */
|
|
45
|
+
this.rootNode = newNode();
|
|
46
|
+
this.stack = [this.rootNode];
|
|
47
|
+
}
|
|
48
|
+
get top() {
|
|
49
|
+
return this.stack[this.stack.length - 1];
|
|
50
|
+
}
|
|
51
|
+
get root() {
|
|
52
|
+
return this.rootNode;
|
|
53
|
+
}
|
|
54
|
+
/** @param node */
|
|
55
|
+
add(node) {
|
|
56
|
+
this.top.children.push(node);
|
|
57
|
+
}
|
|
58
|
+
/** @param scope */
|
|
59
|
+
openNode(scope) {
|
|
60
|
+
/** @type Node */
|
|
61
|
+
const node = newNode({ scope });
|
|
62
|
+
this.add(node);
|
|
63
|
+
this.stack.push(node);
|
|
64
|
+
}
|
|
65
|
+
closeNode() {
|
|
66
|
+
if (this.stack.length > 1) {
|
|
67
|
+
return this.stack.pop();
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
closeAllNodes() {
|
|
72
|
+
while (this.closeNode())
|
|
73
|
+
;
|
|
74
|
+
}
|
|
75
|
+
toJSON() {
|
|
76
|
+
return JSON.stringify(this.rootNode, null, 4);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @typedef { import("./html_renderer").Renderer } Renderer
|
|
80
|
+
* @param builder
|
|
81
|
+
*/
|
|
82
|
+
walk(builder) {
|
|
83
|
+
// this does not
|
|
84
|
+
return this.constructor._walk(builder, this.rootNode);
|
|
85
|
+
// this works
|
|
86
|
+
// return TokenTree._walk(builder, this.rootNode);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @param builder
|
|
90
|
+
* @param node
|
|
91
|
+
*/
|
|
92
|
+
static _walk(builder, node) {
|
|
93
|
+
if (typeof node === 'string') {
|
|
94
|
+
builder.addText(node);
|
|
95
|
+
}
|
|
96
|
+
else if (node.children) {
|
|
97
|
+
builder.openNode(node);
|
|
98
|
+
node.children.forEach((child) => this._walk(builder, child));
|
|
99
|
+
builder.closeNode(node);
|
|
100
|
+
}
|
|
101
|
+
return builder;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @param node
|
|
105
|
+
*/
|
|
106
|
+
static _collapse(node) {
|
|
107
|
+
if (typeof node === 'string')
|
|
108
|
+
return;
|
|
109
|
+
if (!node.children)
|
|
110
|
+
return;
|
|
111
|
+
if (node.children.every(el => typeof el === 'string')) {
|
|
112
|
+
// node.text = node.children.join("");
|
|
113
|
+
// delete node.children;
|
|
114
|
+
node.children = [node.children.join('')];
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
node.children.forEach((child) => {
|
|
118
|
+
TokenTree._collapse(child);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
Currently this is all private API, but this is the minimal API necessary
|
|
125
|
+
that an Emitter must implement to fully support the parser.
|
|
126
|
+
|
|
127
|
+
Minimal interface:
|
|
128
|
+
|
|
129
|
+
- addText(text)
|
|
130
|
+
- __addSublanguage(emitter, subLanguageName)
|
|
131
|
+
- startScope(scope)
|
|
132
|
+
- endScope()
|
|
133
|
+
- finalize()
|
|
134
|
+
- toHTML()
|
|
135
|
+
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* @implements {Emitter}
|
|
139
|
+
*/
|
|
140
|
+
class TokenTreeEmitter extends TokenTree {
|
|
141
|
+
/**
|
|
142
|
+
* @param options
|
|
143
|
+
*/
|
|
144
|
+
constructor(options) {
|
|
145
|
+
super();
|
|
146
|
+
this.options = options;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @param text
|
|
150
|
+
*/
|
|
151
|
+
addText(text) {
|
|
152
|
+
if (text === '') {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
this.add(text);
|
|
156
|
+
}
|
|
157
|
+
/** @param scope */
|
|
158
|
+
startScope(scope) {
|
|
159
|
+
this.openNode(scope);
|
|
160
|
+
}
|
|
161
|
+
endScope() {
|
|
162
|
+
this.closeNode();
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @param emitter
|
|
166
|
+
* @param name
|
|
167
|
+
*/
|
|
168
|
+
__addSublanguage(emitter, name) {
|
|
169
|
+
/** @type DataNode */
|
|
170
|
+
const node = emitter.root;
|
|
171
|
+
if (name)
|
|
172
|
+
node.scope = `language:${name}`;
|
|
173
|
+
this.add(node);
|
|
174
|
+
}
|
|
175
|
+
toHTML() {
|
|
176
|
+
const renderer = new HTMLRenderer(this, this.options);
|
|
177
|
+
return renderer.value();
|
|
178
|
+
}
|
|
179
|
+
finalize() {
|
|
180
|
+
this.closeAllNodes();
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* @typedef {object} Renderer
|
|
186
|
+
* @property {(text: string) => void} addText
|
|
187
|
+
* @property {(node: Node) => void} openNode
|
|
188
|
+
* @property {(node: Node) => void} closeNode
|
|
189
|
+
* @property {() => string} value
|
|
190
|
+
*/
|
|
191
|
+
/** @typedef {{scope?: string, language?: string, sublanguage?: boolean}} Node */
|
|
192
|
+
/** @typedef {{walk: (r: Renderer) => void}} Tree */
|
|
193
|
+
/** */
|
|
194
|
+
const SPAN_CLOSE = '</span>';
|
|
195
|
+
/**
|
|
196
|
+
* Determines if a node needs to be wrapped in <span>
|
|
197
|
+
*
|
|
198
|
+
* @param node */
|
|
199
|
+
const emitsWrappingTags = (node) =>
|
|
200
|
+
// rarely we can have a sublanguage where language is undefined
|
|
201
|
+
// TODO: track down why
|
|
202
|
+
!!node.scope;
|
|
203
|
+
/**
|
|
204
|
+
*
|
|
205
|
+
* @param name
|
|
206
|
+
* @param options
|
|
207
|
+
*/
|
|
208
|
+
const scopeToCSSClass = (name, { prefix }) => {
|
|
209
|
+
// sub-language
|
|
210
|
+
if (name.startsWith('language:')) {
|
|
211
|
+
return name.replace('language:', 'language-');
|
|
212
|
+
}
|
|
213
|
+
// tiered scope: comment.line
|
|
214
|
+
if (name.includes('.')) {
|
|
215
|
+
const pieces = name.split('.');
|
|
216
|
+
return [
|
|
217
|
+
`${prefix}${pieces.shift()}`,
|
|
218
|
+
...(pieces.map((x, i) => `${x}${'_'.repeat(i + 1)}`))
|
|
219
|
+
].join(' ');
|
|
220
|
+
}
|
|
221
|
+
// simple scope
|
|
222
|
+
return `${prefix}${name}`;
|
|
223
|
+
};
|
|
224
|
+
/** @type {Renderer} */
|
|
225
|
+
class HTMLRenderer {
|
|
226
|
+
/**
|
|
227
|
+
* Creates a new HTMLRenderer
|
|
228
|
+
*
|
|
229
|
+
* @param parseTree - the parse tree (must support `walk` API)
|
|
230
|
+
* @param options
|
|
231
|
+
*/
|
|
232
|
+
constructor(parseTree, options) {
|
|
233
|
+
this.buffer = '';
|
|
234
|
+
this.classPrefix = options.classPrefix;
|
|
235
|
+
this.openStack = [];
|
|
236
|
+
parseTree.walk(this);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Adds texts to the output stream
|
|
240
|
+
*
|
|
241
|
+
* @param text */
|
|
242
|
+
addText(text) {
|
|
243
|
+
const lines = text.split(BREAK_LINE_REGEXP).map(escapeHTML);
|
|
244
|
+
const lineBreak = new Array(this.openStack.length).fill(SPAN_CLOSE).join('') + '\n' + this.openStack.join('');
|
|
245
|
+
this.buffer += lines.join(lineBreak);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Adds a node open to the output stream (if needed)
|
|
249
|
+
*
|
|
250
|
+
* @param node */
|
|
251
|
+
openNode(node) {
|
|
252
|
+
if (!emitsWrappingTags(node))
|
|
253
|
+
return;
|
|
254
|
+
const className = scopeToCSSClass(node.scope, { prefix: this.classPrefix });
|
|
255
|
+
this.span(className);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Adds a node close to the output stream (if needed)
|
|
259
|
+
*
|
|
260
|
+
* @param node */
|
|
261
|
+
closeNode(node) {
|
|
262
|
+
if (!emitsWrappingTags(node))
|
|
263
|
+
return;
|
|
264
|
+
this.buffer += SPAN_CLOSE;
|
|
265
|
+
this.openStack.pop();
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* returns the accumulated buffer
|
|
269
|
+
*/
|
|
270
|
+
value() {
|
|
271
|
+
return this.buffer;
|
|
272
|
+
}
|
|
273
|
+
// helpers
|
|
274
|
+
/**
|
|
275
|
+
* Builds a span element
|
|
276
|
+
*
|
|
277
|
+
* @param className */
|
|
278
|
+
span(className) {
|
|
279
|
+
const span = `<span class="${className}">`;
|
|
280
|
+
this.buffer += span;
|
|
281
|
+
this.openStack.push(span);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* @param value
|
|
286
|
+
* @returns
|
|
287
|
+
*/
|
|
288
|
+
function escapeHTML(value) {
|
|
289
|
+
return value
|
|
290
|
+
.replace(/&/g, '&')
|
|
291
|
+
.replace(/</g, '<')
|
|
292
|
+
.replace(/>/g, '>')
|
|
293
|
+
.replace(/"/g, '"')
|
|
294
|
+
.replace(/'/g, ''');
|
|
295
|
+
}
|
|
296
|
+
|
|
27
297
|
class HighlightLoader {
|
|
28
298
|
constructor() {
|
|
29
299
|
this.document = inject(DOCUMENT);
|
|
30
300
|
this.options = inject(NXT_HIGHLIGHT_OPTIONS, { optional: true });
|
|
31
301
|
this.pendingTasks = inject(PendingTasks);
|
|
32
|
-
this.
|
|
302
|
+
this._t = this.pendingTasks.add();
|
|
303
|
+
this.ready = this.loadLibrary()
|
|
33
304
|
.then(async (hljs) => {
|
|
34
305
|
if (this.options?.lineNumbersLoader) {
|
|
35
306
|
const plugin = await this.options.lineNumbersLoader();
|
|
36
307
|
hljs.lineNumbersBlock = plugin.activateLineNumbers(this.document);
|
|
37
308
|
}
|
|
309
|
+
hljs.configure({
|
|
310
|
+
__emitter: TokenTreeEmitter
|
|
311
|
+
});
|
|
38
312
|
if (this.options?.highlightOptions)
|
|
39
313
|
hljs.configure(this.options.highlightOptions);
|
|
40
314
|
return hljs;
|
|
41
|
-
})
|
|
315
|
+
})
|
|
316
|
+
.finally(this._t);
|
|
42
317
|
if (this.options?.themePath) {
|
|
43
318
|
this.loadTheme(this.options.themePath);
|
|
44
319
|
}
|
|
@@ -99,10 +374,10 @@ class HighlightLoader {
|
|
|
99
374
|
this.themeLinkElement.media = 'screen,print';
|
|
100
375
|
this.document.head.appendChild(this.themeLinkElement);
|
|
101
376
|
}
|
|
102
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
103
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
377
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
378
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightLoader, providedIn: 'root' }); }
|
|
104
379
|
}
|
|
105
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
380
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightLoader, decorators: [{
|
|
106
381
|
type: Injectable,
|
|
107
382
|
args: [{
|
|
108
383
|
providedIn: 'root'
|
|
@@ -204,10 +479,10 @@ class HighlightJS {
|
|
|
204
479
|
hljs.lineNumbersBlock(el, options);
|
|
205
480
|
}
|
|
206
481
|
}
|
|
207
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
208
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
482
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightJS, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
483
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightJS, providedIn: 'root' }); }
|
|
209
484
|
}
|
|
210
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
485
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightJS, decorators: [{
|
|
211
486
|
type: Injectable,
|
|
212
487
|
args: [{
|
|
213
488
|
providedIn: 'root'
|
|
@@ -273,35 +548,30 @@ class HighlightBase {
|
|
|
273
548
|
setInnerHTML(content) {
|
|
274
549
|
this.nativeElement.innerHTML = trustedHTMLFromStringBypass(this.sanitizer.sanitize(SecurityContext.HTML, content || null) || '');
|
|
275
550
|
}
|
|
276
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
277
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
551
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightBase, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
552
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.0.5", type: HighlightBase, isStandalone: true, ngImport: i0 }); }
|
|
278
553
|
}
|
|
279
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
554
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightBase, decorators: [{
|
|
280
555
|
type: Directive
|
|
281
556
|
}], ctorParameters: () => [] });
|
|
282
557
|
|
|
283
|
-
class
|
|
558
|
+
class HighlightAutoDirective extends HighlightBase {
|
|
284
559
|
constructor() {
|
|
285
560
|
super(...arguments);
|
|
286
561
|
/**
|
|
287
562
|
* Code to highlight
|
|
288
563
|
*/
|
|
289
|
-
this.code = input(undefined, { alias: '
|
|
564
|
+
this.code = input(undefined, { alias: 'nxtHighlightAuto' });
|
|
290
565
|
/**
|
|
291
566
|
* Highlighted result
|
|
292
567
|
*/
|
|
293
568
|
this.highlightResult = signal(undefined);
|
|
294
569
|
/**
|
|
295
|
-
*
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* An optional flag, when set to true it forces highlighting to finish even in case of detecting
|
|
300
|
-
* illegal syntax for the language instead of throwing an exception
|
|
570
|
+
* An optional array of language names and aliases restricting detection to only those languages
|
|
571
|
+
*
|
|
572
|
+
* The subset can also be set with configure, but the local parameter overrides the option if set.
|
|
301
573
|
*/
|
|
302
|
-
this.
|
|
303
|
-
transform: booleanAttribute
|
|
304
|
-
});
|
|
574
|
+
this.languages = input();
|
|
305
575
|
/**
|
|
306
576
|
* Stream that emits when code string is highlighted
|
|
307
577
|
*/
|
|
@@ -309,42 +579,44 @@ class HighlightDirective extends HighlightBase {
|
|
|
309
579
|
}
|
|
310
580
|
highlightElement(code) {
|
|
311
581
|
const hljs = this.hljs.hljs();
|
|
312
|
-
return hljs?.
|
|
313
|
-
language: this.language(),
|
|
314
|
-
ignoreIllegals: this.ignoreIllegals()
|
|
315
|
-
});
|
|
582
|
+
return hljs?.highlightAuto(code, this.languages());
|
|
316
583
|
}
|
|
317
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
318
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "
|
|
584
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightAutoDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
585
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.0.5", type: HighlightAutoDirective, isStandalone: true, selector: "[nxtHighlightAuto]", inputs: { code: { classPropertyName: "code", publicName: "nxtHighlightAuto", isSignal: true, isRequired: false, transformFunction: null }, languages: { classPropertyName: "languages", publicName: "languages", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { highlighted: "highlighted" }, host: { properties: { "class.hljs": "true" } }, providers: [{ provide: HighlightBase, useExisting: HighlightAutoDirective }], usesInheritance: true, ngImport: i0 }); }
|
|
319
586
|
}
|
|
320
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
587
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightAutoDirective, decorators: [{
|
|
321
588
|
type: Directive,
|
|
322
589
|
args: [{
|
|
323
|
-
selector: '[
|
|
324
|
-
providers: [{ provide: HighlightBase, useExisting:
|
|
590
|
+
selector: '[nxtHighlightAuto]',
|
|
591
|
+
providers: [{ provide: HighlightBase, useExisting: HighlightAutoDirective }],
|
|
325
592
|
host: {
|
|
326
593
|
'[class.hljs]': 'true'
|
|
327
594
|
}
|
|
328
595
|
}]
|
|
329
596
|
}] });
|
|
330
597
|
|
|
331
|
-
class
|
|
598
|
+
class HighlightDirective extends HighlightBase {
|
|
332
599
|
constructor() {
|
|
333
600
|
super(...arguments);
|
|
334
601
|
/**
|
|
335
602
|
* Code to highlight
|
|
336
603
|
*/
|
|
337
|
-
this.code = input(undefined, { alias: '
|
|
604
|
+
this.code = input(undefined, { alias: 'nxtHighlight' });
|
|
338
605
|
/**
|
|
339
606
|
* Highlighted result
|
|
340
607
|
*/
|
|
341
608
|
this.highlightResult = signal(undefined);
|
|
342
609
|
/**
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
* The subset can also be set with configure, but the local parameter overrides the option if set.
|
|
610
|
+
* The language name highlight only one language
|
|
346
611
|
*/
|
|
347
|
-
this.
|
|
612
|
+
this.language = input.required();
|
|
613
|
+
/**
|
|
614
|
+
* An optional flag, when set to true it forces highlighting to finish even in case of detecting
|
|
615
|
+
* illegal syntax for the language instead of throwing an exception
|
|
616
|
+
*/
|
|
617
|
+
this.ignoreIllegals = input(undefined, {
|
|
618
|
+
transform: booleanAttribute
|
|
619
|
+
});
|
|
348
620
|
/**
|
|
349
621
|
* Stream that emits when code string is highlighted
|
|
350
622
|
*/
|
|
@@ -352,16 +624,19 @@ class HighlightAutoDirective extends HighlightBase {
|
|
|
352
624
|
}
|
|
353
625
|
highlightElement(code) {
|
|
354
626
|
const hljs = this.hljs.hljs();
|
|
355
|
-
return hljs?.
|
|
627
|
+
return hljs?.highlight(code, {
|
|
628
|
+
language: this.language(),
|
|
629
|
+
ignoreIllegals: this.ignoreIllegals()
|
|
630
|
+
});
|
|
356
631
|
}
|
|
357
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
358
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "
|
|
632
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
633
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "20.0.5", type: HighlightDirective, isStandalone: true, selector: "[nxtHighlight]", inputs: { code: { classPropertyName: "code", publicName: "nxtHighlight", isSignal: true, isRequired: false, transformFunction: null }, language: { classPropertyName: "language", publicName: "language", isSignal: true, isRequired: true, transformFunction: null }, ignoreIllegals: { classPropertyName: "ignoreIllegals", publicName: "ignoreIllegals", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { highlighted: "highlighted" }, host: { properties: { "class.hljs": "true" } }, providers: [{ provide: HighlightBase, useExisting: HighlightDirective }], usesInheritance: true, ngImport: i0 }); }
|
|
359
634
|
}
|
|
360
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
635
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightDirective, decorators: [{
|
|
361
636
|
type: Directive,
|
|
362
637
|
args: [{
|
|
363
|
-
selector: '[
|
|
364
|
-
providers: [{ provide: HighlightBase, useExisting:
|
|
638
|
+
selector: '[nxtHighlight]',
|
|
639
|
+
providers: [{ provide: HighlightBase, useExisting: HighlightDirective }],
|
|
365
640
|
host: {
|
|
366
641
|
'[class.hljs]': 'true'
|
|
367
642
|
}
|
|
@@ -369,11 +644,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.3", ngImpor
|
|
|
369
644
|
}] });
|
|
370
645
|
|
|
371
646
|
class HighlightModule {
|
|
372
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
373
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
374
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
647
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
648
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.5", ngImport: i0, type: HighlightModule, imports: [HighlightDirective, HighlightAutoDirective], exports: [HighlightDirective, HighlightAutoDirective] }); }
|
|
649
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightModule }); }
|
|
375
650
|
}
|
|
376
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
651
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.5", ngImport: i0, type: HighlightModule, decorators: [{
|
|
377
652
|
type: NgModule,
|
|
378
653
|
args: [{
|
|
379
654
|
imports: [HighlightDirective, HighlightAutoDirective],
|