fix(aio): trim code blocks before rendering
This commit is contained in:
parent
e4c3882a81
commit
34a1990c57
|
@ -105,6 +105,22 @@ describe('CodeComponent', () => {
|
|||
expect(lis.length).toBe(0, 'should be no linenums');
|
||||
});
|
||||
|
||||
it('should trim whitespace from the code before rendering', () => {
|
||||
hostComponent.linenums = false;
|
||||
hostComponent.code = '\n\n\n' + multiLineCode + '\n\n\n';
|
||||
fixture.detectChanges();
|
||||
const codeContent = codeComponentDe.nativeElement.querySelector('code').innerText;
|
||||
expect(codeContent).toEqual(codeContent.trim());
|
||||
});
|
||||
|
||||
it('should trim whitespace from code before computing whether to format linenums', () => {
|
||||
hostComponent.code = '\n\n\n' + hostComponent.code + '\n\n\n';
|
||||
fixture.detectChanges();
|
||||
// `<li>`s are a tell-tale for line numbers
|
||||
const lis = codeComponentDe.nativeElement.querySelectorAll('li');
|
||||
expect(lis.length).toBe(0, 'should be no linenums');
|
||||
});
|
||||
|
||||
it('should call copier service when copy button clicked', () => {
|
||||
const copierService: TestCopierService = <any> codeComponentDe.injector.get(CopierService) ;
|
||||
const button = fixture.debugElement.query(By.css('button')).nativeElement;
|
||||
|
|
|
@ -72,6 +72,8 @@ export class CodeComponent implements OnChanges {
|
|||
ngOnChanges() {
|
||||
if (!this.code) { return; }
|
||||
|
||||
this.code = this.code.trim();
|
||||
|
||||
const linenums = this.getLinenums();
|
||||
|
||||
this.setCodeHtml(this.code); // start with unformatted code
|
||||
|
|
Loading…
Reference in New Issue