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

Syntax doesn't work when surrounded by quotes #8

Open
OscarGodson opened this issue Nov 3, 2015 · 3 comments
Open

Syntax doesn't work when surrounded by quotes #8

OscarGodson opened this issue Nov 3, 2015 · 3 comments

Comments

@OscarGodson
Copy link

For example

<img class="__post-cover-photo" src="<%= thumbnail %>" />

It's a solid color inside of the quotes. It should have different colors for things like <%= and %> and thumbnail

@karloluis
Copy link

Sadly the is no look ahead in regex, therefore there is no way for it to know that there is a script inside this string.

@OscarGodson
Copy link
Author

Hm, out of curiosity then how do the other templating languages do this? For example that identical code works in Mustache just changing it to {{ and }} instead of <%= and %>

@karloluis
Copy link

It's a scoping mechanism. Those symbols determine that code begins and ends, code which has it's own syntax. For strings there is no further syntax to be parsed through, you can just have a string.

There is no way to differentiate when `"<%= ... %>" is meant for code and when it coincidentally happens as a string, therefore the syntax compromises and says it's always a string because it doesn't know any better.

If my explanation does not suffice as it might be confusing, try to learn more about regular expression or even how compilers and interpreters "tokenize" your code. Hope this helped any way.

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

No branches or pull requests

2 participants