Skip to content

feat(twig): highlight Symfony UX Twig Components - #249

Open
juliangut wants to merge 1 commit into
tempestphp:mainfrom
juliangut:feat/twig-components
Open

juliangut wants to merge 1 commit into
tempestphp:mainfrom
juliangut:feat/twig-components

Conversation

@juliangut

Copy link
Copy Markdown

Adds support for Symfony UX Twig Components to the twig language.

<twig:…> component tags were left unhighlighted, because HtmlOpenTagPattern and HtmlCloseTagPattern deliberately reject names containing :. They are now highlighted like any other tag:

{% props size = 'md' %}
<twig:Card class="mb-4">
    <twig:block name="header">{{ title }}</twig:block>
    <twig:Button variant="outline" :disabled="busy" />
</twig:Card>
  • TwigComponentTagPattern highlights opening, closing and self-closing tags. Names accept the same characters as the Symfony UX lexer ([A-Za-z0-9_:@\-.]), so twig:Card.Header and twig:@Acme:Alert work too.
  • The props and component/endcomponent tags are added to TwigTagLanguage. In {% set x = component('Alert') %} the function call keeps its highlighting.

Tests cover the tag forms, near misses (<twigx:Alert>, <twig:>), and tags inside Twig comments and strings, which stay untouched.

Not covered: :prop="expr" values are not highlighted as Twig expressions. A <twig:…> tag inside an HTML attribute value or a JavaScript string is highlighted, exactly as a <div> is today.

These changes were made with AI assistance, based on changes already in use in another project, and have been reviewed manually. Here the tag name follows the Symfony UX lexer's full character set, and the UX keywords are added to the existing Twig keyword list.

Highlight `<twig:…>` component tags like any other tag, and the
`props` and `component`/`endcomponent` tags inside `{% %}` blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant