mapcomplete/UI/Base/FixedUiElement.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
848 B
TypeScript
Raw Normal View History

2021-06-12 02:58:32 +02:00
import BaseUIElement from "../BaseUIElement"
2020-06-24 00:35:19 +02:00
2021-06-12 02:58:32 +02:00
export class FixedUiElement extends BaseUIElement {
2021-11-30 22:50:48 +01:00
public readonly content: string
2020-06-24 00:35:19 +02:00
constructor(html: string) {
2021-06-12 02:58:32 +02:00
super()
2021-11-30 22:50:48 +01:00
this.content = html ?? ""
2020-06-24 00:35:19 +02:00
}
2020-07-20 18:24:00 +02:00
InnerRender(): string {
2021-11-30 22:50:48 +01:00
return this.content
2020-06-24 00:35:19 +02:00
}
AsMarkdown(): string {
2022-04-08 01:55:42 +02:00
if (this.HasClass("code")) {
2023-02-12 22:58:21 +01:00
if (this.content.indexOf("\n") > 0 || this.HasClass("block")) {
return "\n```\n" + this.content + "\n```\n"
}
2022-04-08 01:55:42 +02:00
return "`" + this.content + "`"
}
2022-12-08 00:48:44 +01:00
if (this.HasClass("font-bold")) {
return "*" + this.content + "*"
}
2021-11-30 22:50:48 +01:00
return this.content
}
2021-06-12 02:58:32 +02:00
protected InnerConstructElement(): HTMLElement {
const e = document.createElement("span")
2021-11-30 22:50:48 +01:00
e.innerHTML = this.content
2021-06-12 02:58:32 +02:00
return e
}
2020-06-24 00:35:19 +02:00
}