Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pug nested syntax #62

Open
freemember007 opened this issue Mar 8, 2019 · 5 comments
Open

Add support for pug nested syntax #62

freemember007 opened this issue Mar 8, 2019 · 5 comments

Comments

@freemember007
Copy link

freemember007 commented Mar 8, 2019

function Counter(props) {
  const [count, setCount] = useState(0)
  useEffect(() => {
    document.title = `You clicked ${count} times`
  })
  return pug`
    div.red.f1
      if props.showGreeting
        p.greeting Hello #{props.name}!
      button(
        onClick=()=>setCount(count + 1)
      ) #{count} Click Me
`}
@bathos
Copy link
Owner

bathos commented Mar 8, 2019

Sounds good. I would guess this can be added following the pattern @blake-regalia has established for other tagged template cases if a sublime syntax def for pug already exists. Otherwise we’d have to add new rules just for pug (which is okay, but it’d be nice to just be able to reuse what’s out there).

@freemember007 is there an existing pug sublime syntax package?

@freemember007
Copy link
Author

freemember007 commented Mar 8, 2019

@bathos yes, exists pug sublime syntax package, and I have achieved it by modifying the ecmascript.sublime-syntax source file:

%YAML 1.2
---
name: Ecmascript
file_extensions: [ js, jsx, es, es6, mjs ]
scope: source.es
...
...
variables:
...
...
  syntaxDirective_PUG:   '[Pp](?:UG|ug){{syntaxDirectiveTail}}'
...
...
  syntaxDirective: >-
...
...
        | {{syntaxDirective_PUG}}
...
...
contexts:

# MAIN, META & PROTOTYPE #######################################################

  main:
...
...

  syntax_DIRECTIVE:
...
...
    - match: '{{syntaxDirective_PUG}}'
      captures:
        1: punctuation.definition.comment.end.es
        2: entity.quasi.tag.name.js # ^BS
        3: variable.other.readwrite.tag.es
      set: [ syntax_meta_PUG, syntax_PUG_OPEN ]
...
...

# PUG SYNTAX ###################################################################

  syntax_meta_PUG:
    - meta_content_scope: meta.interpolation.syntax.pug
    - meta_include_prototype: false
    - match: '{{PLA_anything}}'
      pop: true

  syntax_PUG_OPEN:
    - meta_include_prototype: false
    - match: '`'
      scope: string.interpolated.es punctuation.definition.string.interpolated.begin.es
      set: scope:text.pug
      with_prototype:
        - include: syntax_AFTER_OPEN
...
...

this is the appearance:

img

thank you for write so awesome plugin!

@bathos
Copy link
Owner

bathos commented Mar 8, 2019

Nice.

I wonder if we should allow just recognizing certain “well-known” tags like “pug” without the hint comment? It seems sufficiently unlikely to me that the name “pug” would appear for other tags.

In any case, having added it @freemember007, please feel free to open a PR with your changes if you believe this is working right and will be useful to others.

@blake-regalia
Copy link
Collaborator

Thanks @freemember007 . I will take care of PR -- I have a local branch which adds pug following the same build process as HTML and Markdown because these syntaxes push or embed source.js, so we have special handling to prevent infinite recursion / exceeding stack limit in ST3.

However, it seems that pug-tmbundle might be slightly incompatibility with our syntax as is since it is not so straightforward to simply push into our syntax without context and assume it will recover, e.g.
screen shot 2019-03-08 at 9 58 54 am

@blake-regalia
Copy link
Collaborator

After spending a bit of time working on this, it's clear that the existing pug syntax requires somewhat substantial modifications to be compatible within ours. It also leaves something to be desired since it is does not always follow conventional scope naming. The repo has gone stale some time ago and I personally use pug wherever I can so I may just end up forking or rewriting the pug syntax from scratch 🤨

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

No branches or pull requests

3 participants