Skip to content

Commit 55b9e3e

Browse files
committed
add styling for tsx
1 parent 2a7937b commit 55b9e3e

File tree

6 files changed

+91
-34
lines changed

6 files changed

+91
-34
lines changed

deps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export { default as marked } from "https://esm.sh/[email protected]";
1111
export * as Prism from "https://esm.sh/[email protected]";
1212

1313
export { default as sanitizeHtml } from "https://esm.sh/[email protected]";
14+
15+
export { escape as htmlEscape } from "https://esm.sh/[email protected]";

example/content.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,44 @@ To contribute, please read our
105105
[Build status]: https://github.com/denoland/deno/actions
106106
[Twitter badge]: https://twitter.com/intent/follow?screen_name=deno_land
107107
[Twitter handle]: https://img.shields.io/twitter/follow/deno_land.svg?style=social&label=Follow
108+
109+
```tsx
110+
/** @jsx h */
111+
import { h, IS_BROWSER, useState } from "../deps.ts";
112+
113+
export default function Home() {
114+
return (
115+
<div>
116+
<p>
117+
Welcome to `fresh`. Try update this message in the ./pages/index.tsx
118+
file, and refresh.
119+
</p>
120+
<Counter />
121+
<p>{IS_BROWSER ? "Viewing browser render." : "Viewing JIT render."}</p>
122+
</div>
123+
);
124+
}
125+
126+
function Counter() {
127+
const [count, setCount] = useState(0);
128+
return (
129+
<div>
130+
<p>{count}</p>
131+
<button
132+
onClick={() => setCount(count - 1)}
133+
disabled={!IS_BROWSER}
134+
>
135+
-1
136+
</button>
137+
<button
138+
onClick={() => setCount(count + 1)}
139+
disabled={!IS_BROWSER}
140+
>
141+
+1
142+
</button>
143+
</div>
144+
);
145+
}
146+
147+
export const config: PageConfig = { runtimeJS: true };
148+
```

example/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { listenAndServe } from "https://deno.land/[email protected]/http/server.ts";
22

33
import { CSS, render } from "../mod.ts";
44

5-
import "https://esm.sh/[email protected]/components/prism-javascript?no-check";
5+
import "https://esm.sh/[email protected]/components/prism-jsx?no-check";
66
import "https://esm.sh/[email protected]/components/prism-typescript?no-check";
7+
import "https://esm.sh/[email protected]/components/prism-tsx?no-check";
78
import "https://esm.sh/[email protected]/components/prism-bash?no-check";
89
import "https://esm.sh/[email protected]/components/prism-powershell?no-check";
910

mod.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { emojify, marked, Prism, sanitizeHtml } from "./deps.ts";
1+
import { emojify, htmlEscape, marked, Prism, sanitizeHtml } from "./deps.ts";
22
import { CSS } from "./style.js";
33
export { CSS };
44

@@ -20,7 +20,7 @@ class Renderer extends marked.Renderer {
2020
? Prism.languages[language]
2121
: undefined;
2222
if (grammar === undefined) {
23-
return `<pre><code>${code}</code></pre>`;
23+
return `<pre><code>${htmlEscape(code)}</code></pre>`;
2424
}
2525
const html = Prism.highlight(code, grammar, language);
2626
return `<div class="highlight highlight-source-${language}"><pre>${html}</pre></div>`;
@@ -56,6 +56,7 @@ export function render(markdown: string, opts: RenderOptions = {}): string {
5656
if (opts.allowIframes) {
5757
allowedTags.push("iframe");
5858
}
59+
return html;
5960
return sanitizeHtml(html, {
6061
allowedTags,
6162
allowedAttributes: {

style.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

style/main.scss

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,49 @@
2525

2626
@import "@primer/css/markdown/index.scss";
2727

28-
.highlight .token.keyword {
29-
color: var(--color-prettylights-syntax-keyword);
30-
}
31-
32-
.highlight .token.operator,
33-
.token.number,
34-
.token.boolean {
35-
color: var(--color-prettylights-syntax-constant);
36-
}
37-
38-
.highlight .token.function {
39-
color: var(--color-prettylights-syntax-entity);
40-
}
41-
42-
.highlight .token.string {
43-
color: var(--color-prettylights-syntax-string);
44-
}
45-
46-
.highlight .token.comment {
47-
color: var(--color-prettylights-syntax-comment);
48-
}
49-
50-
.highlight .token.class-name {
51-
color: var(--color-prettylights-syntax-variable);
52-
}
28+
.highlight .token {
29+
&.keyword {
30+
color: var(--color-prettylights-syntax-keyword);
31+
}
5332

54-
.highlight .token.regex {
55-
color: var(--color-prettylights-syntax-string);
56-
}
33+
&.operator,
34+
&.number,
35+
&.boolean,
36+
&.tag .token.punctuation,
37+
&.tag .token.attr-name {
38+
color: var(--color-prettylights-syntax-constant);
39+
}
5740

58-
.highlight .token.regex .regex-delimiter {
59-
color: var(--color-prettylights-syntax-constant);
41+
&.function {
42+
color: var(--color-prettylights-syntax-entity);
43+
}
44+
45+
&.string {
46+
color: var(--color-prettylights-syntax-string);
47+
}
48+
49+
&.comment {
50+
color: var(--color-prettylights-syntax-comment);
51+
}
52+
53+
&.class-name {
54+
color: var(--color-prettylights-syntax-variable);
55+
}
56+
57+
&.regex {
58+
color: var(--color-prettylights-syntax-string);
59+
}
60+
61+
&.regex .regex-delimiter {
62+
color: var(--color-prettylights-syntax-constant);
63+
}
64+
65+
&.tag .token.tag {
66+
color: var(--color-prettylights-syntax-entity-tag);
67+
}
68+
69+
&.tag .token.class-name {
70+
color: var(--color-prettylights-syntax-storage-modifier-import);
71+
}
6072
}
6173

0 commit comments

Comments
 (0)