prettier-plugin-embed 0.4.5 → 0.4.6
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 +147 -103
- package/dist/embedded/css/options.d.ts +1 -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 +1 -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 +4 -4
- 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 +538 -528
- package/dist/options.d.ts +35 -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,236 @@ 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 specific language identifiers.
|
|
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 specific 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. |
|
|
126
149
|
|
|
127
|
-
Formatting embedded CSS
|
|
150
|
+
Formatting embedded CSS language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
128
151
|
|
|
129
|
-
|
|
152
|
+
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
153
|
|
|
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 |
|
|
154
|
+
#### ES (ECMAScript/JavaScript)
|
|
135
155
|
|
|
136
|
-
|
|
156
|
+
| Option | Type | Default | Description |
|
|
157
|
+
| :---------------------: | :-----------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------: | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
158
|
+
| `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. |
|
|
159
|
+
| `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. |
|
|
160
|
+
|
|
161
|
+
Formatting embedded ECMAScript language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
162
|
+
|
|
163
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
137
164
|
|
|
138
165
|
#### GLSL
|
|
139
166
|
|
|
140
|
-
| Option |
|
|
141
|
-
| :-----------------------: |
|
|
142
|
-
| `embeddedGlslIdentifiers` | [`[
|
|
167
|
+
| Option | Type | Default | Description |
|
|
168
|
+
| :-----------------------: | :--------: | :----------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
169
|
+
| `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
170
|
|
|
144
|
-
Formatting embedded GLSL
|
|
171
|
+
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
172
|
|
|
146
173
|
#### GraphQL
|
|
147
174
|
|
|
148
|
-
| Option |
|
|
149
|
-
| :--------------------------: |
|
|
150
|
-
| `embeddedGraphqlIdentifiers` | [`[
|
|
175
|
+
| Option | Type | Default | Description |
|
|
176
|
+
| :--------------------------: | :--------: | :-------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------- |
|
|
177
|
+
| `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. |
|
|
178
|
+
|
|
179
|
+
Formatting embedded GraphQL language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
151
180
|
|
|
152
|
-
|
|
181
|
+
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
182
|
|
|
154
183
|
#### HTML
|
|
155
184
|
|
|
156
|
-
| Option |
|
|
157
|
-
| :-----------------------: |
|
|
158
|
-
| `embeddedHtmlIdentifiers` | [`[
|
|
185
|
+
| Option | Type | Default | Description |
|
|
186
|
+
| :-----------------------: | :-----------------------------------------------------------------------: | :---------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------- |
|
|
187
|
+
| `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. |
|
|
188
|
+
| `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. |
|
|
189
|
+
|
|
190
|
+
Formatting embedded HTML language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
191
|
+
|
|
192
|
+
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
193
|
|
|
160
|
-
|
|
194
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
161
195
|
|
|
162
196
|
#### INI
|
|
163
197
|
|
|
164
|
-
| Option |
|
|
165
|
-
| :----------------------: |
|
|
166
|
-
| `embeddedIniIdentifiers` | [`[
|
|
198
|
+
| Option | Type | Default | Description |
|
|
199
|
+
| :----------------------: | :--------: | :------------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
200
|
+
| `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
201
|
|
|
168
|
-
Formatting embedded INI
|
|
202
|
+
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
203
|
|
|
170
204
|
#### JSON
|
|
171
205
|
|
|
172
|
-
| Option |
|
|
173
|
-
| :-----------------------: |
|
|
174
|
-
| `embeddedJsonIdentifiers` | [`[
|
|
175
|
-
| `embeddedJsonParser` | [`"json"`](./src/embedded/json/options.ts) | The parser used to parse the JSON
|
|
206
|
+
| Option | Type | Default | Description |
|
|
207
|
+
| :-----------------------: | :----------------------------------------------------------------------------------: | :---------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------- |
|
|
208
|
+
| `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. |
|
|
209
|
+
| `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
210
|
|
|
177
|
-
Formatting embedded JSON
|
|
211
|
+
Formatting embedded JSON language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
212
|
+
|
|
213
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
178
214
|
|
|
179
215
|
#### LaTeX
|
|
180
216
|
|
|
181
|
-
| Option |
|
|
182
|
-
| :------------------------: |
|
|
183
|
-
| `embeddedLatexIdentifiers` | [`[
|
|
217
|
+
| Option | Type | Default | Description |
|
|
218
|
+
| :------------------------: | :--------: | :---------------------------------------------------------------------------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
219
|
+
| `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
220
|
|
|
185
|
-
Formatting embedded LaTeX
|
|
221
|
+
Formatting embedded LaTeX language requires the [`prettier-plugin-latex`](https://github.com/siefkenj/prettier-plugin-latex) plugin to be loaded as well.
|
|
186
222
|
|
|
187
223
|
#### Markdown
|
|
188
224
|
|
|
189
|
-
| Option |
|
|
190
|
-
| :---------------------------: |
|
|
191
|
-
| `embeddedMarkdownIdentifiers` | [`[
|
|
225
|
+
| Option | Type | Default | Description |
|
|
226
|
+
| :---------------------------: | :--------: | :--------------------------------------------------------: | -------------------------------------------------------------------------------------------------------------------- |
|
|
227
|
+
| `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. |
|
|
228
|
+
|
|
229
|
+
Formatting embedded Markdown language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
192
230
|
|
|
193
|
-
|
|
231
|
+
This can override the native formatting for embedded Markdown language. If you want to keep the native behavior, set `embeddedMarkdownIdentifiers` to `[]` or other identifiers.
|
|
194
232
|
|
|
195
233
|
#### PHP
|
|
196
234
|
|
|
197
|
-
| Option |
|
|
198
|
-
| :----------------------: |
|
|
199
|
-
| `embeddedPhpIdentifiers` | [`[
|
|
235
|
+
| Option | Type | Default | Description |
|
|
236
|
+
| :----------------------: | :--------: | :------------------------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
237
|
+
| `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
238
|
|
|
201
|
-
Formatting embedded PHP
|
|
239
|
+
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
240
|
|
|
203
241
|
#### Properties
|
|
204
242
|
|
|
205
|
-
| Option |
|
|
206
|
-
| :-----------------------------: |
|
|
207
|
-
| `embeddedPropertiesIdentifiers` | [`[
|
|
243
|
+
| Option | Type | Default | Description |
|
|
244
|
+
| :-----------------------------: | :--------: | :------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
245
|
+
| `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
246
|
|
|
209
|
-
Formatting embedded
|
|
247
|
+
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
248
|
|
|
211
249
|
#### Ruby
|
|
212
250
|
|
|
213
|
-
| Option |
|
|
214
|
-
| :-----------------------: |
|
|
215
|
-
| `embeddedRubyIdentifiers` |
|
|
216
|
-
| `embeddedRubyParser` | [`
|
|
251
|
+
| Option | Type | Default | Description |
|
|
252
|
+
| :-----------------------: | :-----------------------------------------------------------: | :------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
253
|
+
| `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. |
|
|
254
|
+
| `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. |
|
|
217
255
|
|
|
218
|
-
Formatting embedded Ruby
|
|
256
|
+
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.
|
|
219
257
|
|
|
220
|
-
|
|
258
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
221
259
|
|
|
222
|
-
|
|
223
|
-
| :---------------------: | :-------------------------------------: | --------------------------------------------------------------------------------------------------- |
|
|
224
|
-
| `embeddedShIdentifiers` | [`[...]`](./src/embedded/sh/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as Shell code |
|
|
260
|
+
#### Sh (Shell)
|
|
225
261
|
|
|
226
|
-
|
|
262
|
+
| Option | Type | Default | Description |
|
|
263
|
+
| :---------------------: | :--------: | :--------------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
264
|
+
| `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. |
|
|
227
265
|
|
|
228
|
-
|
|
266
|
+
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.
|
|
267
|
+
|
|
268
|
+
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
269
|
|
|
230
270
|
#### SQL
|
|
231
271
|
|
|
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) |
|
|
272
|
+
| Option | Type | Default | Description |
|
|
273
|
+
| :----------------------: | :------------------------------------------------------------------------------------------------: | :------------------------------------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
274
|
+
| `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. |
|
|
275
|
+
| `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. |
|
|
276
|
+
| `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
277
|
|
|
238
|
-
Formatting embedded SQL
|
|
278
|
+
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
279
|
|
|
240
|
-
Note that `prettier-plugin-sql` supports many different SQL dialects
|
|
280
|
+
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
281
|
|
|
242
282
|
#### TOML
|
|
243
283
|
|
|
244
|
-
| Option |
|
|
245
|
-
| :-----------------------: |
|
|
246
|
-
| `embeddedTomlIdentifiers` | [`[
|
|
284
|
+
| Option | Type | Default | Description |
|
|
285
|
+
| :-----------------------: | :--------: | :------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
286
|
+
| `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. |
|
|
287
|
+
|
|
288
|
+
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
289
|
|
|
248
|
-
|
|
290
|
+
#### TS (TypeScript)
|
|
249
291
|
|
|
250
|
-
|
|
292
|
+
| Option | Type | Default | Description |
|
|
293
|
+
| :---------------------: | :----------------------------------------------------------: | :-------------------------------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------------- |
|
|
294
|
+
| `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. |
|
|
295
|
+
| `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
296
|
|
|
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 |
|
|
297
|
+
Formatting embedded TypeScript language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
256
298
|
|
|
257
|
-
|
|
299
|
+
If you want to specify different parsers for different identifiers, check [`embeddedOverrides`](#embeddedoverrides).
|
|
258
300
|
|
|
259
301
|
#### XML
|
|
260
302
|
|
|
261
|
-
| Option |
|
|
262
|
-
| :----------------------: |
|
|
263
|
-
| `embeddedXmlIdentifiers` | [`[
|
|
303
|
+
| Option | Type | Default | Description |
|
|
304
|
+
| :----------------------: | :--------: | :--------------------------------------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
305
|
+
| `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
306
|
|
|
265
|
-
Formatting embedded XML
|
|
307
|
+
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
308
|
|
|
267
309
|
#### YAML
|
|
268
310
|
|
|
269
|
-
| Option |
|
|
270
|
-
| :-----------------------: |
|
|
271
|
-
| `embeddedYamlIdentifiers` | [`[
|
|
311
|
+
| Option | Type | Default | Description |
|
|
312
|
+
| :-----------------------: | :--------: | :-------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------- |
|
|
313
|
+
| `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
314
|
|
|
273
|
-
Formatting embedded YAML
|
|
315
|
+
Formatting embedded YAML language doesn't require other plugins and uses the parsers and printers provided by Prettier natively.
|
|
274
316
|
|
|
275
317
|
</details>
|
|
276
318
|
|
|
277
319
|
### Language-Agnostic Options
|
|
278
320
|
|
|
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.
|
|
321
|
+
| Option | Type | Default | Description |
|
|
322
|
+
| :-----------------------------------: | :--------: | :---------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
323
|
+
| `noEmbeddedIdentificationByComment` | `string[]` | `[]` | Turns off `` /* identifier */ `...` `` comment-based embedded language identification for the specified identifiers. |
|
|
324
|
+
| `noEmbeddedIdentificationByTag` | `string[]` | `[]` | Turns off `` identifier`...` `` tag-based embedded language identification for the specified identifiers. |
|
|
325
|
+
| `preserveEmbeddedExteriorWhitespaces` | `string[]` | `[]` | Preserves leading and trailing whitespaces in the formatting results for the specified identifiers. |
|
|
326
|
+
| `noEmbeddedMultiLineIndentation` | `string[]` | `[]` | Turns off auto indentation in the formatting results when they are formatted to span multi lines for the specified identifiers. |
|
|
327
|
+
| `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
328
|
|
|
287
329
|
#### `embeddedOverrides`
|
|
288
330
|
|
|
@@ -290,7 +332,7 @@ This option is provided for users to override certain options based on identifie
|
|
|
290
332
|
|
|
291
333
|
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
334
|
|
|
293
|
-
In a json file, the root is the array of objects. In a
|
|
335
|
+
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
336
|
|
|
295
337
|
An example `.json` file is:
|
|
296
338
|
|
|
@@ -311,7 +353,9 @@ An example `.json` file is:
|
|
|
311
353
|
]
|
|
312
354
|
```
|
|
313
355
|
|
|
314
|
-
|
|
356
|
+
> [!CAUTION]
|
|
357
|
+
>
|
|
358
|
+
> 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
359
|
|
|
316
360
|
## Contributing
|
|
317
361
|
|
|
@@ -19,7 +19,7 @@ export declare const options: {
|
|
|
19
19
|
readonly default: [{
|
|
20
20
|
readonly value: ["css"];
|
|
21
21
|
}];
|
|
22
|
-
readonly description: "
|
|
22
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded CSS language.";
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
type Options = typeof options;
|
|
@@ -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;
|
|
@@ -20,7 +20,7 @@ export declare const options: {
|
|
|
20
20
|
readonly default: [{
|
|
21
21
|
readonly value: ["md", "markdown"];
|
|
22
22
|
}];
|
|
23
|
-
readonly description: "
|
|
23
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded Markdown language.";
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
type Options = typeof options;
|
|
@@ -10,7 +10,7 @@ export declare const options: {
|
|
|
10
10
|
readonly default: [{
|
|
11
11
|
readonly value: [];
|
|
12
12
|
}];
|
|
13
|
-
readonly description: "
|
|
13
|
+
readonly description: "Tag or comment identifiers that prevent their subsequent template literals from being identified as embedded languages and thus from being formatted.";
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
type Options = typeof options;
|
|
@@ -22,7 +22,7 @@ export declare const options: {
|
|
|
22
22
|
readonly default: [{
|
|
23
23
|
readonly value: ["php", "php5"];
|
|
24
24
|
}];
|
|
25
|
-
readonly description: "
|
|
25
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded PHP language. This option requires the `@prettier/plugin-php` plugin.";
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
type Options = typeof options;
|
|
@@ -20,7 +20,7 @@ export declare const options: {
|
|
|
20
20
|
readonly default: [{
|
|
21
21
|
readonly value: ["properties"];
|
|
22
22
|
}];
|
|
23
|
-
readonly description: "
|
|
23
|
+
readonly description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded Properties language. This option requires the `prettier-plugin-properties` plugin.";
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
type Options = typeof options;
|