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

Latte templating language support #1599

Closed
wants to merge 3 commits into from

Conversation

jahudka
Copy link

@jahudka jahudka commented Oct 27, 2018

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.

Copy link
Member

@RunDevelopment RunDevelopment left a 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",
Copy link
Member

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 = {
Copy link
Member

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) {
Copy link
Member

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)) {
Copy link
Member

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) {
Copy link
Member

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}
Copy link
Member

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,\])]|$)/,
Copy link
Member

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/,
Copy link
Member

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.

@RunDevelopment
Copy link
Member

See #2140.

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

Successfully merging this pull request may close these issues.

None yet

2 participants