import { docLink } from "@goauthentik/common/global"; import "@goauthentik/elements/Alert"; import { Level } from "@goauthentik/elements/Alert"; import { AKElement } from "@goauthentik/elements/Base"; import { matter } from "md-front-matter"; import * as showdown from "showdown"; import { CSSResult, PropertyValues, css, html, nothing } from "lit"; import { customElement, property } from "lit/decorators.js"; import { unsafeHTML } from "lit/directives/unsafe-html.js"; import PFContent from "@patternfly/patternfly/components/Content/content.css"; import PFList from "@patternfly/patternfly/components/List/list.css"; export interface MarkdownDocument { path: string; } export type Replacer = (input: string, md: MarkdownDocument) => string; const isRelativeLink = /href="(\.[^"]*)"/gm; const isFile = /[^/]+\.md/; @customElement("ak-markdown") export class Markdown extends AKElement { @property() md: string = ""; @property() meta: string = ""; @property({ attribute: false }) replacers: Replacer[] = []; docHtml = ""; docTitle = ""; defaultReplacers: Replacer[] = [ this.replaceAdmonitions, this.replaceList, this.replaceRelativeLinks, ]; static get styles(): CSSResult[] { return [ PFList, PFContent, css` h2:first-of-type { margin-top: 0; } `, ]; } converter = new showdown.Converter({ metadata: true, tables: true }); replaceAdmonitions(input: string): string { const admonitionStart = /:::(\w+)(|\s*$)/gm; const admonitionEnd = /:::/gm; return ( input .replaceAll(admonitionStart, "") .replaceAll(admonitionEnd, "") // Workaround for admonitions using caution instead of warning .replaceAll("pf-m-caution", Level.Warning) ); } replaceList(input: string): string { return input.replace("