Skip to content

Commit

Permalink
Merge pull request #27 from fsegurai/development
Browse files Browse the repository at this point in the history
fix/improved markdown rendering component
fix/unit tests
  • Loading branch information
fsegurai committed Jul 4, 2024
2 parents 429deae + a749ce6 commit b32da0f
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 442 deletions.
2 changes: 1 addition & 1 deletion demo/src/app/get-started/get-started.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<app-scrollspy-nav-layout [headings]="headings">
<h1 id="getting-started">Get Started</h1>
<markdown (load)="onLoad()" emoji
<markdown (load)="onLoad()" [emoji]="true"
src="https://raw.githubusercontent.com/fsegurai/ngx-markdown/main/README.md"></markdown>
</app-scrollspy-nav-layout>
13 changes: 6 additions & 7 deletions demo/src/app/playground/playground.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
<h1>Playground</h1>

<section>
<h2>Markdown</h2>

<div class="playground">
<mat-form-field class="editor">
<mat-label>Textarea</mat-label>
<textarea matInput [(ngModel)]="markdownContent"></textarea>
</mat-form-field>

<markdown
(ready)="onLoad()"
class="markdown"
[disableSanitizer]="true"
lineNumbers
[lineNumbers]="true"
[start]="1"
emoji
katex
[emoji]="true"
[katex]="true"
[katexOptions]="katexOptions"
mermaid
[mermaid]="true"
[mermaidOptions]="mermaidOptions"
clipboard
[clipboard]="true"
[clipboardLanguageButton]="true"
[data]="markdownRendering"
[routerLinkOptions]="{
Expand Down
26 changes: 16 additions & 10 deletions demo/src/app/playground/playground.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
ChangeDetectionStrategy, ChangeDetectorRef,
Component,
ElementRef,
OnDestroy,
OnInit,
} from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit } from '@angular/core';
import { FlexModule } from '@angular/flex-layout/flex';
import { FormsModule } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
Expand Down Expand Up @@ -74,23 +68,35 @@ export default class PlaygroundComponent implements OnInit, OnDestroy {
}

ngOnInit(): void {
this.setHeadings();

this.updateMarkdownRendering();
}

ngOnDestroy(): void {
this.headings = undefined;
}

onLoad(): void {
this.stripContent();
this.setHeadings();
}

private setHeadings(): void {
const headings: Element[] = [];
this.elementRef.nativeElement
.querySelectorAll('h2')
.forEach(x => headings.push(x));
.forEach((x) => headings.push(x));
this.headings = headings;
}

private stripContent(): void {
this.elementRef.nativeElement
.querySelector('markdown')!
.querySelectorAll(
'markdown > p:nth-child(-n + 2), #ngx-markdown, #table-of-contents + ul, #table-of-contents',
)
.forEach((x) => x.remove());
}

private updateMarkdownRendering(): void {
this.markdownRendering = this.markdownContent;

Expand Down
Loading

0 comments on commit b32da0f

Please sign in to comment.