Skip to content

Add Astro lexer support #2287

Description

@nyaomaru

The name of the language

Astro

Astro components use the .astro file extension.

The syntax combines a component script section between --- fences with an HTML-like template section.

Official syntax documentation:

Example:

---
const title = "Hello Astro";
const items = ["a", "b", "c"];
---

<h1>{title}</h1>

<ul>
  {items.map((item) => (
    <li>{item}</li>
  ))}
</ul>

Implementation in other libraries

Astro syntax highlighting is supported in other syntax highlighting tools/libraries.

I could not find an existing Astro lexer request in Rouge issues or pull requests.


Additional context

Supporting Astro in Rouge would help downstream platforms that use Rouge for syntax highlighting, such as Forem / DEV.to.

Currently, Markdown code fences like this are not highlighted as Astro on DEV.to:

---
const title = "Hello Astro";
---

<h1>{title}</h1>

A first implementation could support:

  • tag: astro
  • filenames: *.astro
  • the --- ... --- component script section as JavaScript/TypeScript-like code
  • the template section as HTML-like markup
  • {...} template expressions as JavaScript-like expressions

I’m opening this as a lexer request because Astro code blocks are becoming common in technical articles and documentation.

I hope this helps anyone interested in adding support for Astro in Rouge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lexer-requestA request for a lexer to be developed.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions