@covalent/flavored-markdown 4.0.0-beta.4 → 4.1.0-develop.4

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