Skip to content

Commit

Permalink
remove quoteAttributes option
Browse files Browse the repository at this point in the history
Since jinjaX v0.4 the attribute syntax changed and the workaround
with not quoting attributes is no longer needed.
  • Loading branch information
David Odenwald committed Sep 29, 2024
1 parent 5a52623 commit b7df7a3
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 58 deletions.
25 changes: 2 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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
npx prettier --write **/*.html
```
Expand All @@ -43,7 +43,7 @@ npx prettier --plugin=prettier-plugin-jinja-template --parser=jinja-template --w

### Ignoring Code

Using range ignores is the best way to tell prettier to igone part of files. Most of the time this is necessary for Jinja tags inside `script` or `style` tags:
Using range ignores is the best way to tell prettier to ignore part of files. Most of the time this is necessary for Jinja tags inside `script` or `style` tags:

```html
<!-- prettier-ignore-start -->
Expand Down Expand Up @@ -74,24 +74,3 @@ Or using Jinja comments:
{# prettier-ignore-end #}
```

## Options

This Plugin provides additional options:

### Quote Attributes

Surrounds the value of html attributes with quotes. This option was introduced to support [JinjaX](https://jinjax.scaletti.dev/) syntax.

`true` - Example:
```js
<Paginator items="{products}" />
```

`false` - Example:
```js
<Paginator items={products} />
```

| Default | CLI Override | API Override |
| ------- | ----------------------- | ------------------------- |
| `true` | `--no-quote-attributes` | `quoteAttributes: <bool>` |
21 changes: 1 addition & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { Node } from "./jinja";
import { parse } from "./parser";
import { print, embed, getVisitorKeys } from "./printer";
import {
Parser,
Printer,
SupportLanguage,
SupportOptions,
ParserOptions,
} from "prettier";
import { Parser, Printer, SupportLanguage } from "prettier";

const PLUGIN_KEY = "jinja-template";

Expand Down Expand Up @@ -36,16 +30,3 @@ export const printers = {
getVisitorKeys,
},
};

export type extendedOptions = ParserOptions<Node> & {
quoteAttributes: boolean;
};

export const options: SupportOptions = {
quoteAttributes: {
type: "boolean",
category: PLUGIN_KEY,
default: true,
description: "Surrounds the value of html attributes with quotes.",
},
};
11 changes: 1 addition & 10 deletions src/printer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AstPath, Doc, Options, Printer } from "prettier";
import { builders, utils } from "prettier/doc";
import { extendedOptions } from "./index";
import { Block, Expression, Node, Placeholder, Statement } from "./jinja";

const NOT_FOUND = -1;
Expand Down Expand Up @@ -121,17 +120,9 @@ export const embed: Printer<Node>["embed"] = () => {
if (content in node.nodes) {
doc = content;
} else {
/**
* The lwc parser is the same as the "html" parser,
* but also formats LWC-specific syntax for unquoted template attributes.
*/
const parser = (options as extendedOptions).quoteAttributes
? "html"
: "lwc";

doc = await textToDoc(content, {
...options,
parser,
parser: "html",
});
}

Expand Down
3 changes: 0 additions & 3 deletions test/cases/jinjaX/config.json

This file was deleted.

1 change: 0 additions & 1 deletion test/cases/jinjaX/expected.html

This file was deleted.

1 change: 0 additions & 1 deletion test/cases/jinjaX/input.html

This file was deleted.

0 comments on commit b7df7a3

Please sign in to comment.