Skip to content

Commit

Permalink
use 'shared:' as keyword for shared vm info in markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Prinz authored and Philip Prinz committed Nov 26, 2024
1 parent 71cf9ac commit ee96249
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/app/hf-markdown/hf-markdown.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ ${token}`;

ngOnChanges() {
const contentWithReplacedTokens = this.replaceSessionToken(
this.replaceVmInfoTokens(this.content),
this.replaceVmInfoTokens(this.replaceSharedVmInfoTokens(this.content)),
);
// the parse method internally uses the Angular Dom Sanitizer and is therefore safe to use
this.processedContent = this.markdownService.parse(
Expand All @@ -256,10 +256,24 @@ ${token}`;

private replaceVmInfoTokens(content: string) {
return content.replace(
/\$\{vmInfo:([^:]*):([^}]*)\}/g,
/\$\{vminfo:([^:]*):([^}]*)\}/g,
(match, vmName, propName) => {
const vm = this.context.vmInfo?.[vmName.toLowerCase()];
return String(vm?.[propName as keyof VM] ?? match);
return String(
vm?.vm_type != 'SHARED' ? vm?.[propName as keyof VM] : match,
);
},
);
}

private replaceSharedVmInfoTokens(content: string) {
return content.replace(
/\$\{shared:([^:]*):([^}]*)\}/g,
(match, vmName, propName) => {
const vm = this.context.vmInfo?.[vmName.toLowerCase()];
return String(
vm?.vm_type == 'SHARED' ? vm?.[propName as keyof VM] : match,
);
},
);
}
Expand Down

0 comments on commit ee96249

Please sign in to comment.