Skip to content

Commit

Permalink
Support slot shorthand syntax to Vue lexer (#1483)
Browse files Browse the repository at this point in the history
As of Vue 2.6.0, it is possible to use a shorthand syntax for
specifying slots. To tokenise the syntax correctly, the HTML `:tag`
state must be amended to allow a tag's attributes to include the `#`
character. This commit makes that change.
  • Loading branch information
pyrmont authored Apr 7, 2020
1 parent 32c315e commit f054b73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rouge/lexers/vue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def lookup_lang(lang)
end
end

prepend :tag do
rule %r/[a-zA-Z0-9_:#\[\]()*.-]+\s*=\s*/m, Name::Attribute, :attr
end

state :style do
rule %r/(<\s*\/\s*)(style)(\s*>)/ do
groups Name::Tag, Keyword, Name::Tag
Expand Down Expand Up @@ -121,4 +125,3 @@ def lookup_lang(lang)
end
end
end

8 changes: 8 additions & 0 deletions spec/visual/samples/vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ p {
<script lang="coffee">
module.exports = { data: -> { greeting: 'Hello' } }
</script>

<!-- Slot Shorthand -->
<current-user v-slot:default="{ user }">
{{ user.firstName }}
</current-user>
<current-user #default="{ user }">
{{ user.firstName }}
</current-user>

0 comments on commit f054b73

Please sign in to comment.