prettier-plugin-embed 0.3.0 → 0.3.2

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 CHANGED
@@ -85,6 +85,10 @@ await prettier.format(code, {
85
85
  }
86
86
  ```
87
87
 
88
+ ### Quick Start Config Examples
89
+
90
+ Here're some [quick start config examples](./ConfigExamples.md) to use this plugin for various embedded languages. Check beblow for a detailed explanation of all the available options.
91
+
88
92
  ### An Overview of the Philosophy
89
93
 
90
94
  To use this plugin, [`embedded-language-formatting`](https://prettier.io/docs/en/options.html#embedded-language-formatting) option must be set to `auto` (which is the default setting as of now), because this option serves as the main switch for activating embedded language formatting.
@@ -97,6 +101,8 @@ Embedded languages to be formatted are required to be enclosed in the template l
97
101
 
98
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.
99
103
 
104
+ **Important: 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
+
100
106
  ### Language-Specific Options
101
107
 
102
108
  <details>
@@ -129,6 +135,14 @@ Formatting embedded CSS code doesn't require other plugins and uses the parsers
129
135
 
130
136
  Formatting embedded ECMAScript code doesn't require other plugins and uses the parsers and printers provided by Prettier natively. This can override the native embedded language formatting for ECMAScript code.
131
137
 
138
+ #### GLSL
139
+
140
+ | Option | Default | Description |
141
+ | :-----------------------: | :---------------------------------------: | -------------------------------------------------------------------------------------------------- |
142
+ | `embeddedGlslIdentifiers` | [`[...]`](./src/embedded/glsl/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as GLSL code |
143
+
144
+ Formatting embedded GLSL code requires [`prettier-plugin-glsl`](https://github.com/NaridaL/glsl-language-toolkit/tree/main/packages/prettier-plugin-glsl) to be loaded as well.
145
+
132
146
  #### HTML
133
147
 
134
148
  | Option | Default | Description |
@@ -230,10 +244,6 @@ An example `.json` file is:
230
244
 
231
245
  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).
232
246
 
233
- ## Demos
234
-
235
- TBD.
236
-
237
247
  ## Contributing
238
248
 
239
249
  Bug fixes, new language support and tests are welcome. Please have a look at the project structure before getting started. Feel free to leave questions or suggestions.
@@ -6,7 +6,7 @@ import { type AutocompleteStringList, type StringListToInterfaceKey } from "../u
6
6
  declare const DEFAULT_IDENTIFIERS: readonly ["css"];
7
7
  type Identifiers = AutocompleteStringList<typeof DEFAULT_IDENTIFIERS>;
8
8
  type DefaultIdentifiersHolder = StringListToInterfaceKey<typeof DEFAULT_IDENTIFIERS>;
9
- declare const embeddedLanguageIdentifiersOptionName: "embeddedCssIdentifiers";
9
+ declare const EMBEDDED_LANGUAGE_IDENTIFIERS: "embeddedCssIdentifiers";
10
10
  export interface PrettierPluginDepsOptions {
11
11
  }
12
12
  export declare const options: {
@@ -27,7 +27,7 @@ declare module "../types.js" {
27
27
  interface EmbeddedDefaultIdentifiersHolder extends DefaultIdentifiersHolder {
28
28
  }
29
29
  interface PrettierPluginEmbedOptions {
30
- [embeddedLanguageIdentifiersOptionName]?: Identifiers;
30
+ [EMBEDDED_LANGUAGE_IDENTIFIERS]?: Identifiers;
31
31
  }
32
32
  }
33
33
  declare module "prettier" {
@@ -8,8 +8,8 @@ type Identifiers = AutocompleteStringList<typeof DEFAULT_IDENTIFIERS>;
8
8
  type DefaultIdentifiersHolder = StringListToInterfaceKey<typeof DEFAULT_IDENTIFIERS>;
9
9
  declare const DEFAULT_ES_PARSERS: readonly ["babel", "babel-flow", "acorn", "espree", "flow", "meriyah"];
10
10
  type EsParser = (typeof DEFAULT_ES_PARSERS)[number];
11
- declare const embeddedLanguageIdentifiersOptionName: "embeddedEsIdentifiers";
12
- declare const embeddedLanguageParserOptionName: "embeddedEsParser";
11
+ declare const EMBEDDED_LANGUAGE_IDENTIFIERS: "embeddedEsIdentifiers";
12
+ declare const EMBEDDED_LANGUAGE_PARSER: "embeddedEsParser";
13
13
  export interface PrettierPluginDepsOptions {
14
14
  }
15
15
  export declare const options: {
@@ -37,8 +37,8 @@ declare module "../types.js" {
37
37
  interface EmbeddedDefaultIdentifiersHolder extends DefaultIdentifiersHolder {
38
38
  }
39
39
  interface PrettierPluginEmbedOptions {
40
- [embeddedLanguageIdentifiersOptionName]?: Identifiers;
41
- [embeddedLanguageParserOptionName]?: EsParser;
40
+ [EMBEDDED_LANGUAGE_IDENTIFIERS]?: Identifiers;
41
+ [EMBEDDED_LANGUAGE_PARSER]?: EsParser;
42
42
  }
43
43
  }
44
44
  declare module "prettier" {
@@ -6,7 +6,7 @@ import { type AutocompleteStringList, type StringListToInterfaceKey } from "../u
6
6
  declare const DEFAULT_IDENTIFIERS: readonly ["md", "livemd", "markdown", "mdown", "mdwn", "mkd", "mkdn", "mkdown", "ronn", "scd", "workbook"];
7
7
  type Identifiers = AutocompleteStringList<typeof DEFAULT_IDENTIFIERS>;
8
8
  type DefaultIdentifiersHolder = StringListToInterfaceKey<typeof DEFAULT_IDENTIFIERS>;
9
- declare const embeddedLanguageIdentifiersOptionName: "embeddedMarkdownIdentifiers";
9
+ declare const EMBEDDED_LANGUAGE_IDENTIFIERS: "embeddedMarkdownIdentifiers";
10
10
  export interface PrettierPluginDepsOptions {
11
11
  __inJsTemplate?: boolean;
12
12
  }
@@ -28,7 +28,7 @@ declare module "../types.js" {
28
28
  interface EmbeddedDefaultIdentifiersHolder extends DefaultIdentifiersHolder {
29
29
  }
30
30
  interface PrettierPluginEmbedOptions {
31
- [embeddedLanguageIdentifiersOptionName]?: Identifiers;
31
+ [EMBEDDED_LANGUAGE_IDENTIFIERS]?: Identifiers;
32
32
  }
33
33
  }
34
34
  declare module "prettier" {
@@ -4,8 +4,8 @@ export declare const embeddedParsers: EmbeddedParsers;
4
4
  export declare const embeddedEmbedders: EmbeddedEmbedders;
5
5
  export declare const embeddedOptions: EmbeddedOptions;
6
6
  import * as __glob__0_0 from "./css/index.js";
7
- import * as __glob__0_1 from "./glsl/index.js";
8
- import * as __glob__0_2 from "./html/index.js";
7
+ import * as __glob__0_1 from "./html/index.js";
8
+ import * as __glob__0_2 from "./glsl/index.js";
9
9
  import * as __glob__0_3 from "./es/index.js";
10
10
  import * as __glob__0_4 from "./markdown/index.js";
11
11
  import * as __glob__0_5 from "./noop/index.js";
@@ -1,14 +1,12 @@
1
1
  import type { SqlBaseOptions as PrettierPluginDepsOptions } from "prettier-plugin-sql";
2
2
  import { type AutocompleteStringList, type StringListToInterfaceKey } from "../utils.js";
3
3
  /** References
4
- * - https://github.com/un-ts/prettier/blob/a5f1aae6464aa54749377d69a8237a70a6509a13/packages/sql/src/index.ts
4
+ * - https://github.com/un-ts/prettier/blob/master/packages/sql/src/index.ts
5
+ * "sql" is the default dialect, so we only have "sql" as the default identifier to avoid confusion.
5
6
  */
6
- export declare const SQL_FORMATTER_LANGUAGES: readonly ["sql", "bigquery", "db2", "db2i", "hive", "mariadb", "mysql", "n1ql", "postgresql", "plsql", "redshift", "singlestoredb", "snowflake", "spark", "sqlite", "transactsql", "tsql", "trino"];
7
- export declare const NODE_SQL_PARSER_DATABASES: readonly ["bigquery", "db2", "hive", "mariadb", "mysql", "postgresql", "transactsql", "flinksql", "snowflake"];
8
- type Identifiers = AutocompleteStringList<typeof SQL_FORMATTER_LANGUAGES | typeof NODE_SQL_PARSER_DATABASES>;
9
- type DefaultIdentifiersHolder = StringListToInterfaceKey<typeof SQL_FORMATTER_LANGUAGES | typeof NODE_SQL_PARSER_DATABASES>;
10
- export type SqlFormatterLanguage = (typeof SQL_FORMATTER_LANGUAGES)[number];
11
- export type NodeSqlParserDataBase = (typeof NODE_SQL_PARSER_DATABASES)[number];
7
+ declare const DEFAULT_IDENTIFIERS: readonly ["sql"];
8
+ type Identifiers = AutocompleteStringList<typeof DEFAULT_IDENTIFIERS>;
9
+ type DefaultIdentifiersHolder = StringListToInterfaceKey<typeof DEFAULT_IDENTIFIERS>;
12
10
  declare const embeddedLanguageIdentifiers: "embeddedSqlIdentifiers";
13
11
  export { PrettierPluginDepsOptions };
14
12
  export declare const options: {
@@ -17,7 +15,7 @@ export declare const options: {
17
15
  type: "string";
18
16
  array: true;
19
17
  default: {
20
- value: string[];
18
+ value: "sql"[];
21
19
  }[];
22
20
  description: string;
23
21
  };
@@ -8,8 +8,8 @@ type Identifiers = AutocompleteStringList<typeof DEFAULT_IDENTIFIERS>;
8
8
  type DefaultIdentifiersHolder = StringListToInterfaceKey<typeof DEFAULT_IDENTIFIERS>;
9
9
  declare const DEFAULT_TS_PARSERS: readonly ["typescript", "babel-ts"];
10
10
  type TsParser = (typeof DEFAULT_TS_PARSERS)[number];
11
- declare const EMBEDDED_LANGUAGE_PARSER = "embeddedTsParser";
12
- declare const embeddedLanguageIdentifiers: "embeddedTsIdentifiers";
11
+ declare const EMBEDDED_LANGUAGE_PARSER: "embeddedTsParser";
12
+ declare const EMBEDDED_LANGUAGE_IDENTIFIERS: "embeddedTsIdentifiers";
13
13
  export interface PrettierPluginDepsOptions {
14
14
  }
15
15
  export declare const options: {
@@ -37,7 +37,7 @@ declare module "../types.js" {
37
37
  interface EmbeddedDefaultIdentifiersHolder extends DefaultIdentifiersHolder {
38
38
  }
39
39
  interface PrettierPluginEmbedOptions {
40
- [embeddedLanguageIdentifiers]?: Identifiers;
40
+ [EMBEDDED_LANGUAGE_IDENTIFIERS]?: Identifiers;
41
41
  [EMBEDDED_LANGUAGE_PARSER]?: TsParser;
42
42
  }
43
43
  }