Skip to content

fix: support multi-line lang attribute detection in style/script tags#16763

Open
algojogacor wants to merge 1 commit into
withastro:mainfrom
algojogacor:fix/sass-multiline-syntax-highlighting
Open

fix: support multi-line lang attribute detection in style/script tags#16763
algojogacor wants to merge 1 commit into
withastro:mainfrom
algojogacor:fix/sass-multiline-syntax-highlighting

Conversation

@algojogacor
Copy link
Copy Markdown

Summary

Fix syntax highlighting for <style> and <script> tags when the lang or type attribute is on a different line from the opening tag.

Root Cause

The TextMate grammar regex used [^>]*? to scan for lang/type attributes within style/script tags. In Oniguruma (VS Code's regex engine), [^>] does not reliably match across newlines in all configurations, causing the language detection to fail when attributes span multiple lines. The content then falls back to default CSS highlighting.

Changes

  • astro.tmLanguage.src.yaml: Changed [^>]*?[\s\S]*? in all three language-detection patterns (JSON-LD, module/JS, and generic language)
  • astro.tmLanguage.json: Same change in compiled grammar
  • Test fixture: Added sass-multiline.astro covering SCSS, LESS, SASS, and CSS with both single-line and multi-line attribute layouts

Testing

  • Manually verified the regex matches using Node.js and Python
  • Added test fixture covering all style language types with both single-line and multi-line <style> tag layouts
  • Existing grammar snapshot tests should continue to pass (pnpm test:grammar)

Related

Fixes #14657
Closes draft PR #15066 (supersedes with proper YAML source + JSON update)

The TextMate grammar used [^>]*? to scan for lang/type attributes
in style and script tags. In Oniguruma (VS Code's regex engine),
this does not reliably match across newlines, causing SASS/SCSS/LESS
content to be incorrectly highlighted as CSS when the lang attribute
is on a different line from the opening tag.

Changed [^>]*? to [\s\S]*? in all three language detection patterns
to explicitly match any character including newlines.

Fixes withastro#14657

- Updated astro.tmLanguage.src.yaml (source)
- Updated astro.tmLanguage.json (compiled)
- Added test fixture: sass-multiline.astro
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 17, 2026

⚠️ No Changeset found

Latest commit: 6ace9de

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 BUG: SASS content incorrectly highlighted as CSS syntax when lang='sass' is not on the same line with <style

1 participant