prettier-plugin-embed 0.4.5 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -103
- package/dist/embedded/css/options.d.ts +15 -1
- package/dist/embedded/es/options.d.ts +1 -1
- package/dist/embedded/glsl/options.d.ts +1 -1
- package/dist/embedded/graphql/options.d.ts +1 -1
- package/dist/embedded/html/options.d.ts +15 -1
- package/dist/embedded/ini/options.d.ts +1 -1
- package/dist/embedded/json/options.d.ts +1 -1
- package/dist/embedded/latex/options.d.ts +1 -1
- package/dist/embedded/markdown/options.d.ts +15 -1
- package/dist/embedded/noop/options.d.ts +1 -1
- package/dist/embedded/php/options.d.ts +1 -1
- package/dist/embedded/properties/options.d.ts +1 -1
- package/dist/embedded/register.d.ts +5 -5
- package/dist/embedded/ruby/options.d.ts +1 -1
- package/dist/embedded/sh/options.d.ts +3 -3
- package/dist/embedded/sql/options.d.ts +1 -1
- package/dist/embedded/toml/options.d.ts +3 -3
- package/dist/embedded/ts/options.d.ts +1 -1
- package/dist/embedded/xml/options.d.ts +2 -2
- package/dist/embedded/yaml/options.d.ts +1 -1
- package/dist/index.js +754 -724
- package/dist/options.d.ts +55 -25
- package/dist/types.d.ts +2 -1
- package/dist/utils.d.ts +4 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
# Prettier Plugin Embed
|
|
6
6
|
|
|
7
|
-
[](https://www.npmjs.com/package/prettier-plugin-embed/v/latest) [](https://www.npmjs.com/package/prettier-plugin-embed/v/latest) [](https://www.npmjs.com/package/prettier-plugin-embed/v/latest)
|
|
8
8
|
|
|
9
|
-
[](https://github.com/Sec-ant/prettier-plugin-embed) [](https://bundlephobia.com/package/prettier-plugin-embed@latest) [](https://www.jsdelivr.com/package/npm/prettier-plugin-embed)
|
|
10
10
|
|
|
11
11
|
A Configurable [Prettier](https://prettier.io/) [Plugin](https://prettier.io/docs/en/plugins.html) to Format [Embedded Languages](https://prettier.io/docs/en/options.html#embedded-language-formatting) in `js`/`ts` Files.
|
|
12
12
|
|
|
@@ -95,194 +95,244 @@ To use this plugin, [`embedded-language-formatting`](https://prettier.io/docs/en
|
|
|
95
95
|
|
|
96
96
|
This plugin does not aim to implement parsers or printers to support every newly added embedded language. Instead, ideally, it makes use of existing [Prettier plugins](https://prettier.io/docs/en/plugins.html#official-plugins) for those languages and only adds formatting support when they are embedded in template literals.
|
|
97
97
|
|
|
98
|
-
Therefore, to enable formatting for a specific embedded language, the corresponding Prettier plugin for that language must also be loaded. For example, if you wish to format embedded XML
|
|
98
|
+
Therefore, to enable formatting for a specific embedded language, the corresponding Prettier plugin for that language must also be loaded. For example, if you wish to format embedded XML language, you will need to load both this plugin and [`@prettier/plugin-xml`](https://github.com/prettier/plugin-xml). To find out which other plugins are required when using this plugin, please refer to the [Language-Specific Options](#language-specific-options) section below.
|
|
99
99
|
|
|
100
|
-
Embedded languages to be formatted are required to be enclosed in the template literals, and are identified by the preceding [tags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) `` identifier`...` `` or [block comments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#block_comments) `` /* identifier */ `...` ``. This plugin comes pre-configured with a built-in set of identifiers for identifying various embedded languages. For instance, using identifiers like `xml` or `svg` will trigger automatic formatting for the embedded XML
|
|
100
|
+
Embedded languages to be formatted are required to be enclosed in the template literals, and are identified by the preceding [tags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) `` identifier`...` `` or [block comments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#block_comments) `` /* identifier */ `...` ``. This plugin comes pre-configured with a built-in set of identifiers for identifying various embedded languages. For instance, using identifiers like `xml` or `svg` will trigger automatic formatting for the embedded XML language. You can specify an alternative list of identifiers using the `embeddedXmlIdentifiers` option. The naming convention for these options follows the pattern of `embedded<Language>Identifiers` for other languages as well. Further details on these options and how to configure them are also available in the [Language-Specific Options](#language-specific-options) section.
|
|
101
101
|
|
|
102
102
|
To exclude certain identifiers from being identified, including the default ones supported by the [`embedded-language-formatting`](https://prettier.io/docs/en/options.html#embedded-language-formatting) option, add them to the list of the `embeddedNoopIdentifiers` option. Any matching identifiers listed in this option will take precedence over other `embedded<Language>Identifiers` options, effectively disabling their formatting.
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
> [!IMPORTANT]
|
|
105
|
+
>
|
|
106
|
+
> Until this notice is removed, always specify identifiers explicitly and do not rely on the built-in defaults, as they may be subject to change.
|
|
105
107
|
|
|
106
108
|
### Language-Specific Options
|
|
107
109
|
|
|
108
|
-
|
|
110
|
+
Supported embedded languages are:
|
|
111
|
+
|
|
112
|
+
- [CSS](#css)
|
|
113
|
+
- [ES (ECMAScript/JavaScript)](#es-ecmascriptjavascript)
|
|
114
|
+
- [GLSL](#glsl)
|
|
115
|
+
- [GraphQL](#graphql)
|
|
116
|
+
- [HTML](#html)
|
|
117
|
+
- [INI](#ini)
|
|
118
|
+
- [JSON](#json)
|
|
119
|
+
- [LaTeX](#latex)
|
|
120
|
+
- [Markdown](#markdown)
|
|
121
|
+
- [PHP](#php)
|
|
122
|
+
- [Properties](#properties)
|
|
123
|
+
- [Ruby](#ruby)
|
|
124
|
+
- [Sh (Shell)](#sh-shell)
|
|
125
|
+
- [SQL](#sql)
|
|
126
|
+
- [TOML](#TOML)
|
|
127
|
+
- [TS (TypeScript)](#ts-typescript)
|
|
128
|
+
- [XML](#xml)
|
|
129
|
+
- [YAML](#yaml)
|
|
130
|
+
|
|
131
|
+
<details open>
|
|
109
132
|
<summary>
|
|
110
|
-
Click Here
|
|
133
|
+
Click Here to Toggle
|
|
111
134
|
</summary>
|
|
112
135
|
|
|
113
136
|
#### NOOP
|
|
114
137
|
|
|
115
|
-
| Option |
|
|
116
|
-
| :-----------------------: |
|
|
117
|
-
| `embeddedNoopIdentifiers` |
|
|
138
|
+
| Option | Type | Default | Description |
|
|
139
|
+
| :-----------------------: | :--------: | :------------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
140
|
+
| `embeddedNoopIdentifiers` | `string[]` | [`[]`](./src/embedded/noop/options.ts) | Tag or comment identifiers that prevent their subsequent template literals from being identified as embedded languages and thus from being formatted. |
|
|
118
141
|
|
|
119
|
-
This doesn't require other plugins and can override the native embedded language formatting. It serves as a way to turn off embedded language formatting for
|
|
142
|
+
This option doesn't require other plugins and can override the native embedded language formatting. It serves as a way to turn off embedded language formatting for the specified language identifiers.
|
|
120
143
|
|
|
121
144
|
#### CSS
|
|
122
145
|
|
|
123
|
-
| Option |
|
|
124
|
-
| :----------------------: |
|
|
125
|
-
| `embeddedCssIdentifiers` | [`[
|
|
146
|
+
| Option | Type | Default | Description |
|
|
147
|
+
| :----------------------: | :----------------------------------------------------------: | :----------------------------------------: | --------------------------------------------------------------------------------------------------------------- |
|
|
148
|
+
| `embeddedCssIdentifiers` | `string[]` | [`["css"]`](./src/embedded/css/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded CSS language. |
|
|
149
|
+
| `embeddedCssParser` | [`"css" \| "less"\| "scss"`](./src/embedded/css/options.ts) | [`"scss"`](./src/embedded/css/options.ts) | The parser used to parse the embedded CSS language. |
|
|
126
150
|
|
|
127
|
-
Formatting embedded CSS
|
|
151
|
+
Formatting embedded CSS language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
128
152
|
|
|
129
|
-
|
|
153
|
+
This can override the native formatting bahavior for embedded CSS language. If you want to keep the native behavior, set `embeddedCssIdentifiers` to `[]` or other identifiers.
|
|
130
154
|
|
|
131
|
-
|
|
132
|
-
| :---------------------: | :---------------------------------------: | --------------------------------------------------------------------------------------------------------------------- |
|
|
133
|
-
| `embeddedEsIdentifiers` | [`[...]`](./src/embedded/es/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as ECMAScript (JavaScript) code |
|
|
134
|
-
| `embeddedEsParser` | [`"babel"`](./src/embedded/es/options.ts) | The parser used to parse the ECMASCript (JavaScript) code |
|
|
155
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
135
156
|
|
|
136
|
-
|
|
157
|
+
#### ES (ECMAScript/JavaScript)
|
|
158
|
+
|
|
159
|
+
| Option | Type | Default | Description |
|
|
160
|
+
| :---------------------: | :-----------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------: | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
161
|
+
| `embeddedEsIdentifiers` | `string[]` | [`["js", "jsx", "es", "es6", "mjs", "cjs", "pac", "javascript"]`](./src/embedded/es/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded ECMAScript/JavaScript language. |
|
|
162
|
+
| `embeddedEsParser` | [`"babel" \| "babel-flow" \| "acorn" \| "espree" \| "flow" \| "meriyah"`](./src/embedded/es/options.ts) | [`"babel"`](./src/embedded/es/options.ts) | The parser used to parse the embedded ECMASCript/JavaScript language. |
|
|
163
|
+
|
|
164
|
+
Formatting embedded ECMAScript language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
165
|
+
|
|
166
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
137
167
|
|
|
138
168
|
#### GLSL
|
|
139
169
|
|
|
140
|
-
| Option |
|
|
141
|
-
| :-----------------------: |
|
|
142
|
-
| `embeddedGlslIdentifiers` | [`[
|
|
170
|
+
| Option | Type | Default | Description |
|
|
171
|
+
| :-----------------------: | :--------: | :----------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
172
|
+
| `embeddedGlslIdentifiers` | `string[]` | [`["glsl", "shader"]`](./src/embedded/glsl/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded GLSL language. This option requires the `prettier-plugin-glsl` plugin. |
|
|
143
173
|
|
|
144
|
-
Formatting embedded GLSL
|
|
174
|
+
Formatting embedded GLSL language requires the [`prettier-plugin-glsl`](https://github.com/NaridaL/glsl-language-toolkit/tree/main/packages/prettier-plugin-glsl) plugin to be loaded as well.
|
|
145
175
|
|
|
146
176
|
#### GraphQL
|
|
147
177
|
|
|
148
|
-
| Option |
|
|
149
|
-
| :--------------------------: |
|
|
150
|
-
| `embeddedGraphqlIdentifiers` | [`[
|
|
178
|
+
| Option | Type | Default | Description |
|
|
179
|
+
| :--------------------------: | :--------: | :-------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------- |
|
|
180
|
+
| `embeddedGraphqlIdentifiers` | `string[]` | [`["graphql", "gql"]`](./src/embedded/graphql/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded GraphQL language. |
|
|
151
181
|
|
|
152
|
-
Formatting embedded GraphQL
|
|
182
|
+
Formatting embedded GraphQL language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
183
|
+
|
|
184
|
+
This can override the native formatting behavior for embedded GraphQL language. If you want to keep the native behavior, set `embeddedGraphqlIdentifiers` to `[]` or other identifiers.
|
|
153
185
|
|
|
154
186
|
#### HTML
|
|
155
187
|
|
|
156
|
-
| Option |
|
|
157
|
-
| :-----------------------: |
|
|
158
|
-
| `embeddedHtmlIdentifiers` | [`[
|
|
188
|
+
| Option | Type | Default | Description |
|
|
189
|
+
| :-----------------------: | :-----------------------------------------------------------------------: | :---------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------- |
|
|
190
|
+
| `embeddedHtmlIdentifiers` | `string[]` | [`["html", "xhtml"]`](./src/embedded/html/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded HTML language. |
|
|
191
|
+
| `embeddedHtmlParser` | [`"html" \| "vue" \| "angular" \| "lwc"`](./src/embedded/html/options.ts) | [`"html"`](./src/embedded/html/options.ts) | The parser used to parse the embedded HTML language. |
|
|
192
|
+
|
|
193
|
+
Formatting embedded HTML language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
194
|
+
|
|
195
|
+
This can override the native formatting behavior for embedded HTML language. If you want to keep the native behavior, set `embeddedHtmlIdentifiers` to `[]` or other identifiers.
|
|
159
196
|
|
|
160
|
-
|
|
197
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
161
198
|
|
|
162
199
|
#### INI
|
|
163
200
|
|
|
164
|
-
| Option |
|
|
165
|
-
| :----------------------: |
|
|
166
|
-
| `embeddedIniIdentifiers` | [`[
|
|
201
|
+
| Option | Type | Default | Description |
|
|
202
|
+
| :----------------------: | :--------: | :------------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
203
|
+
| `embeddedIniIdentifiers` | `string[]` | [`["ini", "cfg", "pro"]`](./src/embedded/ini/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded INI language. This option requires the `prettier-plugin-ini` plugin. |
|
|
167
204
|
|
|
168
|
-
Formatting embedded INI
|
|
205
|
+
Formatting embedded INI language requires the [`prettier-plugin-ini`](https://github.com/kddnewton/prettier-plugin-ini) plugin to be loaded as well. And [options](https://github.com/kddnewton/prettier-plugin-ini#configuration) supported by `prettier-plugin-ini` can therefore be used to further control the formatting behavior.
|
|
169
206
|
|
|
170
207
|
#### JSON
|
|
171
208
|
|
|
172
|
-
| Option |
|
|
173
|
-
| :-----------------------: |
|
|
174
|
-
| `embeddedJsonIdentifiers` | [`[
|
|
175
|
-
| `embeddedJsonParser` | [`"json"`](./src/embedded/json/options.ts) | The parser used to parse the JSON
|
|
209
|
+
| Option | Type | Default | Description |
|
|
210
|
+
| :-----------------------: | :----------------------------------------------------------------------------------: | :---------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------- |
|
|
211
|
+
| `embeddedJsonIdentifiers` | `string[]` | [`["json", "jsonl"]`](./src/embedded/json/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded JSON language. |
|
|
212
|
+
| `embeddedJsonParser` | [`"json" \| "json5" \| "jsonc" \| "json-stringify"`](./src/embedded/json/options.ts) | [`"json"`](./src/embedded/json/options.ts) | The parser used to parse the embedded JSON language. |
|
|
176
213
|
|
|
177
|
-
Formatting embedded JSON
|
|
214
|
+
Formatting embedded JSON language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
215
|
+
|
|
216
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
178
217
|
|
|
179
218
|
#### LaTeX
|
|
180
219
|
|
|
181
|
-
| Option |
|
|
182
|
-
| :------------------------: |
|
|
183
|
-
| `embeddedLatexIdentifiers` | [`[
|
|
220
|
+
| Option | Type | Default | Description |
|
|
221
|
+
| :------------------------: | :--------: | :---------------------------------------------------------------------------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
222
|
+
| `embeddedLatexIdentifiers` | `string[]` | [`["latex", "tex", "aux", "cls", "bbl", "bib", "toc", "sty"]`](./src/embedded/latex/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded LaTeX language. This option requires the `prettier-plugin-latex` plugin. |
|
|
184
223
|
|
|
185
|
-
Formatting embedded LaTeX
|
|
224
|
+
Formatting embedded LaTeX language requires the [`prettier-plugin-latex`](https://github.com/siefkenj/prettier-plugin-latex) plugin to be loaded as well.
|
|
186
225
|
|
|
187
226
|
#### Markdown
|
|
188
227
|
|
|
189
|
-
| Option |
|
|
190
|
-
| :---------------------------: |
|
|
191
|
-
| `embeddedMarkdownIdentifiers` | [`[
|
|
228
|
+
| Option | Type | Default | Description |
|
|
229
|
+
| :---------------------------: | :---------------------------------------------------------------------: | :--------------------------------------------------------: | -------------------------------------------------------------------------------------------------------------------- |
|
|
230
|
+
| `embeddedMarkdownIdentifiers` | `string[]` | [`["md", "markdown"]`](./src/embedded/markdown/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded Markdown language. |
|
|
231
|
+
| `embeddedMarkdownParser` | [`"markdown" \| "mdx"\| "remark"`](./src/embedded/markdown/options.ts) | [`"markdown"`](./src/embedded/markdown/options.ts) | The parser used to parse the embedded Markdown language. |
|
|
232
|
+
|
|
233
|
+
Formatting embedded Markdown language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
234
|
+
|
|
235
|
+
This can override the native formatting for embedded Markdown language. If you want to keep the native behavior, set `embeddedMarkdownIdentifiers` to `[]` or other identifiers.
|
|
192
236
|
|
|
193
|
-
|
|
237
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
238
|
+
|
|
239
|
+
The `remark` parser is [an alias of the `markdown` parser](https://github.com/prettier/prettier/blob/ed23dacc9e655c3876971b30859497b17ff2cf9f/src/language-markdown/parser-markdown.js#L57).
|
|
194
240
|
|
|
195
241
|
#### PHP
|
|
196
242
|
|
|
197
|
-
| Option |
|
|
198
|
-
| :----------------------: |
|
|
199
|
-
| `embeddedPhpIdentifiers` | [`[
|
|
243
|
+
| Option | Type | Default | Description |
|
|
244
|
+
| :----------------------: | :--------: | :------------------------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
245
|
+
| `embeddedPhpIdentifiers` | `string[]` | [`["php", "php5"]`](./src/embedded/php/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded PHP language. This option requires the `@prettier/plugin-php` plugin. |
|
|
200
246
|
|
|
201
|
-
Formatting embedded PHP
|
|
247
|
+
Formatting embedded PHP language requires the [`@prettier/plugin-php`](https://github.com/prettier/plugin-php) plugin to be loaded as well. And [options](https://github.com/prettier/plugin-php#configuration) supported by `@prettier/plugin-php` can therefore be used to further control the formatting behavior.
|
|
202
248
|
|
|
203
249
|
#### Properties
|
|
204
250
|
|
|
205
|
-
| Option |
|
|
206
|
-
| :-----------------------------: |
|
|
207
|
-
| `embeddedPropertiesIdentifiers` | [`[
|
|
251
|
+
| Option | Type | Default | Description |
|
|
252
|
+
| :-----------------------------: | :--------: | :------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
253
|
+
| `embeddedPropertiesIdentifiers` | `string[]` | [`["properties"]`](./src/embedded/properties/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded Properties language. This option requires the `prettier-plugin-properties` plugin. |
|
|
208
254
|
|
|
209
|
-
Formatting embedded
|
|
255
|
+
Formatting embedded Properties language requires the [`prettier-plugin-properties`](https://github.com/eemeli/prettier-plugin-properties) plugin to be loaded as well. And [options](https://github.com/eemeli/prettier-plugin-properties#configuration) supported by `prettier-plugin-properties` can therefore be used to further control the formatting behavior.
|
|
210
256
|
|
|
211
257
|
#### Ruby
|
|
212
258
|
|
|
213
|
-
| Option |
|
|
214
|
-
| :-----------------------: |
|
|
215
|
-
| `embeddedRubyIdentifiers` |
|
|
216
|
-
| `embeddedRubyParser` | [`
|
|
259
|
+
| Option | Type | Default | Description |
|
|
260
|
+
| :-----------------------: | :-----------------------------------------------------------: | :------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
261
|
+
| `embeddedRubyIdentifiers` | `string[]` | [`["ruby"]`](./src/embedded/ruby/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded Ruby language. This option requires the `@prettier/plugin-ruby` plugin. |
|
|
262
|
+
| `embeddedRubyParser` | [`"ruby" \| "rbs" \| "haml"`](./src/embedded/ruby/options.ts) | [`"ruby"`](./src/embedded/ruby/options.ts) | The parser used to parse the embedded Ruby language. This option requires the `@prettier/plugin-ruby` plugin. |
|
|
263
|
+
|
|
264
|
+
Formatting embedded Ruby language requires the [`@prettier/plugin-ruby`](https://github.com/prettier/plugin-ruby) to be loaded and [its dependencies to be installed](https://github.com/prettier/plugin-ruby#getting-started) as well. And [options](https://github.com/prettier/plugin-ruby#configuration) supported by `@prettier/plugin-ruby` can therefore be used to further control the formatting behavior.
|
|
217
265
|
|
|
218
|
-
|
|
266
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
219
267
|
|
|
220
|
-
#### Shell
|
|
268
|
+
#### Sh (Shell)
|
|
221
269
|
|
|
222
|
-
| Option | Default
|
|
223
|
-
| :---------------------: |
|
|
224
|
-
| `embeddedShIdentifiers` | [`[
|
|
270
|
+
| Option | Type | Default | Description |
|
|
271
|
+
| :---------------------: | :--------: | :--------------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
272
|
+
| `embeddedShIdentifiers` | `string[]` | [`["sh"]`](./src/embedded/sh/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded Shell language. This option requires the `prettier-plugin-sh` plugin. |
|
|
225
273
|
|
|
226
|
-
Formatting embedded Shell
|
|
274
|
+
Formatting embedded Shell language requires the [`prettier-plugin-sh`](https://github.com/un-ts/prettier/tree/master/packages/sh#readme) plugin to be loaded as well. And [options](https://github.com/un-ts/prettier/tree/master/packages/sh#parser-options) supported by `prettier-plugin-sh` can therefore be used to further control the formatting behavior.
|
|
227
275
|
|
|
228
|
-
Note that `prettier-plugin-sh` supports different variants of shell syntaxes and they are specified by the [`variant` option](https://github.com/un-ts/prettier/tree/master/packages/sh#parser-options).
|
|
276
|
+
Note that `prettier-plugin-sh` supports different variants of shell syntaxes and they are specified by the [`variant` option](https://github.com/un-ts/prettier/tree/master/packages/sh#parser-options). If you want to specify different variants for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
229
277
|
|
|
230
278
|
#### SQL
|
|
231
279
|
|
|
232
|
-
| Option | Default | Description
|
|
233
|
-
| :----------------------: | :------------------------------------------------------: |
|
|
234
|
-
| `embeddedSqlIdentifiers` |
|
|
235
|
-
| `embeddedSqlPlugin` | [`"prettier-plugin-sql"`](./src/embedded/sql/options.ts) | The plugin used to format the SQL
|
|
236
|
-
| `embeddedSqlParser` | [`"sqlite"`](./src/embedded/sql/options.ts) |
|
|
280
|
+
| Option | Type | Default | Description |
|
|
281
|
+
| :----------------------: | :------------------------------------------------------------------------------------------------: | :------------------------------------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
282
|
+
| `embeddedSqlIdentifiers` | `string[]` | [`["sql"]`](./src/embedded/sql/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded SQL language. This option requires the `prettier-plugin-sql` plugin or the `prettier-plugin-sql-cst` plugin. |
|
|
283
|
+
| `embeddedSqlPlugin` | [`"prettier-plugin-sql" \| "prettier-plugin-sql-cst"`](./src/embedded/sql/options.ts) | [`"prettier-plugin-sql"`](./src/embedded/sql/options.ts) | The plugin used to format the embedded SQL language. This option requires the `prettier-plugin-sql` plugin or the `prettier-plugin-sql-cst` plugin. |
|
|
284
|
+
| `embeddedSqlParser` | [`"sqlite" \| "bigquery" \| "mysql" \| "mariadb" \| "postgresql"` ](./src/embedded/sql/options.ts) | [`"sqlite"`](./src/embedded/sql/options.ts) | Specify the embedded SQL language parser. This option is only needed with the `prettier-plugin-sql-cst` plugin. |
|
|
237
285
|
|
|
238
|
-
Formatting embedded SQL
|
|
286
|
+
Formatting embedded SQL language requires the [`prettier-plugin-sql`](https://github.com/un-ts/prettier/tree/master/packages/sql#readme) plugin or the [`prettier-plugin-sql-cst`](https://github.com/nene/prettier-plugin-sql-cst) plugin to be loaded as well. And [options](https://github.com/un-ts/prettier/tree/master/packages/sql#parser-options) supported by `prettier-plugin-sql`, or [options](https://github.com/nene/prettier-plugin-sql-cst?tab=readme-ov-file#configuration) supported by `prettier-plugin-sql-cst` can therefore be used to further control the formatting behavior.
|
|
239
287
|
|
|
240
|
-
Note that `prettier-plugin-sql` supports many different SQL dialects
|
|
288
|
+
Note that `prettier-plugin-sql` supports many different SQL dialects which are specified by the [`language`, `database` or `dialect` option](https://github.com/un-ts/prettier/tree/master/packages/sql#parser-options). And `prettier-plugin-sql-cst` also supports various parsers as shown above. If you want to specify different dialects or parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
241
289
|
|
|
242
290
|
#### TOML
|
|
243
291
|
|
|
244
|
-
| Option |
|
|
245
|
-
| :-----------------------: |
|
|
246
|
-
| `embeddedTomlIdentifiers` | [`[
|
|
292
|
+
| Option | Type | Default | Description |
|
|
293
|
+
| :-----------------------: | :--------: | :------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
294
|
+
| `embeddedTomlIdentifiers` | `string[]` | [`["toml"]`](./src/embedded/toml/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded TOML language. This option requires the `prettier-plugin-toml` plugin. |
|
|
295
|
+
|
|
296
|
+
Formatting embedded TOML language requires the [`prettier-plugin-toml`](https://github.com/un-ts/prettier/tree/master/packages/toml#readme) plugin to be loaded as well. And options supported by `prettier-plugin-toml` can therefore be used to further control the formatting behavior.
|
|
247
297
|
|
|
248
|
-
|
|
298
|
+
#### TS (TypeScript)
|
|
249
299
|
|
|
250
|
-
|
|
300
|
+
| Option | Type | Default | Description |
|
|
301
|
+
| :---------------------: | :----------------------------------------------------------: | :-------------------------------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------------- |
|
|
302
|
+
| `embeddedTsIdentifiers` | `string[]` | [`["ts", "tsx", "cts", "mts", "typescript"]`](./src/embedded/ts/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded TypeScript language. |
|
|
303
|
+
| `embeddedTsParser` | [`"typescript" \| "babel-ts"`](./src/embedded/ts/options.ts) | [`"typescript"`](./src/embedded/ts/options.ts) | The parser used to parse the embedded TypeScript language. |
|
|
251
304
|
|
|
252
|
-
|
|
253
|
-
| :---------------------: | :--------------------------------------------: | -------------------------------------------------------------------------------------------------------- |
|
|
254
|
-
| `embeddedTsIdentifiers` | [`[...]`](./src/embedded/ts/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as TypeScript code |
|
|
255
|
-
| `embeddedTsParser` | [`"typescript"`](./src/embedded/ts/options.ts) | The parser used to parse the TypeScript code |
|
|
305
|
+
Formatting embedded TypeScript language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
256
306
|
|
|
257
|
-
|
|
307
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
258
308
|
|
|
259
309
|
#### XML
|
|
260
310
|
|
|
261
|
-
| Option |
|
|
262
|
-
| :----------------------: |
|
|
263
|
-
| `embeddedXmlIdentifiers` | [`[
|
|
311
|
+
| Option | Type | Default | Description |
|
|
312
|
+
| :----------------------: | :--------: | :--------------------------------------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
313
|
+
| `embeddedXmlIdentifiers` | `string[]` | [`["xml", "opml", "rss", "svg"]`](./src/embedded/xml/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded XML language. This option requires the `@prettier/plugin-xml` plugin. |
|
|
264
314
|
|
|
265
|
-
Formatting embedded XML
|
|
315
|
+
Formatting embedded XML language requires the [`@prettier/plugin-xml`](https://github.com/prettier/plugin-xml) plugin to be loaded as well. And [options](https://github.com/prettier/plugin-xml#configuration) supported by `@prettier/plugin-xml` can therefore be used to further control the formatting behavior.
|
|
266
316
|
|
|
267
317
|
#### YAML
|
|
268
318
|
|
|
269
|
-
| Option |
|
|
270
|
-
| :-----------------------: |
|
|
271
|
-
| `embeddedYamlIdentifiers` | [`[
|
|
319
|
+
| Option | Type | Default | Description |
|
|
320
|
+
| :-----------------------: | :--------: | :-------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------- |
|
|
321
|
+
| `embeddedYamlIdentifiers` | `string[]` | [`["yaml", "yml"]`](./src/embedded/yaml/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as embedded YAML language. |
|
|
272
322
|
|
|
273
|
-
Formatting embedded YAML
|
|
323
|
+
Formatting embedded YAML language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
274
324
|
|
|
275
325
|
</details>
|
|
276
326
|
|
|
277
327
|
### Language-Agnostic Options
|
|
278
328
|
|
|
279
|
-
| Option | Default | Description
|
|
280
|
-
| :-----------------------------------: | :---------: |
|
|
281
|
-
| `noEmbeddedIdentificationByComment` | `[]` | Turns off `` /* identifier */ `...` `` comment-based language identification for the specified identifiers
|
|
282
|
-
| `noEmbeddedIdentificationByTag` | `[]` | Turns off `` identifier`...` `` tag-based language identification for the specified identifiers
|
|
283
|
-
| `preserveEmbeddedExteriorWhitespaces` | `[]` | Preserves leading and trailing whitespaces in the formatting results for the specified identifiers
|
|
284
|
-
| `noEmbeddedMultiLineIndentation` | `[]` | Turns off auto indentation in the formatting results when they are formatted to span multi lines for the specified identifiers
|
|
285
|
-
| `embeddedOverrides` | `undefined` | Option overrides for the specified identifiers.
|
|
329
|
+
| Option | Type | Default | Description |
|
|
330
|
+
| :-----------------------------------: | :--------: | :---------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
331
|
+
| `noEmbeddedIdentificationByComment` | `string[]` | `[]` | Turns off `` /* identifier */ `...` `` comment-based embedded language identification for the specified identifiers. |
|
|
332
|
+
| `noEmbeddedIdentificationByTag` | `string[]` | `[]` | Turns off `` identifier`...` `` tag-based embedded language identification for the specified identifiers. |
|
|
333
|
+
| `preserveEmbeddedExteriorWhitespaces` | `string[]` | `[]` | Preserves leading and trailing whitespaces in the formatting results for the specified identifiers. |
|
|
334
|
+
| `noEmbeddedMultiLineIndentation` | `string[]` | `[]` | Turns off auto indentation in the formatting results when they are formatted to span multi lines for the specified identifiers. |
|
|
335
|
+
| `embeddedOverrides` | `string` | `undefined` | Option overrides for the specified identifiers. It should either be a stringified JSON or an absolute filepath to the option overrides file. See [below](#embeddedoverrides) for a detailed explanation. |
|
|
286
336
|
|
|
287
337
|
#### `embeddedOverrides`
|
|
288
338
|
|
|
@@ -290,7 +340,7 @@ This option is provided for users to override certain options based on identifie
|
|
|
290
340
|
|
|
291
341
|
The resolved value should be an array of objects. Each object in the array must have 2 fields: `identifiers` and `options`. The `options` are considerred overrides that will be applied to the global `options` of prettier for those `idenfitiers` only. It's like the [`overrides`](https://prettier.io/docs/en/configuration.html#configuration-overrides) of `prettier`, but it is identifier-based instead of file-based.
|
|
292
342
|
|
|
293
|
-
In a json file, the root is the array of objects. In a
|
|
343
|
+
In a json file, the root is the array of objects. In a JavaScript file, the array of objects should be a default export, or a named export with the name `embeddedOverrides`.
|
|
294
344
|
|
|
295
345
|
An example `.json` file is:
|
|
296
346
|
|
|
@@ -311,7 +361,9 @@ An example `.json` file is:
|
|
|
311
361
|
]
|
|
312
362
|
```
|
|
313
363
|
|
|
314
|
-
|
|
364
|
+
> [!CAUTION]
|
|
365
|
+
>
|
|
366
|
+
> Please note that not every option is supported to override. That largely depends on at which phase those options will kick in and take effect. For example, you can't override `tabWidth` in `embeddedOverrides` because this option is used in the [`printDocToString`](https://github.com/prettier/prettier/blob/7aecca5d6473d73f562ca3af874831315f8f2581/src/document/printer.js#L302) phase, where `prettier-plugin-embed` cannot override this option for only a set of specified identifiers. To find the list of unsupported options, please check the interface definition of `EmbeddedOverride` in the [source code](https://github.com/Sec-ant/prettier-plugin-embed/blob/main/src/types.ts).
|
|
315
367
|
|
|
316
368
|
## Contributing
|
|
317
369
|
|
|
@@ -8,7 +8,10 @@ import { type AutocompleteStringList, type StringListToInterfaceKey } from "../u
|
|
|
8
8
|
declare const DEFAULT_IDENTIFIERS: readonly ["css"];
|
|
9
9
|
type Identifiers = AutocompleteStringList<typeof DEFAULT_IDENTIFIERS>;
|
|
10
10
|
type DefaultIdentifiersHolder = StringListToInterfaceKey<typeof DEFAULT_IDENTIFIERS>;
|
|
11
|
+
declare const CSS_PARSERS: readonly ["css", "less", "scss"];
|
|
12
|
+
type CssParser = (typeof CSS_PARSERS)[number];
|
|
11
13
|
declare const EMBEDDED_LANGUAGE_IDENTIFIERS: "embeddedCssIdentifiers";
|
|
14
|
+
declare const EMBEDDED_LANGUAGE_PARSER: "embeddedCssParser";
|
|
12
15
|
export interface PrettierPluginDepsOptions {
|
|
13
16
|
}
|
|
14
17
|
export declare const options: {
|
|
@@ -19,7 +22,17 @@ export declare const options: {
|
|
|
19
22
|
readonly default: [{
|
|
20
23
|
readonly value: ["css"];
|
|
21
24
|
}];
|
|
22
|
-
readonly description: "
|
|
25
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded CSS language.";
|
|
26
|
+
};
|
|
27
|
+
readonly embeddedCssParser: {
|
|
28
|
+
category: string;
|
|
29
|
+
type: "choice";
|
|
30
|
+
default: "scss";
|
|
31
|
+
description: string;
|
|
32
|
+
choices: {
|
|
33
|
+
value: "css" | "less" | "scss";
|
|
34
|
+
description: string;
|
|
35
|
+
}[];
|
|
23
36
|
};
|
|
24
37
|
};
|
|
25
38
|
type Options = typeof options;
|
|
@@ -30,6 +43,7 @@ declare module "../types.js" {
|
|
|
30
43
|
}
|
|
31
44
|
interface PrettierPluginEmbedOptions {
|
|
32
45
|
[EMBEDDED_LANGUAGE_IDENTIFIERS]?: Identifiers;
|
|
46
|
+
[EMBEDDED_LANGUAGE_PARSER]?: CssParser;
|
|
33
47
|
}
|
|
34
48
|
}
|
|
35
49
|
declare module "prettier" {
|
|
@@ -22,7 +22,7 @@ export declare const options: {
|
|
|
22
22
|
readonly default: [{
|
|
23
23
|
readonly value: ["js", "jsx", "es", "es6", "mjs", "cjs", "pac", "javascript"];
|
|
24
24
|
}];
|
|
25
|
-
readonly description: "
|
|
25
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded ECMAScript/JavaScript language.";
|
|
26
26
|
};
|
|
27
27
|
readonly embeddedEsParser: {
|
|
28
28
|
category: string;
|
|
@@ -19,7 +19,7 @@ export declare const options: {
|
|
|
19
19
|
readonly default: [{
|
|
20
20
|
readonly value: ["glsl", "shader"];
|
|
21
21
|
}];
|
|
22
|
-
readonly description: "
|
|
22
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded GLSL language. This option requires the `prettier-plugin-glsl` plugin.";
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
type Options = typeof options;
|
|
@@ -18,7 +18,7 @@ export declare const options: {
|
|
|
18
18
|
readonly default: [{
|
|
19
19
|
readonly value: ["graphql", "gql"];
|
|
20
20
|
}];
|
|
21
|
-
readonly description: "
|
|
21
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded GraphQL language.";
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
type Options = typeof options;
|
|
@@ -8,7 +8,10 @@ import { type AutocompleteStringList, type StringListToInterfaceKey } from "../u
|
|
|
8
8
|
declare const DEFAULT_IDENTIFIERS: readonly ["html", "xhtml"];
|
|
9
9
|
type Identifiers = AutocompleteStringList<typeof DEFAULT_IDENTIFIERS>;
|
|
10
10
|
type DefaultIdentifiersHolder = StringListToInterfaceKey<typeof DEFAULT_IDENTIFIERS>;
|
|
11
|
+
declare const HTML_PARSERS: readonly ["html", "vue", "angular", "lwc"];
|
|
12
|
+
type HtmlParser = (typeof HTML_PARSERS)[number];
|
|
11
13
|
declare const EMBEDDED_LANGUAGE_IDENTIFIERS: "embeddedHtmlIdentifiers";
|
|
14
|
+
declare const EMBEDDED_LANGUAGE_PARSER: "embeddedHtmlParser";
|
|
12
15
|
export interface PrettierPluginDepsOptions {
|
|
13
16
|
}
|
|
14
17
|
export declare const options: {
|
|
@@ -19,7 +22,17 @@ export declare const options: {
|
|
|
19
22
|
readonly default: [{
|
|
20
23
|
readonly value: ["html", "xhtml"];
|
|
21
24
|
}];
|
|
22
|
-
readonly description: "
|
|
25
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded HTML language.";
|
|
26
|
+
};
|
|
27
|
+
readonly embeddedHtmlParser: {
|
|
28
|
+
category: string;
|
|
29
|
+
type: "choice";
|
|
30
|
+
default: "html";
|
|
31
|
+
description: string;
|
|
32
|
+
choices: {
|
|
33
|
+
value: "html" | "vue" | "angular" | "lwc";
|
|
34
|
+
description: string;
|
|
35
|
+
}[];
|
|
23
36
|
};
|
|
24
37
|
};
|
|
25
38
|
type Options = typeof options;
|
|
@@ -30,6 +43,7 @@ declare module "../types.js" {
|
|
|
30
43
|
}
|
|
31
44
|
interface PrettierPluginEmbedOptions {
|
|
32
45
|
[EMBEDDED_LANGUAGE_IDENTIFIERS]?: Identifiers;
|
|
46
|
+
[EMBEDDED_LANGUAGE_PARSER]?: HtmlParser;
|
|
33
47
|
}
|
|
34
48
|
}
|
|
35
49
|
declare module "prettier" {
|
|
@@ -19,7 +19,7 @@ export declare const options: {
|
|
|
19
19
|
readonly default: [{
|
|
20
20
|
readonly value: ["ini", "cfg", "pro"];
|
|
21
21
|
}];
|
|
22
|
-
readonly description: "
|
|
22
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded INI language. This option requires the `prettier-plugin-ini` plugin.";
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
type Options = typeof options;
|
|
@@ -21,7 +21,7 @@ export declare const options: {
|
|
|
21
21
|
readonly default: [{
|
|
22
22
|
readonly value: ["json", "jsonl"];
|
|
23
23
|
}];
|
|
24
|
-
readonly description: "
|
|
24
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded JSON language.";
|
|
25
25
|
};
|
|
26
26
|
readonly embeddedJsonParser: {
|
|
27
27
|
category: string;
|
|
@@ -18,7 +18,7 @@ export declare const options: {
|
|
|
18
18
|
readonly default: [{
|
|
19
19
|
readonly value: ["latex", "tex", "aux", "cls", "bbl", "bib", "toc", "sty"];
|
|
20
20
|
}];
|
|
21
|
-
readonly description: "
|
|
21
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded LaTeX language. This option requires the `prettier-plugin-latex` plugin.";
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
type Options = typeof options;
|