Compare commits

...

5 commits

7 changed files with 33 additions and 22 deletions

1
.npmrc Normal file
View file

@ -0,0 +1 @@
registry=https://git.fetbuk.ru/api/packages/WerySkok/npm/

View file

@ -1,11 +1,17 @@
# prettier-plugin-jinja-template # prettier-plugin-askama-template
[prettier-plugin-jinja-template](https://github.com/davidodenwald/prettier-plugin-jinja-template) but with patches to work with Askama.
Formatter plugin for jinja2 template files.
## Install ## Install
```bash ```bash
npm install --save-dev prettier prettier-plugin-jinja-template npm install --save-dev prettier https://git.fetbuk.ru/WerySkok/-/packages/npm/prettier-plugin-askama-template/1.0.0/files/2
```
Add the plugin to your `.prettierrc`:
```json
{
"plugins": ["prettier-plugin-askama-template"]
}
``` ```
## Use ## Use
@ -17,7 +23,7 @@ To format basic .html files, you'll have to override the used parser inside your
{ {
"files": ["*.html"], "files": ["*.html"],
"options": { "options": {
"parser": "jinja-template" "parser": "askama-template"
} }
} }
] ]
@ -27,4 +33,9 @@ To format basic .html files, you'll have to override the used parser inside your
Run it on all html files in your project: Run it on all html files in your project:
```bash ```bash
npx prettier --write **/*.html npx prettier --write **/*.html
```
If you don't have a prettier config you can run the plugin with this command:
```bash
npx prettier --write **/*.html --plugin=prettier-plugin-askama-template
``` ```

6
package-lock.json generated
View file

@ -1,11 +1,11 @@
{ {
"name": "prettier-plugin-jinja-template", "name": "prettier-plugin-askama-template",
"version": "1.0.0", "version": "1.0.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "prettier-plugin-jinja-template", "name": "prettier-plugin-askama-template",
"version": "1.0.0", "version": "1.0.0",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
@ -17,7 +17,7 @@
"typescript": "^5.1.6" "typescript": "^5.1.6"
}, },
"peerDependencies": { "peerDependencies": {
"prettier": "^2.0.0" "prettier": "^3.0.0"
} }
}, },
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {

View file

@ -1,25 +1,23 @@
{ {
"name": "prettier-plugin-jinja-template", "name": "prettier-plugin-askama-template",
"version": "1.0.0", "version": "1.0.0",
"description": "Prettier plugin for formatting jinja templates.", "description": "prettier-plugin-jinja-template but with patches to work with Askama.",
"author": "David Odenwald", "author": "Alexander Minkin",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/davidodenwald/prettier-plugin-jinja-template.git" "url": "git+https://git.fetbuk.ru/WerySkok/prettier-plugin-askama-template.git"
}, },
"bugs": { "bugs": {
"url": "https://github.com/davidodenwald/prettier-plugin-jinja-template/issues" "url": "https://git.fetbuk.ru/WerySkok/prettier-plugin-askama-template/issues"
}, },
"homepage": "https://github.com/davidodenwald/prettier-plugin-jinja-template#readme", "homepage": "https://git.fetbuk.ru/WerySkok/prettier-plugin-askama-template#readme",
"keywords": [ "keywords": [
"prettier", "prettier",
"plugin", "plugin",
"template", "template",
"html", "html",
"jinja", "askama"
"jinja2",
"flask"
], ],
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {

View file

@ -3,14 +3,14 @@ import { parse } from "./parser";
import { print, embed, getVisitorKeys } from "./printer"; import { print, embed, getVisitorKeys } from "./printer";
import { Parser, Printer, SupportLanguage } from "prettier"; import { Parser, Printer, SupportLanguage } from "prettier";
const PLUGIN_KEY = "jinja-template"; const PLUGIN_KEY = "askama-template";
export const languages: SupportLanguage[] = [ export const languages: SupportLanguage[] = [
{ {
name: "JinjaTemplate", name: "AskamaTemplate",
parsers: [PLUGIN_KEY], parsers: [PLUGIN_KEY],
extensions: [".jinja", ".jinja2", ".j2", ".html"], extensions: [".jinja", ".jinja2", ".j2", ".html", "askama"],
vscodeLanguageIds: ["jinja"], vscodeLanguageIds: ["askama"],
}, },
]; ];

View file

@ -42,4 +42,5 @@ export const nonClosingStatements = [
"from", "from",
"extends", "extends",
"pluralize", "pluralize",
"when"
]; ];

View file

@ -5,7 +5,7 @@ import * as jinjaPlugin from "../src/index";
const prettify = (code: string, options: Options) => const prettify = (code: string, options: Options) =>
format(code, { format(code, {
parser: "jinja-template", parser: "askama-template",
plugins: [jinjaPlugin], plugins: [jinjaPlugin],
...options, ...options,
}); });