Skip to content

Commit

Permalink
parse markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoller committed Jan 18, 2025
1 parent f8e45d1 commit 94242ca
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
width="32"
height="32"
/>
<div *ngIf="message.text">{{ message.text }}</div>
<div *ngIf="message.text">
<div *ngIf="formattedMessage" [innerHTML]="formattedMessage"></div>
</div>
<div *ngIf="message.audio">
<audio [src]="message.audio" controls></audio>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component, Input } from '@angular/core';
import { ChatMessage } from '../tb-chat-message-list/tb-chat-message-list.component';
import {Component, Input, SimpleChanges} from '@angular/core';
import {ChatMessage} from '../tb-chat-message-list/tb-chat-message-list.component';
import {DomSanitizer, SafeHtml} from "@angular/platform-browser";
import {marked} from "marked";

@Component({
selector: 'tb-chat-message',
Expand All @@ -11,4 +13,16 @@ export class TbChatMessageComponent {
isTaskbase: true,
text: 'Default',
};

formattedMessage: SafeHtml | null = null;

constructor(private sanitizer: DomSanitizer) {}

async ngOnChanges(changes: SimpleChanges): Promise<void> {
if (changes['message'] && this.message.text) {
const markdown = await marked(this.message.text);
console.log("markdown: " + markdown);
this.formattedMessage = this.sanitizer.bypassSecurityTrustHtml(markdown);
}
}
}
139 changes: 139 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@
"husky": "^8.0.3",
"prettier": "^2.8.5",
"pretty-quick": "^3.1.3"
},
"dependencies": {
"@angular/platform-browser": "^19.1.1",
"marked": "^15.0.6"
}
}

0 comments on commit 94242ca

Please sign in to comment.