Skip to content

django: Closing tags do not return to the previous rule #5898

@jsulgrove

Description

@jsulgrove

Describe the bug

Everything between a closing Django tag and the next "<" HTML start tag is unformatted. Furthermore, block comments should have green contents.

Expected Behavior

Everything between closing Django tags and "<" HTML start tags should maintain the same formatting as before the respective opening Django tag. Block comments should have green contents.

This image displays what it should look like:
Image

Current Behavior

Everything between a closing Django tag and the next "<" HTML start tag is unformatted. The opening {% comment %} tag is green, but the content in between is unformatted and the {% endcomment %} tag is formatted like a regular tag.

See the sample provided in the reproduction steps.

Reproduction Steps

Check out the formatting at this sample.

Possible Solution

This could be fixed in a similar manner as the HTML Elixir implementation.

var DjangoHtmlHighlightRules = function () {
    HtmlHighlightRules.call(this);
    var startRules = [
        {
            token: "comment.line",
            regex: "\\{#.*?#\\}"
        }, {
            token: "comment.block",
            regex: "\\{\\%\\s*comment\\s*\\%\\}",
            push: [{
                token: "comment.block",
                regex: "\\{\\%\\s*endcomment\\s*\\%\\}",
                next: "pop"
            }, {
                defaultToken: "comment.block"
            }]
        }, {
            token: "constant.language",
            regex: "\\{\\{",
            push: "django-start"
        }, {
            token: "constant.language",
            regex: "\\{\\%",
            push: "django-tag"
        }
    ];
    var endRules = [
        {
            token: "constant.language",
            regex: "\\%\\}",
            next: "pop"
        }, {
            token: "constant.language",
            regex: "\\}\\}",
            next: "pop"
        }
    ];
    for (var key in this.$rules)
        this.$rules[key].unshift.apply(this.$rules[key], startRules);
    this.embedRules(DjangoHighlightRules, "django-", endRules, ["start"]);
    this.normalizeRules();
};

Additional Information/Context

No response

Ace Version / Browser / OS / Keyboard layout

1.43.5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions