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

Is there an vscode extension we can use for syntax highlighing in html templates? #15

Closed
Pika-Pool opened this issue Jan 18, 2022 · 2 comments
Labels
feature request something requested by external user question Further information is requested

Comments

@Pika-Pool
Copy link

Screenshot

Right now it looks like a simple string. it'll be much better if we could get some syntax highlighting and ability to check/format the html and css in template string. Something like what the lit-html vscode extension does

@ECorreia45
Copy link
Contributor

ECorreia45 commented Jan 18, 2022

Not yet (working on it).

However, you can use inline-html or even the lit-html one and do the following in the code;

// utils/html.ts
export const html = x => x;

// my-button.ts
import {html} from './utils/html';

class MyButton extends WebComponent {
  get template() {
    return html`<button><slot></slot></button>`[0];
  }

  get stylesheet() {
    return html`<style>button {color: #900}</style>`[0];
  }
}

I know this is a hacky way but that is the best I can suggest for now.

I created a feature request for this
#16

@ECorreia45 ECorreia45 added feature request something requested by external user question Further information is requested labels Jan 18, 2022
@Pika-Pool
Copy link
Author

Pika-Pool commented Jan 18, 2022

The hack doesn't work as intended. The html function will return an array of type TemplateStringsArray, and not the string. This is my solution:

function html(strings: TemplateStringsArray, ...values: any[]) {
	return strings.reduce(
		(res, currString, currIndex) =>
			res + currString + (values[currIndex] ?? '').toString(),
		'',
	);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request something requested by external user question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants