- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
/** @jsx h */
import { h, withStyles } from "../deps/nano_jsx.ts";
function cx(className: string): string {
return `markdown__${className}`;
}
interface MarkdownProps {
/**
* Parsed HTML string.
*/
html: string;
}
/**
* Component to render parsed markdown content.
*/
export const Markdown = ({ html }: MarkdownProps) => {
return withStyles(css)(
<div class={cx("root")} dangerouslySetInnerHTML={{ __html: html }} />,
);
};
const css = `
.${cx("root")} h1 {
font-size: var(--font-size-xl);
font-weight: bold;
}
.${cx("root")} h2 {
font-size: var(--font-size-lg);
font-weight: bold;
margin-top: 2em;
}
.${cx("root")} h3 {
font-size: var(--font-size-md);
font-weight: bold;
margin-top: 1.5em;
}
.${cx("root")} h4 {
font-size: var(--font-size-md);
font-weight: bold;
margin-top: 1em;
}
@keyframes ${cx("blink")} {
from {
color: hsl(var(--color-on-neutral));
}
to {
color: hsl(var(--color-primary));
}
}
.${cx("root")} h1:target,
.${cx("root")} h2:target,
.${cx("root")} h3:target {
animation: 0.3s 0s linear alternate 4 ${cx("blink")};
}
.${cx("root")} p {
line-height: var(--line-height-normal);
margin-top: 0.5em;
}
.${cx("root")} a {
color: hsl(var(--color-primary));
text-decoration: none;
}
.${cx("root")} a:hover,
.${cx("root")} a:focus-visible {
text-decoration: underline;
}
.${cx("root")} code:not(pre > code),
.${cx("root")} pre {
padding: var(--gutter-xs) var(--gutter-md);
font-family: var(--font-family-mono);
background-color: hsl(var(--color-panel));
border-radius: var(--radius);
color: hsl(var(--color-on-panel));
}
.${cx("root")} pre {
margin-top: 1em;
width: 100%;
padding: var(--gutter-md) var(--gutter-lg);
border: var(--border-width) solid hsla(var(--color-border));
line-height: var(--line-height-dense);
overflow-x: auto;
}
.${cx("root")} details {
margin-top: 1em;
}
.${cx("root")} [class^="language-"] .token.keyword {
color: hsl(var(--color-code-keyword));
}
.${cx("root")} [class^="language-"] .token.string {
color: hsl(var(--color-code-string));
}
.${cx("root")} [class^="language-"] .token.operator {
color: hsl(var(--color-code-operator));
}
.${cx("root")} [class^="language-"] .token.function {
color: hsl(var(--color-code-function));
}
.${cx("root")} [class^="language-"] .token.comment {
color: hsl(var(--color-code-comment));
font-style: italic;
}
.${cx("root")} ul {
margin-top: 0.5em;
padding-left: 1em;
}
.${cx("root")} ul ul {
margin-top: 0;
}
.${cx("root")} iframe {
margin-top: 1em;
width: 100%;
aspect-ratio: 4 / 3;
border: var(--border-width) solid hsla(var(--color-border));
border-radius: var(--radius);
}
.${cx("root")} table {
width: 100%;
margin-top: 1em;
/*
border-collapse: collapse;
*/
border-spacing: 0;
border: var(--border-width) solid hsla(var(--color-border));
border-radius: var(--radius);
}
.${cx("root")} thead {
background-color: hsl(var(--color-panel));
color: hsl(var(--color-on-panel));
}
.${cx("root")} th,
.${cx("root")} tr:not(:last-child) > td {
border-bottom: var(--border-width) solid hsla(var(--color-border));
}
.${cx("root")} th,
.${cx("root")} td {
padding: var(--gutter-sm) var(--gutter-md);
}
`;