2021-06-15 00:28:59 +02:00
|
|
|
import BaseUIElement from "../BaseUIElement";
|
|
|
|
import Translations from "../i18n/Translations";
|
|
|
|
|
2021-09-09 00:05:51 +02:00
|
|
|
export default class Title extends BaseUIElement {
|
2021-06-15 00:28:59 +02:00
|
|
|
private readonly _embedded: BaseUIElement;
|
2021-09-09 00:05:51 +02:00
|
|
|
private readonly _level: number;
|
|
|
|
|
|
|
|
constructor(embedded: string | BaseUIElement, level: number = 3) {
|
2021-06-15 00:28:59 +02:00
|
|
|
super()
|
|
|
|
this._embedded = Translations.W(embedded);
|
|
|
|
this._level = level;
|
|
|
|
}
|
|
|
|
|
2021-09-09 00:05:51 +02:00
|
|
|
AsMarkdown(): string {
|
|
|
|
const embedded = " " + this._embedded.AsMarkdown() + " ";
|
|
|
|
|
|
|
|
if (this._level == 1) {
|
|
|
|
return "\n" + embedded + "\n" + "=".repeat(embedded.length) + "\n\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._level == 2) {
|
|
|
|
return "\n" + embedded + "\n" + "-".repeat(embedded.length) + "\n\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "\n" + "#".repeat(this._level) + embedded + "\n\n";
|
|
|
|
}
|
|
|
|
|
2021-06-15 00:28:59 +02:00
|
|
|
protected InnerConstructElement(): HTMLElement {
|
|
|
|
const el = this._embedded.ConstructElement()
|
2021-09-09 00:05:51 +02:00
|
|
|
if (el === undefined) {
|
2021-06-15 00:28:59 +02:00
|
|
|
return undefined;
|
|
|
|
}
|
2021-09-09 00:05:51 +02:00
|
|
|
const h = document.createElement("h" + this._level)
|
2021-06-15 00:28:59 +02:00
|
|
|
h.appendChild(el)
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
}
|