Skip to content

Pattern match on multiple language document (e.g., Vue SFC file) #978

Answered by zhiyuanzmj
hitochan777 asked this question in Q&A
Discussion options

You must be logged in to vote

You can comment <style> and <template> block first.

id: setup-sfc start comment
language: html
rule:
  kind: script_element
  has:
    kind: start_tag
    pattern: $START
    precedes:
      kind: raw_text
      pattern: $RAW
      precedes:
        kind: end_tag
        pattern: $END
  inside:
    kind: fragment
fix: |-
  $START*/
  $RAW/*$END
id: setup-sfc end comment
language: html
rule:
  kind: fragment
  pattern: $A
  has:
    kind: script_element
fix: /*$A*/

Result

/*<script setup>*/

defineProps<{
  foo: string
}>()

/*</script>
<template>
  <div>{foo}<div>
</template>*/

After conversion, clean these comments.

id: setup-sfc clean comment
language: tsx
rule:
  kind: comment
  regex: 

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@HerringtonDarkholme
Comment options

@hitochan777
Comment options

@hitochan777
Comment options

Comment options

You must be logged in to vote
3 replies
@hitochan777
Comment options

@HerringtonDarkholme
Comment options

@hitochan777
Comment options

Answer selected by hitochan777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants