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

Djangojavascriptlexerfix #1589

Merged
merged 3 commits into from Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygments/lexers/templates.py
Expand Up @@ -338,7 +338,7 @@ class DjangoLexer(RegexLexer):
(r'[^{]+', Other),
(r'\{\{', Comment.Preproc, 'var'),
# jinja/django comments
(r'\{[*#].*?[*#]\}', Comment),
(r'\{#.*?#\}', Comment),
# django comments
(r'(\{%)(-?\s*)(comment)(\s*-?)(%\})(.*?)'
r'(\{%)(-?\s*)(endcomment)(\s*-?)(%\})',
Expand Down
41 changes: 41 additions & 0 deletions tests/test_djangojavascript_lexer.py
@@ -0,0 +1,41 @@
import pytest

from pygments.lexers.templates import JavascriptDjangoLexer
from pygments.token import Comment


@pytest.fixture(scope="module")
def lexer():
yield JavascriptDjangoLexer()


def test_do_not_mistake_JSDoc_for_django_comment(lexer):
"""
Test to make sure the lexer doesn't mistake
{* ... *} to be a django comment
"""
text = """/**
* @param {*} cool
*/
func = function(cool) {
};

/**
* @param {*} stuff
*/
fun = function(stuff) {
};"""
tokens = list(lexer.get_tokens(text))
assert (
(
Comment,
"""{*} cool
*/
func = function(cool) {
};

/**
* @param {*}""",
)
not in tokens
)