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

associate other file extensions #1

Closed
disrupted opened this issue Nov 2, 2023 · 4 comments
Closed

associate other file extensions #1

disrupted opened this issue Nov 2, 2023 · 4 comments

Comments

@disrupted
Copy link

disrupted commented Nov 2, 2023

What a cool new formatter! I've been trying it out with dprint and it works great, especially the ability to format embedded CSS and JS tags is brilliant.
I was hoping to use this to format my Jinja2 HTML templates (also known as htmldjango filetype in Neovim). Here's an example:

index.jinja2

<!doctype html>
<html>
  <head>
    <title>Hello World</title>
    <style>
      body {
        font-family: sans-serif;
      }
    </style>
  </head>
  <body>
    <h1>Hello {{ user.name }}</h1>
    {% for item in items %}
      <a>{{ item }}<a>
    {% endfor %}
  </body>
</html>

When I run dprint fmt "**/*.jinja2" --diff | delta dprint says No files found to format with the specified plugins. That makes sense, since markup_fmt expects files with the .html extension. As expected, it works with this trick cat index.jinja2 | dprint fmt --stdin html.

I was hoping to add associations for custom file extensions. I tried it with the following minimal config
dprint.jsonc

{
    "$schema": "https://dprint.dev/schemas/v0.json",
    "incremental": true,
    "typescript": {},
    "malva": {},
    "markup": {
        "associations": [
            "**/*.html",
            "**/*.jinja2"
        ]
    },
    "includes": [
        "**/*.{html,jinja2}"
    ],
    "plugins": [
        "https://plugins.dprint.dev/typescript-0.88.3.wasm",
        "https://plugins.dprint.dev/g-plane/malva-v0.1.2.wasm",
        "https://plugins.dprint.dev/g-plane/markup_fmt-v0.1.1.wasm"
    ]
}

but I am getting the error

Error formatting index.jinja2. Message: unknown file extension of file: index.jinja2
@g-plane
Copy link
Owner

g-plane commented Nov 2, 2023

Adding associations is simple, but I'm not sure whether the code with template syntaxes (such as {% for ... %} and {% if ... %}) can be formatted well or not. Can you rename Jinja2 files to .html temporarily then let us check the format result?

@disrupted
Copy link
Author

markup_fmt already does an excellent job. If I rename the extension to html or run cat index.jinja2 | dprint fmt --stdin html the output is perfectly formatted.

@g-plane
Copy link
Owner

g-plane commented Nov 2, 2023

Sounds good.

@g-plane g-plane closed this as completed in 79efec1 Nov 3, 2023
@disrupted
Copy link
Author

thank you so much!

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