Skip to content

Commit

Permalink
refactor: thinking in new markdown render
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 31, 2020
1 parent 27c0dc2 commit 06b5952
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/app/presentation/reporter/reporter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ export class ReporterComponent implements OnInit {

ngOnInit(): void {
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<div *ngFor="let chart of charts;" class="charts">
<component-markdown-chart [data]="chart"></component-markdown-chart>
<div *ngFor="let token of markdownData" class="markdown-reporter">
<div *ngIf="token.type === 'table'">
<div class="charts">
<component-markdown-chart [data]="token.data"></component-markdown-chart>
</div>
</div>
<div *ngIf="token.type === 'paragraph'">
<p>{{token.text}}</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.charts {
.markdown-reporter {
width: 960px;
margin: 4em auto 0;
}

.charts {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class MarkdownReporterComponent implements OnInit, AfterViewInit {
@Input()
content: string;
charts: ReporterChartModel[] = [];
markdownData: any[] = [];

constructor() {
}
Expand All @@ -26,6 +27,7 @@ export class MarkdownReporterComponent implements OnInit, AfterViewInit {

private buildChartData(content: string) {
const tokens = marked.lexer(content);
console.log(tokens);
this.buildData(tokens);
}

Expand All @@ -42,12 +44,21 @@ export class MarkdownReporterComponent implements OnInit, AfterViewInit {
}

private buildData(tokens: marked.Token[]) {
const markdownData = [];
for (const token of tokens) {
if (token.type === 'table') {
if (token.cells[0].length === 2) {
this.charts.push(this.buildMarkdownChart(token));
}
switch (token.type) {
case 'table':
if (token.cells[0].length === 2) {
const chartInfo = this.buildMarkdownChart(token);
this.charts.push(chartInfo);
this.markdownData.push({
type: 'table',
data: chartInfo
});
}
break;
default:
this.markdownData.push(token);
break;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/assets/docs/reporter.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
来源:[http://www.idcquan.com/Special/2019trucs/](http://www.idcquan.com/Special/2019trucs/)

| 敏捷开发技术 | 占比 |
|-------------|---------|
| 每日站会 | 50.93% |
Expand Down

0 comments on commit 06b5952

Please sign in to comment.