-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component:ledge-mermaid): add support mermaid
- Loading branch information
Showing
10 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
projects/ledge-render/src/lib/components/ledge-mermaid/ledge-mermaid.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div [innerHTML]="code | tohtml"></div> |
Empty file.
25 changes: 25 additions & 0 deletions
25
projects/ledge-render/src/lib/components/ledge-mermaid/ledge-mermaid.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { LedgeMermaidComponent } from './ledge-mermaid.component'; | ||
|
||
describe('LedgeMermaidComponent', () => { | ||
let component: LedgeMermaidComponent; | ||
let fixture: ComponentFixture<LedgeMermaidComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ LedgeMermaidComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(LedgeMermaidComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
projects/ledge-render/src/lib/components/ledge-mermaid/ledge-mermaid.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, OnInit, Input } from '@angular/core'; | ||
import * as mermaid from 'mermaid'; | ||
|
||
@Component({ | ||
selector: 'ledge-mermaid', | ||
templateUrl: './ledge-mermaid.component.html', | ||
styleUrls: ['./ledge-mermaid.component.scss'], | ||
}) | ||
export class LedgeMermaidComponent implements OnInit { | ||
@Input() | ||
data: string; | ||
code: string; | ||
constructor() {} | ||
|
||
ngOnInit(): void { | ||
mermaid.default.mermaidAPI.render( | ||
`mermaid-${Math.random().toString(32).slice(2)}`, | ||
this.data, | ||
(code) => { | ||
this.code = code; | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Component } from '@angular/core'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { LedgeRenderModule } from '../ledge-render.module'; | ||
|
||
|
||
describe('Pipe: tohtml', () => { | ||
let fixture: ComponentFixture<TestComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [LedgeRenderModule], | ||
declarations: [TestComponent], | ||
}); | ||
fixture = TestBed.createComponent(TestComponent); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
[ | ||
{ value: '', result: `` }, | ||
{ value: '<i>ledge</i>', result: `ledge` }, | ||
].forEach((item: any) => { | ||
it(`${item.value.toString()} muse be ${item.result}`, () => { | ||
fixture.componentInstance.value = item.value; | ||
fixture.detectChanges(); | ||
expect( | ||
(fixture.debugElement.query(By.css('#result')) | ||
.nativeElement as HTMLElement).textContent | ||
).toBe(item.result); | ||
}); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
template: `<div id="result" [innerHTML]="value | tohtml"></div> `, | ||
}) | ||
class TestComponent { | ||
value = ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; | ||
|
||
@Pipe({ name: 'tohtml' }) | ||
export class TohtmlPipe implements PipeTransform { | ||
constructor(private dom: DomSanitizer) {} | ||
|
||
transform(html: string): string | SafeHtml { | ||
return html ? this.dom.bypassSecurityTrustHtml(html) : ''; | ||
} | ||
} |