Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
280 lines (245 loc) · 6.46 KB
/
Copy pathindex.html
File metadata and controls
280 lines (245 loc) · 6.46 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!DOCTYPE html>
<title>syntaxp Syntax Highlighting Examples</title>
<meta name=viewport content="width=device-width">
<link rel=stylesheet href=syntaxp.css>
<script src=syntaxp.js defer></script>
<style>
body {
color: #1a1a1a;
font-family: ui-sans-serif, system-ui, sans-serif;
line-height: 1.5;
margin: 0;
padding: 1.5rem;
background: #f8f9fa;
}
h1 {
font-size: 1.75rem;
margin-bottom: .5rem;
}
h2 {
font-size: 1.25rem;
margin-top: 2rem;
margin-bottom: .5rem;
}
p {
margin-bottom: 1.5rem;
}
a {
color: #0066cc;
}
code {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
font-size: .875rem;
}
pre {
background: var(--s5p-background);
border-radius: 6px;
color: #1e1e2e;
line-height: 1.5;
overflow-x: auto;
padding: 1.25rem;
}
pre code {
display: block;
font-size: .875rem;
}
@media (prefers-color-scheme: dark) {
body {
color: #cdd6f4;
background-color: #1e1e2e;
}
pre {
background: var(--s5p-background);
color: #cdd6f4;
}
a {
color: #89b4fa;
}
}
</style>
<h1>syntaxp Syntax Highlighting Examples</h1>
<p>Code syntax highlighting with <a href=https://github.com/j9t/syntaxp>syntaxp</a> via the <a href="https://drafts.csswg.org/css-highlight-api-1/">CSS Custom Highlight API</a>. Zero runtime dependencies. No extra elements in the DOM. Light and dark mode. (<a href=https://meiert.com/blog/syntax-highlighting-with-syntaxp/>Read the announcement</a> and <a href=https://github.com/j9t/syntaxp#usage>try it in your project</a>.)
<h2>HTML (and XML)</h2>
<pre><code class=language-html><!DOCTYPE html>
<html lang=en>
<head>
<meta charset=UTF-8>
<title>My Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p class=intro>Welcome.</p>
</body>
</html></code></pre>
<h2>Markdown</h2>
<pre><code class=language-markdown># Getting Started
Install the package with `npm install example`, then read the **usage**
guide or check the _API reference_.
> Requires support for the Amazing API.
* Zero dependencies
* Zero maintenance
* [Read the docs](https://example.com/)</code></pre>
<h2>CSS</h2>
<pre><code class=language-css>/* Reset */
*,
*::before,
*::after {
box-sizing: border-box;
margin: ;
padding: ;
}
body {
font-family: system-ui, sans-serif;
line-height: 1.6;
color: #1a1a1a;
background-color: #ffffff;
}
.container {
max-width: 800px;
margin: auto;
padding: 2rem;
}</code></pre>
<h2>JavaScript</h2>
<pre><code class=language-javascript>// Fetch and display user data
async function fetchUser(id) {
try {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const user = await response.json();
console.log(`User: ${user.name}`);
return user;
} catch (err) {
console.error("Failed to fetch user:", err.message);
return null;
}
}
const app = {
name: "My App",
version: "1.0.0",
init() {
console.log(`${this.name} v${this.version} initialized`);
}
};
export default app;</code></pre>
<h2>TypeScript</h2>
<pre><code class=language-typescript>interface User {
id: number;
name: string;
email: string;
role: "admin" | "user" | "guest";
}
async function getUsers<T extends User>(
limit: number = 10
): Promise<T[]> {
const res = await fetch(`/api/users?limit=${limit}`);
const json = await res.json();
return json.data as T[];
}
export { getUsers };
export type { User };</code></pre>
<h2>Python</h2>
<pre><code class=language-python># Fetch and display user data
import json
from urllib.request import urlopen
class UserError(Exception):
pass
def fetch_user(user_id: int) -> dict:
with urlopen(f"https://example.com/api/users/{user_id}") as response:
if response.status != 200:
raise UserError(f"HTTP {response.status}")
return json.load(response)
def main():
user = fetch_user(42)
print(f"User: {user['name']}")
if __name__ == "__main__":
main()</code></pre>
<h2>Shell (and Bash)</h2>
<pre><code class=language-shell># Install dependencies
npm install
# Run development server
npm run dev -- --port 3000
# Build for production
NODE_ENV=production npm run build
# Deploy to server
ssh deploy@server.example.com "cd /var/www && git pull && pm2 restart app"</code></pre>
<h2>JSON</h2>
<pre><code class=language-json>{
"name": "My App",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "node scripts/build.mjs",
"test": "node --test"
},
"dependencies": {
"esbuild": "^0.28.1"
},
"strict": true,
"legacy": false,
"proxy": null
}</code></pre>
<h2>YAML</h2>
<pre><code class=language-yaml># Deployment config
name: My App
version: 1.0.0
private: true
env:
- NODE_ENV=production
- PORT=3000
build:
command: "npm run build"
output: dist/
retries: 3</code></pre>
<h2>SQL</h2>
<pre><code class=language-sql>SELECT customers.name, COUNT(orders.id) AS order_count
FROM customers
INNER JOIN orders ON orders.customer_id = customers.id
WHERE orders.created_at >= '2026-01-01'
GROUP BY customers.name
ORDER BY order_count DESC
LIMIT 10;</code></pre>
<h2>Nunjucks</h2>
<pre><code class=language-nunjucks>{# Render a list of active users #}
{% for user in users %}
{% if user.active %}
<li>{{ user.name | upper }}</li>
{% endif %}
{% endfor %}
{% set greeting = "Hello, " ~ user.name ~ "!" %}
{{ greeting }}</code></pre>
<h2>Diff</h2>
<pre><code class=language-diff>diff --git a/syntaxp.js b/syntaxp.js
index 1a2b3c4..5d6e7f8 100644
--- a/syntaxp.js
+++ b/syntaxp.js
@@ -14,6 +14,7 @@ const languages = {
html: [ … ],
css: [ … ],
+ json: [ … ],
js: [ … ]
};</code></pre>
<h2>HTTP</h2>
<pre><code class=language-http>GET /api/users/42 HTTP/1.1
Host: example.com
Authorization: Bearer abc123
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{"id": 42, "name": "Ada"}</code></pre>
<h2>Apache Configuration</h2>
<pre><code class=language-apacheconf># Redirect to HTTPS and compress text assets
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Header always set X-Content-Type-Options "nosniff"
AddOutputFilterByType DEFLATE text/html text/css application/javascript
ExpiresActive On
ExpiresByType text/css A129600
ExpiresByType text/html A10</code></pre>
<h2>Inline code</h2>
<p>“Use <code class=language-javascript>console.log("hello")</code> for debugging”, “enter <code class=language-shell>npm install</code> to install.”