Skip to content

Commit 96f3b33

Browse files
feat: add pywire grammar and fix repo link
1 parent e4ab7a8 commit 96f3b33

3 files changed

Lines changed: 351 additions & 12 deletions

File tree

site/astro.config.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const viteConfig = {
1919
preprocessorOptions: {
2020
scss: {
2121
logger: {
22-
warn: () => {},
22+
warn: () => { },
2323
},
2424
},
2525
},
@@ -94,5 +94,17 @@ export default defineConfig({
9494
site: 'https://pywire.dev',
9595
base: '/',
9696
integrations: [compress(), icon(), mdx(), sitemap()],
97+
markdown: {
98+
shikiConfig: {
99+
langs: [
100+
'python',
101+
{
102+
id: 'pywire',
103+
scopeName: 'source.pywire',
104+
path: './src/grammars/pywire.tmLanguage.json'
105+
}
106+
]
107+
}
108+
},
97109
vite: viteConfig,
98110
})
Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "PyWire",
4+
"scopeName": "source.pywire",
5+
"patterns": [
6+
{
7+
"include": "#python-header"
8+
},
9+
{
10+
"include": "#separator"
11+
},
12+
{
13+
"include": "#html-content"
14+
}
15+
],
16+
"repository": {
17+
"python-header": {
18+
"begin": "\\A",
19+
"end": "^(?=\\s*---+\\s*html\\s*---+\\s*$)|^(?=[ \\t]*<[!a-zA-Z/])",
20+
"contentName": "meta.embedded.block.python",
21+
"patterns": [
22+
{
23+
"include": "#directives"
24+
},
25+
{
26+
"include": "#wire-variable"
27+
},
28+
{
29+
"include": "source.python"
30+
}
31+
]
32+
},
33+
"separator": {
34+
"match": "^\\s*(-{3,})\\s*[Hh][Tt][Mm][Ll]\\s*\\1\\s*$",
35+
"name": "punctuation.separator.pywire keyword.control.pywire"
36+
},
37+
"html-content": {
38+
"patterns": [
39+
{
40+
"include": "#directives"
41+
},
42+
{
43+
"include": "#comments"
44+
},
45+
{
46+
"include": "#tags"
47+
},
48+
{
49+
"include": "#interpolation"
50+
},
51+
{
52+
"include": "#text"
53+
}
54+
]
55+
},
56+
"directives": {
57+
"patterns": [
58+
{
59+
"match": "^\\s*(!\\w+)",
60+
"name": "keyword.control.directive.pywire"
61+
},
62+
{
63+
"begin": "(!path)\\s*(\\{)",
64+
"beginCaptures": {
65+
"1": {
66+
"name": "keyword.control.directive.pywire"
67+
},
68+
"2": {
69+
"name": "punctuation.section.embedded.begin.pywire"
70+
}
71+
},
72+
"end": "(\\})",
73+
"endCaptures": {
74+
"1": {
75+
"name": "punctuation.section.embedded.end.pywire"
76+
}
77+
},
78+
"contentName": "meta.embedded.block.python",
79+
"patterns": [
80+
{
81+
"include": "#wire-variable"
82+
},
83+
{
84+
"include": "source.python"
85+
}
86+
]
87+
}
88+
]
89+
},
90+
"comments": {
91+
"patterns": [
92+
{
93+
"begin": "<!--",
94+
"end": "-->",
95+
"name": "comment.block.html"
96+
},
97+
{
98+
"match": "^\\s*#.*$",
99+
"name": "comment.line.number-sign.python"
100+
}
101+
]
102+
},
103+
"interpolation": {
104+
"begin": "\\{",
105+
"beginCaptures": {
106+
"0": {
107+
"name": "punctuation.section.embedded.begin.pywire"
108+
}
109+
},
110+
"end": "\\}",
111+
"endCaptures": {
112+
"0": {
113+
"name": "punctuation.section.embedded.end.pywire"
114+
}
115+
},
116+
"contentName": "meta.embedded.inline.python",
117+
"patterns": [
118+
{
119+
"include": "#wire-variable"
120+
},
121+
{
122+
"include": "source.python"
123+
}
124+
]
125+
},
126+
"tags": {
127+
"patterns": [
128+
{
129+
"include": "#tags-void"
130+
},
131+
{
132+
"include": "#tags-general"
133+
}
134+
]
135+
},
136+
"tags-void": {
137+
"begin": "(<)(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)(?=\\s|/?>)",
138+
"beginCaptures": {
139+
"1": {
140+
"name": "punctuation.definition.tag.begin.html"
141+
},
142+
"2": {
143+
"name": "entity.name.tag.html"
144+
}
145+
},
146+
"end": "/?>",
147+
"endCaptures": {
148+
"0": {
149+
"name": "punctuation.definition.tag.end.html"
150+
}
151+
},
152+
"name": "meta.tag.void.html",
153+
"patterns": [
154+
{
155+
"include": "#attributes"
156+
}
157+
]
158+
},
159+
"tags-general": {
160+
"begin": "(<)([^/\\s>/]*)",
161+
"beginCaptures": {
162+
"1": {
163+
"name": "punctuation.definition.tag.begin.html"
164+
},
165+
"2": {
166+
"name": "entity.name.tag.html"
167+
}
168+
},
169+
"end": "(/?>)",
170+
"endCaptures": {
171+
"1": {
172+
"name": "punctuation.definition.tag.end.html"
173+
}
174+
},
175+
"patterns": [
176+
{
177+
"include": "#attributes"
178+
}
179+
]
180+
},
181+
"tags-end": {
182+
"match": "(</)([^/\\s>]*)(\\>)",
183+
"captures": {
184+
"1": {
185+
"name": "punctuation.definition.tag.begin.html"
186+
},
187+
"2": {
188+
"name": "entity.name.tag.html"
189+
},
190+
"3": {
191+
"name": "punctuation.definition.tag.end.html"
192+
}
193+
}
194+
},
195+
"attributes": {
196+
"patterns": [
197+
{
198+
"include": "#attribute-event"
199+
},
200+
{
201+
"include": "#attribute-directive"
202+
},
203+
{
204+
"include": "#attribute-normal"
205+
}
206+
]
207+
},
208+
"attribute-event": {
209+
"begin": "(@[\\w\\.]+)(?=\\s*=?|/?>)",
210+
"beginCaptures": {
211+
"1": {
212+
"name": "entity.other.attribute-name.event.pywire support.function.event.pywire"
213+
}
214+
},
215+
"end": "(?=[\\s/>])",
216+
"patterns": [
217+
{
218+
"include": "#attribute-value-assignment"
219+
}
220+
]
221+
},
222+
"attribute-directive": {
223+
"begin": "(\\$[\\w\\.]+)(?=\\s*=?|/?>)",
224+
"beginCaptures": {
225+
"1": {
226+
"name": "keyword.control.directive.attribute.pywire"
227+
}
228+
},
229+
"end": "(?=[\\s/>])",
230+
"patterns": [
231+
{
232+
"include": "#attribute-value-assignment"
233+
}
234+
]
235+
},
236+
"attribute-normal": {
237+
"begin": "([^\\s\"'=<>`/]+)",
238+
"beginCaptures": {
239+
"1": {
240+
"name": "entity.other.attribute-name.html"
241+
}
242+
},
243+
"end": "(?=[\\s/>])",
244+
"patterns": [
245+
{
246+
"include": "#attribute-value-assignment"
247+
}
248+
]
249+
},
250+
"attribute-value-assignment": {
251+
"begin": "=",
252+
"beginCaptures": {
253+
"0": {
254+
"name": "punctuation.separator.key-value.html"
255+
}
256+
},
257+
"end": "(?=[\\s/>])",
258+
"patterns": [
259+
{
260+
"include": "#interpolation"
261+
},
262+
{
263+
"begin": "\"",
264+
"end": "\"",
265+
"name": "string.quoted.double.html",
266+
"patterns": [
267+
{
268+
"include": "#interpolation"
269+
}
270+
]
271+
},
272+
{
273+
"begin": "'",
274+
"end": "'",
275+
"name": "string.quoted.single.html",
276+
"patterns": [
277+
{
278+
"include": "#interpolation"
279+
}
280+
]
281+
},
282+
{
283+
"match": "[^\\s\"'=<>`/]+",
284+
"name": "string.unquoted.html"
285+
}
286+
]
287+
},
288+
"text": {
289+
"patterns": [
290+
{
291+
"include": "#tags-end"
292+
}
293+
]
294+
},
295+
"wire-variable": {
296+
"match": "(\\$)([a-zA-Z_]\\w*)",
297+
"captures": {
298+
"1": {
299+
"name": "punctuation.definition.variable.pywire keyword.operator.pywire"
300+
},
301+
"2": {
302+
"name": "variable.other.readwrite.pywire"
303+
}
304+
}
305+
}
306+
}
307+
}

site/src/pages/index.astro

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,36 @@ import DefaultLayout from '@layouts/DefaultLayout.astro'
33
import Feature from '@components/Feature.astro'
44
import { Heading, Link } from 'accessible-astro-components'
55
import { Icon } from 'astro-icon/components'
6-
import { Code } from 'astro/components'
6+
import { createHighlighter } from 'shiki'
7+
import pywireGrammar from '../grammars/pywire.tmLanguage.json'
78
8-
const pywireCode = `<div class="counter">
9-
<p>Count: {count}</p>
10-
<button @click={count += 1}>
11-
Add One
12-
</button>
13-
</div>
14-
---
15-
count = 0`
9+
const highlighter = await createHighlighter({
10+
themes: ['github-dark', 'catppuccin-mocha'],
11+
langs: [
12+
'python',
13+
{
14+
...pywireGrammar,
15+
name: 'pywire',
16+
} as any,
17+
],
18+
})
19+
20+
21+
const pywireCode = `count = wire(0)
22+
23+
def increment():
24+
$count += 1
25+
26+
--- html ---
27+
<p>Count: {count}</p>
28+
<button @click={increment}>
29+
Add One
30+
</button>`
31+
32+
const pywireHtml = highlighter.codeToHtml(pywireCode, {
33+
lang: 'pywire',
34+
theme: 'catppuccin-mocha',
35+
})
1636
---
1737

1838
<DefaultLayout title="Home">
@@ -31,7 +51,7 @@ count = 0`
3151
Get Started
3252
</Link>
3353
<Link
34-
href="https://github.com/rholmdahl/pywire"
54+
href="https://github.com/pywire/pywire"
3555
isButton
3656
type="secondary"
3757
animateOnHover
@@ -53,7 +73,7 @@ count = 0`
5373
<div class="h-3 w-3 rounded-full bg-green-500/50"></div>
5474
<span class="ml-2 font-mono text-xs text-[var(--theme-dark-muted)]">counter.wire</span>
5575
</div>
56-
<Code code={pywireCode} lang="html" theme="github-dark" />
76+
<Fragment set:html={pywireHtml} />
5777
</div>
5878
</div>
5979
</div>

0 commit comments

Comments
 (0)