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

Any way to customize rule/pattern to pretty a template file? #360

Closed
eromoe opened this issue Dec 27, 2016 · 1 comment
Closed

Any way to customize rule/pattern to pretty a template file? #360

eromoe opened this issue Dec 27, 2016 · 1 comment

Comments

@eromoe
Copy link

eromoe commented Dec 27, 2016

Hi, I use this plugin for a long time, but when I cope with some django templates file it always only formart html and convert js and css in a mess.

There is a file example :

{% extends 'layout.html' %}

{% block page_css %}
html,body{
    font-family: "Microsoft YaHei";
    height: 100%;
    line-height: 150%;
    font-size: 14px;
}

.tl
{
    text-align: left;
}

.tr
{
    text-align: right;
}

{% endblock page_css %}


{% block page_js %}
$(function(){
   $('.activation-from input').click(function(e){
        e.preventDefault();
        $.ajax({
            url:'{% url 'ss_activate' %}',
            data:{
                code:code
            },
            success: function(r){
                console.log(1111);
            }
        })
   });
});
{% endblock page_js %}


{% if admin %}
<style type="text/css">
body {
  color: purple;
  background-color: #d8da3d }
</style>
<p><b>ADMIN SCREEN</b></p>
{% endif %}
<script>
set_active_tab("Welcome");
if (first_time()) { turn_on_highlights(); }
</script>
<table><tr><td>a</td></tr><tr><td>b</td></tr></table>

I am not asking official to support such kind of files, I know it is difficult.
But I think we can provide some ways follow a rule to pretty a file.Maybe allow user to define a block pattern to do the specific work, such as:

{
    "block_pattern" : [
        {
            "name" : 'django_js_block',
            "type": "js",
            "block_name_regex": "[a-zA-Z0-9_-]+_my_jsblock",
            "regex_start": "{%\s+block\s+{block_name_regex}\s+%}",
            "regex_end": "{%\s+endblock\s+{block_name_regex}\s+%}"
        },
        {
            "name" : 'django_css_block',
            "type": "css",
            ....
        }

    ]
}

When format a file, search pattern to get the specific code block pretty in predefine type, the left code just cope in normal.

@eromoe eromoe changed the title Any way to customize how to pretty a template file? Any way to customize rule/pattern to pretty a template file? Dec 27, 2016
@victorporof
Copy link
Owner

Please file this bug at https://github.com/beautify-web/js-beautify

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