-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Latte templating language support #1599
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing!
Clearly, a lot of thought has gone into making this, so please add some tests explaining the features you covered (I have some trouble understanding them).
Apart from the missing tests and the comments I left you, this PR is basically good as is.
I want to sincerely apologize for the delay.
Thank you for your amazing work!
@@ -405,6 +405,11 @@ | |||
"title": "LaTeX", | |||
"owner": "japborst" | |||
}, | |||
"latte": { | |||
"title": "Latte", | |||
"require": "markup-templating", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also require php
.
|
||
(function(Prism) { | ||
|
||
var string_interpolation = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is only used once in inside.string[1].inside.interpolation
, so why not inline it?
'punctuation': /[\[\]().,:`]+|->|=>/ | ||
}; | ||
|
||
function mkmacro(begin, content, closing) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please give this function a more readable name and add some documentation.
|
||
// Tokenize all inline Latte expressions | ||
Prism.hooks.add('before-tokenize', function(env) { | ||
if (!/(?:\{[a-zA-Z$_!])/ig.test(env.code)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the group? Do the i
and g
flags have any effect?
case 2: valid = match.charAt(1) === '{'; break; | ||
} | ||
|
||
if (m = valid ? syntaxPattern.exec(match) : null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract this assignment.
<script> | ||
(function() { /* This is JS, not Smarty */ } ()); | ||
</script> | ||
{/syntax} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not highlighted.
} | ||
], | ||
'word': { | ||
pattern: /:?[a-zA-Z0-9_.-]+(?::[a-zA-Z0-9_.-]+)*[:!]?(?=[\s,\])]|$)/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use \w
instead of a-zA-Z0-9_
.
There are also a few other places where the same should be done.
'function': /\b(?!\d)\w+(?=\s*\()/, | ||
'keyword': [ | ||
{ | ||
pattern: /\b(?:true|false)\b/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a keyword and a boolean? Almost all other languages (including PHP) have a boolean
pattern and that's it, no keyword
.
See #2140. |
This PR adds support for the Latte templating language used by the Nette PHP framework. It's similar to Smarty; the most obvious difference is the support for
n:attribute
macros.