@covalent/flavored-markdown 6.4.0 → 6.4.2

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.
@@ -0,0 +1,838 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Component, Input, ViewChild, EventEmitter, HostBinding, Output, Directive, ChangeDetectionStrategy, NgModule } from '@angular/core';
3
+ import { MatCheckbox, MatCheckboxModule } from '@angular/material/checkbox';
4
+ import * as i4 from '@angular/material/sort';
5
+ import { MatSort, MatSortModule } from '@angular/material/sort';
6
+ import * as i3$1 from '@angular/material/table';
7
+ import { MatTableDataSource, MatTableModule } from '@angular/material/table';
8
+ import { Subject } from 'rxjs';
9
+ import { takeUntil } from 'rxjs/operators';
10
+ import * as i1 from '@angular/common';
11
+ import { CommonModule } from '@angular/common';
12
+ import * as i2 from '@angular/material/list';
13
+ import { MatListModule } from '@angular/material/list';
14
+ import * as i3 from '@angular/material/divider';
15
+ import { TdHighlightComponent, CovalentHighlightModule } from '@covalent/highlight';
16
+ import * as i1$1 from '@covalent/markdown';
17
+ import { scrollToAnchor, TdMarkdownComponent, CovalentMarkdownModule } from '@covalent/markdown';
18
+ import * as i5 from '@angular/material/button';
19
+ import { MatButtonModule } from '@angular/material/button';
20
+ import * as i3$2 from '@angular/material/progress-bar';
21
+ import { MatProgressBarModule } from '@angular/material/progress-bar';
22
+ import { __awaiter } from 'tslib';
23
+
24
+ function TdFlavoredListComponent_ng_template_1_p_3_Template(rf, ctx) {
25
+ if (rf & 1) {
26
+ i0.ɵɵelementStart(0, "p", 4);
27
+ i0.ɵɵtext(1);
28
+ i0.ɵɵelementEnd();
29
+ }
30
+ if (rf & 2) {
31
+ const subline_r5 = ctx.$implicit;
32
+ i0.ɵɵadvance(1);
33
+ i0.ɵɵtextInterpolate1(" ", subline_r5, " ");
34
+ }
35
+ }
36
+ function TdFlavoredListComponent_ng_template_1_mat_divider_4_Template(rf, ctx) {
37
+ if (rf & 1) {
38
+ i0.ɵɵelement(0, "mat-divider", 4);
39
+ }
40
+ }
41
+ function TdFlavoredListComponent_ng_template_1_Template(rf, ctx) {
42
+ if (rf & 1) {
43
+ i0.ɵɵelementStart(0, "mat-list-item")(1, "h4", 1);
44
+ i0.ɵɵtext(2);
45
+ i0.ɵɵelementEnd();
46
+ i0.ɵɵtemplate(3, TdFlavoredListComponent_ng_template_1_p_3_Template, 2, 1, "p", 2);
47
+ i0.ɵɵtemplate(4, TdFlavoredListComponent_ng_template_1_mat_divider_4_Template, 1, 0, "mat-divider", 3);
48
+ i0.ɵɵelementEnd();
49
+ }
50
+ if (rf & 2) {
51
+ const line_r1 = ctx.$implicit;
52
+ const last_r2 = ctx.last;
53
+ i0.ɵɵadvance(2);
54
+ i0.ɵɵtextInterpolate1(" ", line_r1.line, " ");
55
+ i0.ɵɵadvance(1);
56
+ i0.ɵɵproperty("ngForOf", line_r1.sublines);
57
+ i0.ɵɵadvance(1);
58
+ i0.ɵɵproperty("ngIf", !last_r2);
59
+ }
60
+ }
61
+ class TdFlavoredListComponent {
62
+ constructor() {
63
+ this.dense = false;
64
+ }
65
+ }
66
+ TdFlavoredListComponent.ɵfac = function TdFlavoredListComponent_Factory(t) { return new (t || TdFlavoredListComponent)(); };
67
+ TdFlavoredListComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredListComponent, selectors: [["td-cfm-list"]], inputs: { lines: "lines", dense: "dense" }, decls: 2, vars: 2, consts: [["ngFor", "", 3, "ngForOf"], ["matListItemTitle", ""], ["matListItemLine", "", 4, "ngFor", "ngForOf"], ["matListItemLine", "", 4, "ngIf"], ["matListItemLine", ""]], template: function TdFlavoredListComponent_Template(rf, ctx) {
68
+ if (rf & 1) {
69
+ i0.ɵɵelementStart(0, "mat-list");
70
+ i0.ɵɵtemplate(1, TdFlavoredListComponent_ng_template_1_Template, 5, 3, "ng-template", 0);
71
+ i0.ɵɵelementEnd();
72
+ }
73
+ if (rf & 2) {
74
+ i0.ɵɵattribute("dense", ctx.dense ? true : null);
75
+ i0.ɵɵadvance(1);
76
+ i0.ɵɵproperty("ngForOf", ctx.lines);
77
+ }
78
+ }, dependencies: [i1.NgForOf, i1.NgIf, i2.MatList, i2.MatListItem, i3.MatDivider, i2.MatListItemLine, i2.MatListItemTitle] });
79
+ (function () {
80
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredListComponent, [{
81
+ type: Component,
82
+ args: [{ selector: 'td-cfm-list', template: "<mat-list [attr.dense]=\"dense ? true : null\">\n <ng-template let-line let-last=\"last\" ngFor [ngForOf]=\"lines\">\n <mat-list-item>\n <h4 matListItemTitle>\n {{ line.line }}\n </h4>\n <p *ngFor=\"let subline of line.sublines\" matListItemLine>\n {{ subline }}\n </p>\n <mat-divider *ngIf=\"!last\" matListItemLine></mat-divider>\n </mat-list-item>\n </ng-template>\n</mat-list>\n" }]
83
+ }], null, { lines: [{
84
+ type: Input
85
+ }], dense: [{
86
+ type: Input
87
+ }] });
88
+ })();
89
+
90
+ function TdFlavoredMarkdownTableComponent_ng_template_1_mat_header_cell_1_Template(rf, ctx) {
91
+ if (rf & 1) {
92
+ i0.ɵɵelementStart(0, "mat-header-cell", 7);
93
+ i0.ɵɵtext(1);
94
+ i0.ɵɵelementEnd();
95
+ }
96
+ if (rf & 2) {
97
+ const column_r3 = i0.ɵɵnextContext().$implicit;
98
+ i0.ɵɵadvance(1);
99
+ i0.ɵɵtextInterpolate(column_r3.label);
100
+ }
101
+ }
102
+ function TdFlavoredMarkdownTableComponent_ng_template_1_mat_cell_2_Template(rf, ctx) {
103
+ if (rf & 1) {
104
+ i0.ɵɵelementStart(0, "mat-cell")(1, "td-markdown");
105
+ i0.ɵɵtext(2);
106
+ i0.ɵɵelementEnd()();
107
+ }
108
+ if (rf & 2) {
109
+ const row_r7 = ctx.$implicit;
110
+ const column_r3 = i0.ɵɵnextContext().$implicit;
111
+ i0.ɵɵadvance(2);
112
+ i0.ɵɵtextInterpolate(row_r7[column_r3.name]);
113
+ }
114
+ }
115
+ function TdFlavoredMarkdownTableComponent_ng_template_1_Template(rf, ctx) {
116
+ if (rf & 1) {
117
+ i0.ɵɵelementContainerStart(0, 4);
118
+ i0.ɵɵtemplate(1, TdFlavoredMarkdownTableComponent_ng_template_1_mat_header_cell_1_Template, 2, 1, "mat-header-cell", 5);
119
+ i0.ɵɵtemplate(2, TdFlavoredMarkdownTableComponent_ng_template_1_mat_cell_2_Template, 3, 1, "mat-cell", 6);
120
+ i0.ɵɵelementContainerEnd();
121
+ }
122
+ if (rf & 2) {
123
+ const column_r3 = ctx.$implicit;
124
+ i0.ɵɵproperty("matColumnDef", column_r3.name);
125
+ }
126
+ }
127
+ function TdFlavoredMarkdownTableComponent_mat_header_row_2_Template(rf, ctx) {
128
+ if (rf & 1) {
129
+ i0.ɵɵelement(0, "mat-header-row");
130
+ }
131
+ }
132
+ function TdFlavoredMarkdownTableComponent_mat_row_3_Template(rf, ctx) {
133
+ if (rf & 1) {
134
+ i0.ɵɵelement(0, "mat-row");
135
+ }
136
+ }
137
+ const _c0 = ["*"];
138
+ class TdFlavoredMarkdownTableComponent {
139
+ constructor() {
140
+ this.columnDefs = [];
141
+ }
142
+ ngOnInit() {
143
+ this.displayedColumns = this.columnDefs.map((c) => c.name);
144
+ this.dataSource = new MatTableDataSource(this.data);
145
+ }
146
+ ngAfterViewInit() {
147
+ this.dataSource.sort = this.sort;
148
+ }
149
+ }
150
+ TdFlavoredMarkdownTableComponent.ɵfac = function TdFlavoredMarkdownTableComponent_Factory(t) { return new (t || TdFlavoredMarkdownTableComponent)(); };
151
+ TdFlavoredMarkdownTableComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredMarkdownTableComponent, selectors: [["ng-component"]], viewQuery: function TdFlavoredMarkdownTableComponent_Query(rf, ctx) {
152
+ if (rf & 1) {
153
+ i0.ɵɵviewQuery(MatSort, 5);
154
+ }
155
+ if (rf & 2) {
156
+ let _t;
157
+ i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.sort = _t.first);
158
+ }
159
+ }, inputs: { columnDefs: "columnDefs", data: "data" }, decls: 4, vars: 4, consts: [["matSort", "", 3, "dataSource"], ["ngFor", "", 3, "ngForOf"], [4, "matHeaderRowDef"], [4, "matRowDef", "matRowDefColumns"], [3, "matColumnDef"], ["mat-sort-header", "", 4, "matHeaderCellDef"], [4, "matCellDef"], ["mat-sort-header", ""]], template: function TdFlavoredMarkdownTableComponent_Template(rf, ctx) {
160
+ if (rf & 1) {
161
+ i0.ɵɵelementStart(0, "mat-table", 0);
162
+ i0.ɵɵtemplate(1, TdFlavoredMarkdownTableComponent_ng_template_1_Template, 3, 1, "ng-template", 1);
163
+ i0.ɵɵtemplate(2, TdFlavoredMarkdownTableComponent_mat_header_row_2_Template, 1, 0, "mat-header-row", 2);
164
+ i0.ɵɵtemplate(3, TdFlavoredMarkdownTableComponent_mat_row_3_Template, 1, 0, "mat-row", 3);
165
+ i0.ɵɵelementEnd();
166
+ }
167
+ if (rf & 2) {
168
+ i0.ɵɵproperty("dataSource", ctx.dataSource);
169
+ i0.ɵɵadvance(1);
170
+ i0.ɵɵproperty("ngForOf", ctx.columnDefs);
171
+ i0.ɵɵadvance(1);
172
+ i0.ɵɵproperty("matHeaderRowDef", ctx.displayedColumns);
173
+ i0.ɵɵadvance(1);
174
+ i0.ɵɵproperty("matRowDefColumns", ctx.displayedColumns);
175
+ }
176
+ }, dependencies: [i1.NgForOf, i1$1.TdMarkdownComponent, i3$1.MatTable, i3$1.MatHeaderCellDef, i3$1.MatHeaderRowDef, i3$1.MatColumnDef, i3$1.MatCellDef, i3$1.MatRowDef, i3$1.MatHeaderCell, i3$1.MatCell, i3$1.MatHeaderRow, i3$1.MatRow, i4.MatSort, i4.MatSortHeader], encapsulation: 2 });
177
+ (function () {
178
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownTableComponent, [{
179
+ type: Component,
180
+ args: [{
181
+ template: `
182
+ <mat-table [dataSource]="dataSource" matSort>
183
+ <!-- Column Definition -->
184
+ <ng-template ngFor let-column [ngForOf]="columnDefs">
185
+ <ng-container [matColumnDef]="column.name">
186
+ <mat-header-cell *matHeaderCellDef mat-sort-header>{{
187
+ column.label
188
+ }}</mat-header-cell>
189
+ <mat-cell *matCellDef="let row"
190
+ ><td-markdown>{{ row[column.name] }}</td-markdown></mat-cell
191
+ >
192
+ </ng-container>
193
+ </ng-template>
194
+ <!-- Header and Row Declarations -->
195
+ <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
196
+ <mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
197
+ </mat-table>
198
+ `,
199
+ }]
200
+ }], null, { columnDefs: [{
201
+ type: Input
202
+ }], data: [{
203
+ type: Input
204
+ }], sort: [{
205
+ type: ViewChild,
206
+ args: [MatSort]
207
+ }] });
208
+ })();
209
+ class TdFlavoredMarkdownButtonComponent {
210
+ constructor() {
211
+ this.display = 'inline-block';
212
+ this.text = '';
213
+ this.data = '';
214
+ this.clicked = new EventEmitter();
215
+ }
216
+ emitClick() {
217
+ this.clicked.emit({ text: this.text, data: this.data });
218
+ }
219
+ }
220
+ TdFlavoredMarkdownButtonComponent.ɵfac = function TdFlavoredMarkdownButtonComponent_Factory(t) { return new (t || TdFlavoredMarkdownButtonComponent)(); };
221
+ TdFlavoredMarkdownButtonComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredMarkdownButtonComponent, selectors: [["ng-component"]], hostVars: 2, hostBindings: function TdFlavoredMarkdownButtonComponent_HostBindings(rf, ctx) {
222
+ if (rf & 2) {
223
+ i0.ɵɵstyleProp("display", ctx.display);
224
+ }
225
+ }, inputs: { text: "text", data: "data" }, outputs: { clicked: "clicked" }, decls: 2, vars: 1, consts: [["mat-raised-button", "", 3, "click"]], template: function TdFlavoredMarkdownButtonComponent_Template(rf, ctx) {
226
+ if (rf & 1) {
227
+ i0.ɵɵelementStart(0, "button", 0);
228
+ i0.ɵɵlistener("click", function TdFlavoredMarkdownButtonComponent_Template_button_click_0_listener() { return ctx.emitClick(); });
229
+ i0.ɵɵtext(1);
230
+ i0.ɵɵelementEnd();
231
+ }
232
+ if (rf & 2) {
233
+ i0.ɵɵadvance(1);
234
+ i0.ɵɵtextInterpolate1(" ", ctx.text, " ");
235
+ }
236
+ }, dependencies: [i5.MatButton], encapsulation: 2 });
237
+ (function () {
238
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownButtonComponent, [{
239
+ type: Component,
240
+ args: [{
241
+ template: `
242
+ <button mat-raised-button (click)="emitClick()">
243
+ {{ text }}
244
+ </button>
245
+ `,
246
+ }]
247
+ }], null, { display: [{
248
+ type: HostBinding,
249
+ args: ['style.display']
250
+ }], text: [{
251
+ type: Input
252
+ }], data: [{
253
+ type: Input
254
+ }], clicked: [{
255
+ type: Output
256
+ }] });
257
+ })();
258
+ class TdFlavoredMarkdownContainerDirective {
259
+ constructor(viewContainerRef, _renderer) {
260
+ this.viewContainerRef = viewContainerRef;
261
+ this._renderer = _renderer;
262
+ }
263
+ clear() {
264
+ this._renderer.setProperty(this.viewContainerRef.element.nativeElement, 'innerHTML', '');
265
+ this.viewContainerRef.clear();
266
+ }
267
+ }
268
+ TdFlavoredMarkdownContainerDirective.ɵfac = function TdFlavoredMarkdownContainerDirective_Factory(t) { return new (t || TdFlavoredMarkdownContainerDirective)(i0.ɵɵdirectiveInject(i0.ViewContainerRef), i0.ɵɵdirectiveInject(i0.Renderer2)); };
269
+ TdFlavoredMarkdownContainerDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: TdFlavoredMarkdownContainerDirective, selectors: [["", "tdFlavoredMarkdownContainer", ""]] });
270
+ (function () {
271
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownContainerDirective, [{
272
+ type: Directive,
273
+ args: [{
274
+ selector: '[tdFlavoredMarkdownContainer]',
275
+ }]
276
+ }], function () { return [{ type: i0.ViewContainerRef }, { type: i0.Renderer2 }]; }, null);
277
+ })();
278
+ class TdFlavoredMarkdownComponent {
279
+ /**
280
+ * content?: string
281
+ *
282
+ * Markdown format content to be parsed as material/covalent markup.
283
+ *
284
+ * e.g. README.md content.
285
+ */
286
+ set content(content) {
287
+ this._content = content;
288
+ }
289
+ /**
290
+ * simpleLineBreaks?: string
291
+ *
292
+ * Sets whether newline characters inside paragraphs and spans are parsed as <br/>.
293
+ * Defaults to false.
294
+ */
295
+ set simpleLineBreaks(simpleLineBreaks) {
296
+ this._simpleLineBreaks = simpleLineBreaks;
297
+ }
298
+ /**
299
+ * hostedUrl?: string
300
+ *
301
+ * If markdown contains relative paths, this is required to generate correct urls
302
+ *
303
+ */
304
+ set hostedUrl(hostedUrl) {
305
+ this._hostedUrl = hostedUrl;
306
+ }
307
+ /**
308
+ * anchor?: string
309
+ *
310
+ * Anchor to jump to
311
+ *
312
+ */
313
+ set anchor(anchor) {
314
+ this._anchor = anchor;
315
+ }
316
+ constructor(_componentFactoryResolver, _renderer, _changeDetectorRef, _injector, _elementRef) {
317
+ this._componentFactoryResolver = _componentFactoryResolver;
318
+ this._renderer = _renderer;
319
+ this._changeDetectorRef = _changeDetectorRef;
320
+ this._injector = _injector;
321
+ this._elementRef = _elementRef;
322
+ this._simpleLineBreaks = false;
323
+ this._components = {};
324
+ this._viewInit = false;
325
+ /**
326
+ * copyCodeToClipboard?: boolean
327
+ *
328
+ * Display copy button on code snippets to copy code to clipboard.
329
+ *
330
+ */
331
+ this.copyCodeToClipboard = false;
332
+ /**
333
+ * copyCodeTooltips?: ICopyCodeTooltips
334
+ *
335
+ * Tooltips for copy button to copy and upon copying.
336
+ */
337
+ this.copyCodeTooltips = {};
338
+ /**
339
+ * toggleRawCode?: boolean
340
+ *
341
+ * Display button to toggle raw code view
342
+ */
343
+ this.toggleRawCode = false;
344
+ /**
345
+ * rawToggleLabels?: IRawToggleLabels
346
+ *
347
+ * Labels for raw code toggle button
348
+ */
349
+ this.rawToggleLabels = {};
350
+ /**
351
+ * useCfmList?: boolean = false;
352
+ * Use CFM list component instead of vanilla markdown list. Used in covalent documentation app.
353
+ */
354
+ this.useCfmList = false;
355
+ /**
356
+ * contentReady?: function
357
+ * Event emitted after the markdown content rendering is finished.
358
+ */
359
+ this.contentReady = new EventEmitter();
360
+ /**
361
+ * buttonClicked?: ITdFlavoredMarkdownButtonClickEvent
362
+ * Event emitted when a button is clicked
363
+ * Is an object containing text and data of button
364
+ */
365
+ this.buttonClicked = new EventEmitter();
366
+ this._destroy$ = new Subject();
367
+ }
368
+ ngOnChanges(changes) {
369
+ // only anchor changed
370
+ if (changes['anchor'] &&
371
+ !changes['content'] &&
372
+ !changes['simpleLineBreaks'] &&
373
+ !changes['hostedUrl']) {
374
+ scrollToAnchor(this._elementRef.nativeElement, this._anchor, false);
375
+ }
376
+ else {
377
+ this.refresh();
378
+ }
379
+ }
380
+ ngAfterViewInit() {
381
+ var _a;
382
+ if (!this._content) {
383
+ this._loadContent((_a = this.container.viewContainerRef.element.nativeElement
384
+ .textContent) !== null && _a !== void 0 ? _a : '');
385
+ Promise.resolve().then(() => {
386
+ this._viewInit = true;
387
+ this._changeDetectorRef.markForCheck();
388
+ });
389
+ }
390
+ }
391
+ ngOnDestroy() {
392
+ this._destroy$.next();
393
+ }
394
+ refresh() {
395
+ var _a;
396
+ if (this._content) {
397
+ this._loadContent(this._content);
398
+ }
399
+ else if (this._viewInit) {
400
+ this._loadContent((_a = this.container.viewContainerRef.element.nativeElement
401
+ .textContent) !== null && _a !== void 0 ? _a : '');
402
+ }
403
+ this._changeDetectorRef.markForCheck();
404
+ }
405
+ _loadContent(markdown) {
406
+ if (markdown && markdown.trim().length > 0) {
407
+ this.container.clear();
408
+ markdown = markdown
409
+ .replace(/^(\s|\t)*\n+/g, '')
410
+ .replace(/(\s|\t)*\n+(\s|\t)*$/g, '');
411
+ // Split markdown by line characters
412
+ let lines = markdown.split('\n');
413
+ // check how much indentation is used by the first actual markdown line
414
+ const firstLineWhitespaceMatch = lines[0].match(/^(\s|\t)*/);
415
+ const firstLineWhitespace = firstLineWhitespaceMatch
416
+ ? firstLineWhitespaceMatch[0]
417
+ : null;
418
+ // Remove all indentation spaces so markdown can be parsed correctly
419
+ // Remove all \r characters
420
+ const startingWhitespaceRegex = new RegExp('^' + firstLineWhitespace);
421
+ lines = lines.map(function (line) {
422
+ return line.replace(startingWhitespaceRegex, '').replace('\r', '');
423
+ });
424
+ // Join lines again with line characters
425
+ markdown = [...lines, '', ''].join('\n');
426
+ markdown = this._replaceCodeBlocks(markdown);
427
+ markdown = this._replaceCheckbox(markdown);
428
+ markdown = this._replaceTables(markdown);
429
+ markdown = this._replaceButtons(markdown);
430
+ if (this.useCfmList) {
431
+ markdown = this._replaceLists(markdown);
432
+ }
433
+ const keys = Object.keys(this._components);
434
+ // need to sort the placeholders in order of encounter in markdown content
435
+ keys.sort((compA, compB) => {
436
+ return markdown.indexOf(compA) > markdown.indexOf(compB) ? 1 : -1;
437
+ });
438
+ this._render(markdown, keys[0], keys);
439
+ // TODO: timeout required since resizing of html elements occurs which causes a change in the scroll position
440
+ setTimeout(() => scrollToAnchor(this._elementRef.nativeElement, this._anchor, false), 250);
441
+ this.contentReady.emit();
442
+ Promise.resolve().then(() => {
443
+ this._changeDetectorRef.markForCheck();
444
+ });
445
+ }
446
+ }
447
+ _render(markdown, key, keys) {
448
+ if (!markdown) {
449
+ return;
450
+ }
451
+ if (key && markdown.indexOf(key) > -1) {
452
+ const markdownParts = markdown.split(key);
453
+ keys.shift();
454
+ this._render(markdownParts[0], '', []);
455
+ this.container.viewContainerRef.insert(this._components[key].hostView, this.container.viewContainerRef.length);
456
+ delete this._components[key];
457
+ this._render(markdownParts[1], keys[0], keys);
458
+ }
459
+ else {
460
+ const contentRef = this._componentFactoryResolver
461
+ .resolveComponentFactory(TdMarkdownComponent)
462
+ .create(this._injector);
463
+ contentRef.instance.content = markdown;
464
+ contentRef.instance.hostedUrl = this._hostedUrl;
465
+ contentRef.instance.simpleLineBreaks = this._simpleLineBreaks;
466
+ contentRef.instance.refresh();
467
+ this.container.viewContainerRef.insert(contentRef.hostView, this.container.viewContainerRef.length);
468
+ }
469
+ }
470
+ _replaceComponent(markdown, type, regExp, replacerFunc) {
471
+ let componentIndex = 0;
472
+ return markdown.replace(regExp, (...args) => {
473
+ const componentFactory = this._componentFactoryResolver.resolveComponentFactory(type);
474
+ const componentRef = componentFactory.create(this._injector);
475
+ replacerFunc(componentRef, ...args);
476
+ const key = '[' +
477
+ componentFactory.selector +
478
+ '-placeholder-' +
479
+ componentIndex++ +
480
+ ']';
481
+ this._components[key] = componentRef;
482
+ return key;
483
+ });
484
+ }
485
+ _replaceCheckbox(markdown) {
486
+ const checkboxRegExp = /(?:^|\n)- \[(x| )\](.*)/gi;
487
+ return this._replaceComponent(markdown, MatCheckbox, checkboxRegExp, (componentRef, match, checked, label) => {
488
+ componentRef.instance.checked = !!checked.trim();
489
+ componentRef.instance.ariaLabel = label;
490
+ componentRef.instance.labelPosition = 'after';
491
+ this._renderer.setProperty((componentRef.instance._elementRef.nativeElement).getElementsByTagName('label')[0], 'innerHTML', label);
492
+ });
493
+ }
494
+ _replaceButtons(markdown) {
495
+ const buttonRegExp = /\[([^[]+)\](\(#data=(.*?)\))/i;
496
+ const globalButtonRegExp = new RegExp(buttonRegExp.source, buttonRegExp.flags + 'g');
497
+ return this._replaceComponent(markdown, TdFlavoredMarkdownButtonComponent, globalButtonRegExp, (componentRef, match) => {
498
+ const matches = buttonRegExp.exec(match);
499
+ if (!matches) {
500
+ return;
501
+ }
502
+ const text = matches[1];
503
+ const data = matches[3];
504
+ componentRef.instance.text = text;
505
+ componentRef.instance.data = data;
506
+ componentRef.instance.clicked
507
+ .pipe(takeUntil(this._destroy$))
508
+ .subscribe((clickEvent) => this.buttonClicked.emit(clickEvent));
509
+ });
510
+ }
511
+ _replaceCodeBlocks(markdown) {
512
+ const codeBlockRegExp = /(?:^|\n)```(.*)\n([\s\S]*?)\n```/g;
513
+ return this._replaceComponent(markdown, TdHighlightComponent, codeBlockRegExp, (componentRef, match, language, codeblock) => {
514
+ if (language) {
515
+ componentRef.instance.codeLang = language;
516
+ }
517
+ componentRef.instance.copyCodeToClipboard = this.copyCodeToClipboard;
518
+ componentRef.instance.copyCodeTooltips = this.copyCodeTooltips;
519
+ componentRef.instance.toggleRawButton = this.toggleRawCode;
520
+ componentRef.instance.rawToggleLabels = this.rawToggleLabels;
521
+ componentRef.instance.content = codeblock;
522
+ });
523
+ }
524
+ _replaceTables(markdown) {
525
+ const tableRgx = /^ {0,3}\|?.+\|.+\n[ \t]{0,3}\|?[ \t]*:?[ \t]*(?:-|=){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:-|=){2,}[\s\S]+?(?:\n\n|~0)/gm;
526
+ return this._replaceComponent(markdown, TdFlavoredMarkdownTableComponent, tableRgx, (componentRef, match) => {
527
+ const dataTableLines = match
528
+ .replace(/(\s|\t)*\n+(\s|\t)*$/g, '')
529
+ .split('\n');
530
+ const columns = dataTableLines[0]
531
+ .split('|')
532
+ .filter((col) => {
533
+ return col;
534
+ })
535
+ .map((s) => {
536
+ return s.trim();
537
+ });
538
+ const alignment = dataTableLines[1]
539
+ .split('|')
540
+ .filter((v) => {
541
+ return v;
542
+ })
543
+ .map((s) => {
544
+ return s.trim();
545
+ });
546
+ const data = [];
547
+ for (let i = 2; i < dataTableLines.length; i++) {
548
+ const rowSplit = dataTableLines[i]
549
+ .split('|')
550
+ .filter((cell) => {
551
+ return cell;
552
+ })
553
+ .map((s) => {
554
+ return s.trim();
555
+ });
556
+ const row = {};
557
+ columns.forEach((col, index) => {
558
+ const rowSplitCell = rowSplit[index];
559
+ if (rowSplitCell) {
560
+ row[col.toLowerCase().trim()] = rowSplitCell.replace(/`(.*)`/, (m, value) => {
561
+ return value;
562
+ });
563
+ }
564
+ });
565
+ data.push(row);
566
+ }
567
+ componentRef.instance.columnDefs = columns.map((col, index) => {
568
+ return {
569
+ label: col,
570
+ name: col ? col.toLowerCase().trim() : `column ${index}`,
571
+ numeric: /^--*[ \t]*:[ \t]*$/.test(alignment[index]),
572
+ };
573
+ });
574
+ componentRef.instance.data = data;
575
+ });
576
+ }
577
+ _replaceLists(markdown) {
578
+ const listRegExp = /(?:^|\n)(( *(\+|\*|-))[ |\t](.*)\n)+/g;
579
+ const listCharRegExp = new RegExp(/^(\+|\*|-)/);
580
+ return this._replaceComponent(markdown, TdFlavoredListComponent, listRegExp, (componentRef, match) => {
581
+ const start = /(\+|\*|-)/.exec(match);
582
+ const matchIndex = start !== null ? start.index : 1;
583
+ const lineTexts = match.split(new RegExp('\\n {' + (matchIndex - 1).toString() + '}(\\+|\\*|\\-)[ |\\t]'));
584
+ lineTexts.shift();
585
+ const lines = [];
586
+ lineTexts.forEach((text) => {
587
+ var _a;
588
+ const sublineTexts = text.split(/\n *(\+|\*|-) /);
589
+ const lineText = (_a = sublineTexts.shift()) !== null && _a !== void 0 ? _a : '';
590
+ if (listCharRegExp.test(lineText)) {
591
+ return;
592
+ }
593
+ lines.push({
594
+ line: lineText,
595
+ sublines: sublineTexts
596
+ .map((subline) => {
597
+ if (listCharRegExp.test(subline)) {
598
+ return '';
599
+ }
600
+ return subline.trim();
601
+ })
602
+ .filter((line) => !!line),
603
+ });
604
+ });
605
+ componentRef.instance.lines = lines;
606
+ });
607
+ }
608
+ }
609
+ TdFlavoredMarkdownComponent.ɵfac = function TdFlavoredMarkdownComponent_Factory(t) { return new (t || TdFlavoredMarkdownComponent)(i0.ɵɵdirectiveInject(i0.ComponentFactoryResolver), i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i0.ElementRef)); };
610
+ TdFlavoredMarkdownComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredMarkdownComponent, selectors: [["td-flavored-markdown"]], viewQuery: function TdFlavoredMarkdownComponent_Query(rf, ctx) {
611
+ if (rf & 1) {
612
+ i0.ɵɵviewQuery(TdFlavoredMarkdownContainerDirective, 7);
613
+ }
614
+ if (rf & 2) {
615
+ let _t;
616
+ i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.container = _t.first);
617
+ }
618
+ }, inputs: { content: "content", simpleLineBreaks: "simpleLineBreaks", hostedUrl: "hostedUrl", anchor: "anchor", copyCodeToClipboard: "copyCodeToClipboard", copyCodeTooltips: "copyCodeTooltips", toggleRawCode: "toggleRawCode", rawToggleLabels: "rawToggleLabels", useCfmList: "useCfmList" }, outputs: { contentReady: "contentReady", buttonClicked: "buttonClicked" }, features: [i0.ɵɵNgOnChangesFeature], ngContentSelectors: _c0, decls: 2, vars: 0, consts: [["tdFlavoredMarkdownContainer", ""]], template: function TdFlavoredMarkdownComponent_Template(rf, ctx) {
619
+ if (rf & 1) {
620
+ i0.ɵɵprojectionDef();
621
+ i0.ɵɵelementStart(0, "div", 0);
622
+ i0.ɵɵprojection(1);
623
+ i0.ɵɵelementEnd();
624
+ }
625
+ }, dependencies: [TdFlavoredMarkdownContainerDirective], styles: ["[_nghost-%COMP%] td-markdown:first-of-type>div:first-of-type>h1:first-of-type, [_nghost-%COMP%] td-markdown:first-of-type>div:first-of-type>h2:first-of-type{margin-top:0}[_nghost-%COMP%] mat-checkbox{display:block}[_nghost-%COMP%] td-highlight, [_nghost-%COMP%] mat-table, [_nghost-%COMP%] mat-checkbox:last-of-type{margin-bottom:16px}[_nghost-%COMP%] :not(pre)>code{font-family:Menlo,Monaco,Andale Mono,lucida console,Courier New,monospace;padding-left:2px;padding-right:2px}[_nghost-%COMP%] td-highlight{display:flex;flex-direction:row;justify-content:space-between}"], changeDetection: 0 });
626
+ (function () {
627
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownComponent, [{
628
+ type: Component,
629
+ args: [{ selector: 'td-flavored-markdown', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div tdFlavoredMarkdownContainer>\n <ng-content></ng-content>\n</div>\n", styles: [":host ::ng-deep td-markdown:first-of-type>div:first-of-type>h1:first-of-type,:host ::ng-deep td-markdown:first-of-type>div:first-of-type>h2:first-of-type{margin-top:0}:host ::ng-deep mat-checkbox{display:block}:host ::ng-deep td-highlight,:host ::ng-deep mat-table,:host ::ng-deep mat-checkbox:last-of-type{margin-bottom:16px}:host ::ng-deep :not(pre)>code{font-family:Menlo,Monaco,Andale Mono,lucida console,Courier New,monospace;padding-left:2px;padding-right:2px}:host ::ng-deep td-highlight{display:flex;flex-direction:row;justify-content:space-between}\n"] }]
630
+ }], function () { return [{ type: i0.ComponentFactoryResolver }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i0.Injector }, { type: i0.ElementRef }]; }, { content: [{
631
+ type: Input
632
+ }], simpleLineBreaks: [{
633
+ type: Input
634
+ }], hostedUrl: [{
635
+ type: Input
636
+ }], anchor: [{
637
+ type: Input
638
+ }], copyCodeToClipboard: [{
639
+ type: Input
640
+ }], copyCodeTooltips: [{
641
+ type: Input
642
+ }], toggleRawCode: [{
643
+ type: Input
644
+ }], rawToggleLabels: [{
645
+ type: Input
646
+ }], useCfmList: [{
647
+ type: Input
648
+ }], contentReady: [{
649
+ type: Output
650
+ }], buttonClicked: [{
651
+ type: Output
652
+ }], container: [{
653
+ type: ViewChild,
654
+ args: [TdFlavoredMarkdownContainerDirective, { static: true }]
655
+ }] });
656
+ })();
657
+
658
+ function TdFlavoredMarkdownLoaderComponent_mat_progress_bar_0_Template(rf, ctx) {
659
+ if (rf & 1) {
660
+ i0.ɵɵelement(0, "mat-progress-bar", 2);
661
+ }
662
+ if (rf & 2) {
663
+ i0.ɵɵproperty("ngClass", "delay");
664
+ }
665
+ }
666
+ function TdFlavoredMarkdownLoaderComponent_td_flavored_markdown_1_Template(rf, ctx) {
667
+ if (rf & 1) {
668
+ const _r3 = i0.ɵɵgetCurrentView();
669
+ i0.ɵɵelementStart(0, "td-flavored-markdown", 3);
670
+ i0.ɵɵlistener("contentReady", function TdFlavoredMarkdownLoaderComponent_td_flavored_markdown_1_Template_td_flavored_markdown_contentReady_0_listener() { i0.ɵɵrestoreView(_r3); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.contentReady.emit()); })("buttonClicked", function TdFlavoredMarkdownLoaderComponent_td_flavored_markdown_1_Template_td_flavored_markdown_buttonClicked_0_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.buttonClicked.emit($event)); });
671
+ i0.ɵɵelementEnd();
672
+ }
673
+ if (rf & 2) {
674
+ const ctx_r1 = i0.ɵɵnextContext();
675
+ let tmp_1_0;
676
+ let tmp_2_0;
677
+ i0.ɵɵproperty("content", ctx_r1.content)("hostedUrl", (tmp_1_0 = ctx_r1.url) !== null && tmp_1_0 !== undefined ? tmp_1_0 : "")("anchor", (tmp_2_0 = ctx_r1.anchor) !== null && tmp_2_0 !== undefined ? tmp_2_0 : "")("copyCodeToClipboard", ctx_r1.copyCodeToClipboard)("copyCodeTooltips", ctx_r1.copyCodeTooltips)("useCfmList", ctx_r1.useCfmList);
678
+ }
679
+ }
680
+ // TODO: make a td-markdown-loader component
681
+ class TdFlavoredMarkdownLoaderComponent {
682
+ constructor(_changeDetectorRef, _markdownUrlLoaderService) {
683
+ this._changeDetectorRef = _changeDetectorRef;
684
+ this._markdownUrlLoaderService = _markdownUrlLoaderService;
685
+ /**
686
+ * copyCodeToClipboard?: boolean
687
+ *
688
+ * Display copy button on code snippets to copy code to clipboard.
689
+ *
690
+ */
691
+ this.copyCodeToClipboard = false;
692
+ /**
693
+ * copyCodeTooltips?: ICopyCodeTooltips
694
+ *
695
+ * Tooltips for copy button to copy and upon copying.
696
+ */
697
+ this.copyCodeTooltips = {};
698
+ /**
699
+ * useCfmList?: boolean = false;
700
+ * Use CFM list component instead of vanilla markdown list. Used in covalent documentation app.
701
+ */
702
+ this.useCfmList = false;
703
+ /**
704
+ * contentReady: void
705
+ * Emitted when markdown rendering is finished.
706
+ */
707
+ this.contentReady = new EventEmitter();
708
+ /**
709
+ * loadFailed: Error
710
+ * Emitted when loading of markdown file fails.
711
+ */
712
+ this.loadFailed = new EventEmitter();
713
+ this.buttonClicked = new EventEmitter();
714
+ this.loading = true;
715
+ }
716
+ ngOnChanges(changes) {
717
+ if (changes['url'] || changes['httpOptions']) {
718
+ this.loadMarkdown();
719
+ }
720
+ }
721
+ loadMarkdown() {
722
+ var _a;
723
+ return __awaiter(this, void 0, void 0, function* () {
724
+ this.loading = true;
725
+ this._changeDetectorRef.markForCheck();
726
+ try {
727
+ this.content = yield this._markdownUrlLoaderService.load((_a = this.url) !== null && _a !== void 0 ? _a : '', this.httpOptions);
728
+ }
729
+ catch (error) {
730
+ this.loadFailed.emit(error);
731
+ }
732
+ finally {
733
+ this.loading = false;
734
+ this._changeDetectorRef.markForCheck();
735
+ }
736
+ });
737
+ }
738
+ }
739
+ TdFlavoredMarkdownLoaderComponent.ɵfac = function TdFlavoredMarkdownLoaderComponent_Factory(t) { return new (t || TdFlavoredMarkdownLoaderComponent)(i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i1$1.TdMarkdownLoaderService)); };
740
+ TdFlavoredMarkdownLoaderComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TdFlavoredMarkdownLoaderComponent, selectors: [["td-flavored-markdown-loader"]], inputs: { url: "url", httpOptions: "httpOptions", anchor: "anchor", copyCodeToClipboard: "copyCodeToClipboard", copyCodeTooltips: "copyCodeTooltips", useCfmList: "useCfmList" }, outputs: { contentReady: "contentReady", loadFailed: "loadFailed", buttonClicked: "buttonClicked" }, features: [i0.ɵɵNgOnChangesFeature], decls: 2, vars: 2, consts: [["mode", "indeterminate", "color", "accent", "class", "sticky", 3, "ngClass", 4, "ngIf"], [3, "content", "hostedUrl", "anchor", "copyCodeToClipboard", "copyCodeTooltips", "useCfmList", "contentReady", "buttonClicked", 4, "ngIf"], ["mode", "indeterminate", "color", "accent", 1, "sticky", 3, "ngClass"], [3, "content", "hostedUrl", "anchor", "copyCodeToClipboard", "copyCodeTooltips", "useCfmList", "contentReady", "buttonClicked"]], template: function TdFlavoredMarkdownLoaderComponent_Template(rf, ctx) {
741
+ if (rf & 1) {
742
+ i0.ɵɵtemplate(0, TdFlavoredMarkdownLoaderComponent_mat_progress_bar_0_Template, 1, 1, "mat-progress-bar", 0);
743
+ i0.ɵɵtemplate(1, TdFlavoredMarkdownLoaderComponent_td_flavored_markdown_1_Template, 1, 6, "td-flavored-markdown", 1);
744
+ }
745
+ if (rf & 2) {
746
+ i0.ɵɵproperty("ngIf", ctx.loading);
747
+ i0.ɵɵadvance(1);
748
+ i0.ɵɵproperty("ngIf", !ctx.loading);
749
+ }
750
+ }, dependencies: [i1.NgClass, i1.NgIf, i3$2.MatProgressBar, TdFlavoredMarkdownComponent], styles: ["[_nghost-%COMP%]{display:block}.sticky[_ngcontent-%COMP%]{position:absolute;top:0}.delay[_ngcontent-%COMP%]{animation:_ngcontent-%COMP%_delay-animation;animation-duration:.6s}@keyframes _ngcontent-%COMP%_delay-animation{0%{opacity:0}99%{opacity:0}to{opacity:1}}"], changeDetection: 0 });
751
+ (function () {
752
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TdFlavoredMarkdownLoaderComponent, [{
753
+ type: Component,
754
+ args: [{ selector: 'td-flavored-markdown-loader', changeDetection: ChangeDetectionStrategy.OnPush, template: "<mat-progress-bar\n [ngClass]=\"'delay'\"\n *ngIf=\"loading\"\n mode=\"indeterminate\"\n color=\"accent\"\n class=\"sticky\"\n></mat-progress-bar>\n<td-flavored-markdown\n *ngIf=\"!loading\"\n [content]=\"content\"\n [hostedUrl]=\"url ?? ''\"\n [anchor]=\"anchor ?? ''\"\n [copyCodeToClipboard]=\"copyCodeToClipboard\"\n [copyCodeTooltips]=\"copyCodeTooltips\"\n [useCfmList]=\"useCfmList\"\n (contentReady)=\"contentReady.emit()\"\n (buttonClicked)=\"buttonClicked.emit($event)\"\n></td-flavored-markdown>\n", styles: [":host{display:block}.sticky{position:absolute;top:0}.delay{animation:delay-animation;animation-duration:.6s}@keyframes delay-animation{0%{opacity:0}99%{opacity:0}to{opacity:1}}\n"] }]
755
+ }], function () { return [{ type: i0.ChangeDetectorRef }, { type: i1$1.TdMarkdownLoaderService }]; }, { url: [{
756
+ type: Input
757
+ }], httpOptions: [{
758
+ type: Input
759
+ }], anchor: [{
760
+ type: Input
761
+ }], copyCodeToClipboard: [{
762
+ type: Input
763
+ }], copyCodeTooltips: [{
764
+ type: Input
765
+ }], useCfmList: [{
766
+ type: Input
767
+ }], contentReady: [{
768
+ type: Output
769
+ }], loadFailed: [{
770
+ type: Output
771
+ }], buttonClicked: [{
772
+ type: Output
773
+ }] });
774
+ })();
775
+
776
+ class CovalentFlavoredMarkdownModule {
777
+ }
778
+ CovalentFlavoredMarkdownModule.ɵfac = function CovalentFlavoredMarkdownModule_Factory(t) { return new (t || CovalentFlavoredMarkdownModule)(); };
779
+ CovalentFlavoredMarkdownModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: CovalentFlavoredMarkdownModule });
780
+ CovalentFlavoredMarkdownModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule,
781
+ MatCheckboxModule,
782
+ MatListModule,
783
+ MatProgressBarModule,
784
+ CovalentHighlightModule,
785
+ CovalentMarkdownModule,
786
+ MatButtonModule,
787
+ MatTableModule,
788
+ MatSortModule] });
789
+ (function () {
790
+ (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(CovalentFlavoredMarkdownModule, [{
791
+ type: NgModule,
792
+ args: [{
793
+ imports: [
794
+ CommonModule,
795
+ MatCheckboxModule,
796
+ MatListModule,
797
+ MatProgressBarModule,
798
+ CovalentHighlightModule,
799
+ CovalentMarkdownModule,
800
+ MatButtonModule,
801
+ MatTableModule,
802
+ MatSortModule,
803
+ ],
804
+ declarations: [
805
+ TdFlavoredListComponent,
806
+ TdFlavoredMarkdownComponent,
807
+ TdFlavoredMarkdownContainerDirective,
808
+ TdFlavoredMarkdownLoaderComponent,
809
+ TdFlavoredMarkdownButtonComponent,
810
+ TdFlavoredMarkdownTableComponent,
811
+ ],
812
+ exports: [TdFlavoredMarkdownComponent, TdFlavoredMarkdownLoaderComponent],
813
+ }]
814
+ }], null, null);
815
+ })();
816
+ (function () {
817
+ (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(CovalentFlavoredMarkdownModule, { declarations: [TdFlavoredListComponent,
818
+ TdFlavoredMarkdownComponent,
819
+ TdFlavoredMarkdownContainerDirective,
820
+ TdFlavoredMarkdownLoaderComponent,
821
+ TdFlavoredMarkdownButtonComponent,
822
+ TdFlavoredMarkdownTableComponent], imports: [CommonModule,
823
+ MatCheckboxModule,
824
+ MatListModule,
825
+ MatProgressBarModule,
826
+ CovalentHighlightModule,
827
+ CovalentMarkdownModule,
828
+ MatButtonModule,
829
+ MatTableModule,
830
+ MatSortModule], exports: [TdFlavoredMarkdownComponent, TdFlavoredMarkdownLoaderComponent] });
831
+ })();
832
+
833
+ /**
834
+ * Generated bundle index. Do not edit.
835
+ */
836
+
837
+ export { CovalentFlavoredMarkdownModule, TdFlavoredMarkdownButtonComponent, TdFlavoredMarkdownComponent, TdFlavoredMarkdownContainerDirective, TdFlavoredMarkdownLoaderComponent, TdFlavoredMarkdownTableComponent };
838
+ //# sourceMappingURL=covalent-flavored-markdown.mjs.map