Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Astro language support #3679

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Expand Up @@ -175,6 +175,11 @@
"title": "Atmel AVR Assembly",
"owner": "cerkit"
},
"astro": {
"title": "Astro",
"require": "tsx",
"owner": "HynekS"
},
"autohotkey": {
"title": "AutoHotkey",
"owner": "aviaryan"
Expand Down
24 changes: 24 additions & 0 deletions components/prism-astro.js
@@ -0,0 +1,24 @@
(function (Prism) {
Prism.languages.astro = Prism.languages.extend('tsx', {
comment: Prism.languages.tsx.comment.concat([
{
pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
greedy: true,
},
]),
});
Prism.languages.insertBefore('astro', 'prolog', {
'component-script-block': {
pattern: /(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,
lookbehind: true,
greedy: true,
inside: {
punctuation: /^---|---$/,
'component-script': {
pattern: /\S+(?:\s+\S+)*/,
inside: Prism.languages.typescript,
},
},
},
});
}(Prism));
1 change: 1 addition & 0 deletions components/prism-astro.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions examples/prism-astro.html
@@ -0,0 +1,33 @@
<h2>Full example</h2>
<pre><code>---
import Widget from &quot;@astrojs/components/widget&quot;;

// Define some TypeScript code
const message: string = &quot;Welcome to Astro.js&quot;;
---

&lt;style&gt;
article {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
&lt;/style&gt;

&lt;script&gt;
console.log(&quot;Hello from Astro&quot;);
&lt;/script&gt;

&lt;article&gt;
&lt;h1&gt;{message}&lt;/h1&gt;
&lt;p&gt;This is an example demonstrating Astro.js features.&lt;/p&gt;
&lt;!-- &quot;slot&quot; behaves similar to &quot;children&quot; in React --&gt;
&lt;slot /&gt;
&lt;Widget client:load /&gt;
&lt;/article&gt;</pre></code>







1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Expand Up @@ -23,6 +23,7 @@
"markup",
"csharp"
],
"astro": "tsx",
"birb": "clike",
"bison": "c",
"c": "clike",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/languages/astro/comments_feature.test
@@ -0,0 +1,4 @@
---
---
<!-- HTML comment syntax is valid in .astro files -->
{/* JS comment syntax is also valid */}
4 changes: 4 additions & 0 deletions tests/languages/astro/component_script_feature.test
@@ -0,0 +1,4 @@
---
const items = ["Dog", "Cat", "Platypus"];
---
<div>Scooby, Dexter, Plattie</div>
9 changes: 9 additions & 0 deletions tests/languages/astro/script_tag_feature.test
@@ -0,0 +1,9 @@
---
---
<button id="button">Click Me</button>
<script>
function handleClick () {
console.log("button clicked!");
}
document.getElementById("button").addEventListener("click", handleClick);
</script>
9 changes: 9 additions & 0 deletions tests/languages/astro/style_tag_feature.test
@@ -0,0 +1,9 @@
<style>
h1 {
color: red;
}

.text {
color: blue;
}
</style>
8 changes: 8 additions & 0 deletions tests/languages/astro/typescript_inclusion.test
@@ -0,0 +1,8 @@
---
interface Props {
name: string;
greeting?: string;
}
const { greeting = 'Hello', name } = Astro.props;
---
<h2>{greeting}, {name}!</h2>