prettier-plugin-embed 0.7.3 → 0.8.0

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
@@ -4,6 +4,8 @@
4
4
 
5
5
  # Prettier Plugin Embed
6
6
 
7
+ [Online playground](https://sec-ant.github.io/prettier-plugin-embed/) · [Run the playground locally](./playground/README.md)
8
+
7
9
  [![npm version](https://img.shields.io/npm/v/prettier-plugin-embed?cacheSeconds=300)](https://www.npmjs.com/package/prettier-plugin-embed/v/latest) [![npm downloads](https://img.shields.io/npm/dm/prettier-plugin-embed?cacheSeconds=300)](https://www.npmjs.com/package/prettier-plugin-embed/v/latest) [![npm license](https://img.shields.io/npm/l/prettier-plugin-embed?cacheSeconds=300)](https://www.npmjs.com/package/prettier-plugin-embed/v/latest) [![All Contributors](https://img.shields.io/github/all-contributors/Sec-ant/prettier-plugin-embed?color=56b3b4)](#contributors)
8
10
 
9
11
  [![github last commit](https://img.shields.io/github/last-commit/Sec-ant/prettier-plugin-embed?cacheSeconds=300)](https://github.com/Sec-ant/prettier-plugin-embed) [![bundlephobia minzipped](https://img.shields.io/bundlephobia/minzip/prettier-plugin-embed?cacheSeconds=300)](https://bundlephobia.com/package/prettier-plugin-embed@latest) [![](https://img.shields.io/jsdelivr/npm/hm/prettier-plugin-embed?cacheSeconds=300&color=ff5627)](https://www.jsdelivr.com/package/npm/prettier-plugin-embed)
@@ -78,6 +80,14 @@ Projects can also use Yarn's default `pnpFallbackMode: dependencies-only` or pnp
78
80
 
79
81
  ## Usage
80
82
 
83
+ ### Playground
84
+
85
+ Try the plugin in the [online playground](https://sec-ant.github.io/prettier-plugin-embed/). Edit JavaScript or TypeScript alongside your `.prettierrc` configuration, including the `plugins` array and embedded-language options. Formatting runs locally in your browser.
86
+
87
+ To report a formatting issue, keep the original code in Input, enable Compare to inspect the native Prettier output, then use **Copy issue report**. The report includes the input, configuration, output or error, formatter versions, and a shareable playground link. **Share** copies a link containing the current example and configuration.
88
+
89
+ See the [playground guide](./playground/README.md) for local development, keyboard shortcuts, browser limitations, and GitHub Pages deployment.
90
+
81
91
  ### Getting Started
82
92
 
83
93
  This is a Prettier plugin, which follows the [standard usage pattern](https://prettier.io/docs/en/plugins.html#using-plugins) of many other Prettier plugins:
@@ -899,6 +909,8 @@ Supply the `svelte` compiler alongside the formatter plugin, using versions comp
899
909
 
900
910
  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](https://github.com/un-ts/prettier/blob/master/packages/toml/src/options.ts) supported by `prettier-plugin-toml` can therefore be used to further control the formatting behavior.
901
911
 
912
+ `prettier-plugin-toml` 4 requires Node.js 20 or later and its platform-specific optional native dependency. Keep optional dependencies enabled when installing it. Use version 3 for Node.js 18.
913
+
902
914
  #### TS (TypeScript)
903
915
 
904
916
  ##### `embeddedTsComments`
@@ -939,6 +951,8 @@ If you want to specify different parsers for different comments or tags, check [
939
951
 
940
952
  Embedded XML uses the parser provided by [`@prettier/plugin-xml`](https://github.com/prettier/plugin-xml#readme), which must be loaded when XML formatting is enabled. Its [options](https://github.com/prettier/plugin-xml#configuration) control the XML formatting behavior.
941
953
 
954
+ Use version 3 or later with Prettier 3. Version 2 uses the older Prettier 2 embed API and is incompatible.
955
+
942
956
  #### XQuery
943
957
 
944
958
  ##### `embeddedXQueryComments`
@@ -993,13 +1007,21 @@ Embedded YAML uses the parsers and printers included with Prettier.
993
1007
 
994
1008
  This preserves the original exterior whitespace characters, including their indentation. Without this option, whitespace-sensitive markup such as HTML and Jinja preserves whether boundary whitespace exists and allows its indentation to be formatted.
995
1009
 
1010
+ Preserved multiline boundary indentation also sets the margin for subsequent content lines. No extra template indentation is added, including when this option is combined with `noEmbeddedMultiLineIndentation`. If content starts on the same line as the opening backtick, its preserved margin is zero. Content indentation, such as the four spaces of a Markdown code block, belongs to the content rather than to exterior whitespace.
1011
+
996
1012
  ##### `noEmbeddedMultiLineIndentation`
997
1013
 
998
1014
  - **Type**: `string[]`
999
1015
  - **Default**: `[]`
1000
1016
  - **Description**: Turns off auto indentation in the formatting results for the specified comments or tags when they are formatted to span multi lines.
1001
1017
 
1002
- This removes the extra indentation level added around the embedded content. Indentation within the embedded language is still formatted. For example, `"noEmbeddedMultiLineIndentation": ["html", "jinja"]` disables that extra level for both tags and comments. It can be combined with `preserveEmbeddedExteriorWhitespaces`.
1018
+ This prints embedded content from the current document root without inheriting the surrounding JavaScript or TypeScript indentation. Indentation within the embedded language is still formatted. For example, `"noEmbeddedMultiLineIndentation": ["html", "jinja"]` disables automatic template indentation for both tags and comments. It can be combined with `preserveEmbeddedExteriorWhitespaces`, which takes precedence and uses the original boundary margin.
1019
+
1020
+ Markdown retains its root-aligned behavior, so headings inside deeply nested JavaScript do not become indented code blocks. Other languages now follow the same rule. This option affects output layout only; it does not change how the embedded source is parsed or remove its lists, code blocks, or other meaningful indentation. YAML content uses spaces for its internal indentation even when the host uses tabs.
1021
+
1022
+ Before parsing, the plugin removes only the exact whitespace prefix shared by every nonempty content line. A column-zero content line makes that prefix empty. This template margin is determined before trimming boundary whitespace, and tabs and spaces are compared literally. The remaining indentation is passed to the language formatter. This convention applies equally to tags and comments and to both indentation options. It treats a common prefix as template framing; Markdown consisting entirely of indented code can use a fenced code block to make its intent explicit.
1023
+
1024
+ The plugin formats template source and does not insert a runtime dedent operation. For raw whitespace-sensitive values, author content without a common source margin and enable `noEmbeddedMultiLineIndentation` to keep automatic host indentation out of the string value.
1003
1025
 
1004
1026
  ##### `embeddedOverrides`
1005
1027
 
@@ -5,10 +5,9 @@ interface EmbedderConfiguration {
5
5
  parserOption?: string;
6
6
  parserOptions?: Partial<Options>;
7
7
  markup?: boolean;
8
- newlineHandling?: false | "hardline" | "literalline";
9
- dedentContent?: boolean;
8
+ preserveTrailingWhitespace?: boolean;
10
9
  placeholderPrefix?: string;
11
10
  transformDoc?: (doc: Doc) => Doc;
12
11
  }
13
- export declare function createEmbedder({ parser, parserOption, parserOptions, markup, newlineHandling, dedentContent, placeholderPrefix, transformDoc, }: EmbedderConfiguration): Embedder;
12
+ export declare function createEmbedder({ parser, parserOption, parserOptions, markup, preserveTrailingWhitespace, placeholderPrefix, transformDoc, }: EmbedderConfiguration): Embedder;
14
13
  export {};
@@ -1,10 +1,5 @@
1
- import type { Options } from "prettier";
2
- import type { Embedder } from "../../types.js";
3
1
  import { language } from "./language.js";
4
- export declare const embedder: Embedder<Options>;
5
- /**
6
- * Register the embedder to the EmbeddedEmbedders
7
- */
2
+ export declare const embedder: import("../../types.js").Embedder;
8
3
  declare module "../types.js" {
9
4
  interface EmbeddedEmbedders {
10
5
  [language]: typeof embedder;
@@ -15,21 +15,21 @@ import * as __glob__0_8 from "./handlebars/index.js";
15
15
  import * as __glob__0_9 from "./html/index.js";
16
16
  import * as __glob__0_10 from "./hugo/index.js";
17
17
  import * as __glob__0_11 from "./ini/index.js";
18
- import * as __glob__0_12 from "./java/index.js";
18
+ import * as __glob__0_12 from "./jinja/index.js";
19
19
  import * as __glob__0_13 from "./json/index.js";
20
- import * as __glob__0_14 from "./jinja/index.js";
20
+ import * as __glob__0_14 from "./java/index.js";
21
21
  import * as __glob__0_15 from "./jsonata/index.js";
22
22
  import * as __glob__0_16 from "./jte/index.js";
23
- import * as __glob__0_17 from "./latex/index.js";
24
- import * as __glob__0_18 from "./liquid/index.js";
25
- import * as __glob__0_19 from "./markdown/index.js";
26
- import * as __glob__0_20 from "./marko/index.js";
23
+ import * as __glob__0_17 from "./liquid/index.js";
24
+ import * as __glob__0_18 from "./latex/index.js";
25
+ import * as __glob__0_19 from "./marko/index.js";
26
+ import * as __glob__0_20 from "./markdown/index.js";
27
27
  import * as __glob__0_21 from "./motoko/index.js";
28
28
  import * as __glob__0_22 from "./mustache/index.js";
29
- import * as __glob__0_23 from "./nginx/index.js";
30
- import * as __glob__0_24 from "./noop/index.js";
31
- import * as __glob__0_25 from "./nunjucks/index.js";
32
- import * as __glob__0_26 from "./pegjs/index.js";
29
+ import * as __glob__0_23 from "./noop/index.js";
30
+ import * as __glob__0_24 from "./nunjucks/index.js";
31
+ import * as __glob__0_25 from "./pegjs/index.js";
32
+ import * as __glob__0_26 from "./nginx/index.js";
33
33
  import * as __glob__0_27 from "./php/index.js";
34
34
  import * as __glob__0_28 from "./powershell/index.js";
35
35
  import * as __glob__0_29 from "./prisma/index.js";
@@ -3,8 +3,8 @@ import type { AstPath, Doc, Options } from "prettier";
3
3
  import { builders } from "prettier/doc";
4
4
  import type { LiteralUnion, OmitIndexSignature, UnionToIntersection } from "../type-utils.js";
5
5
  import type { InternalPrintFun } from "../types.js";
6
- export declare function prepareTemplate(node: TemplateLiteral, createPlaceholder: (index: number) => string): {
7
- trimmedText: string;
6
+ export declare function prepareTemplate(node: TemplateLiteral, createPlaceholder: (index: number) => string, preserveTrailingWhitespace?: boolean): {
7
+ text: string;
8
8
  leadingWhitespaces: string;
9
9
  trailingWhitespaces: string;
10
10
  };
@@ -16,16 +16,13 @@ export declare function printTemplateExpression(path: AstPath<Expression & {
16
16
  comments?: Comment[];
17
17
  }>, print: InternalPrintFun, templateLiteral: TemplateLiteral, index: number, tabWidth: number, preserveIndentation?: boolean, knownIndentSize?: number): builders.Group;
18
18
  export declare function printTemplateExpressions(path: AstPath<TemplateLiteral>, print: InternalPrintFun, options?: Options, preserveIndentation?: boolean): builders.Group[];
19
- export declare function simpleRehydrateDoc(doc: Doc, placeholderRegex: RegExp, expressionDocs: Doc[],
20
- /**
21
- * How to handle newlines in the formatted content:
22
- * - false: keep newlines as-is (default)
23
- * - "hardline": replace newlines with hardline (adds indentation)
24
- * - "literalline": replace newlines with literalline via replaceEndOfLine (preserves original indentation)
25
- */
26
- newlineHandling?: false | "hardline" | "literalline", lineBreakBeforeExpressions?: ReadonlySet<number>, interpolationTabWidth?: number, escapeClosingScript?: boolean): builders.Doc[] | builders.DocCommand;
19
+ export declare function simpleRehydrateDoc(doc: Doc, placeholderRegex: RegExp, expressionDocs: Doc[], { lineBreakBeforeExpressions, interpolationTabWidth, escapeClosingScript, }?: {
20
+ lineBreakBeforeExpressions?: ReadonlySet<number>;
21
+ interpolationTabWidth?: number;
22
+ escapeClosingScript?: boolean;
23
+ }): builders.Doc;
27
24
  export declare function insertLanguage(languages: string[], language: string, firstLanguage: string): void;
28
- export declare const randomUUID: () => string;
25
+ export declare function randomUUID(): string;
29
26
  export declare function preparePlaceholder(leading?: string, trailing?: string): {
30
27
  createPlaceholder: (index: number) => string;
31
28
  placeholderRegex: RegExp;
@@ -1,10 +1,5 @@
1
- import type { Options } from "prettier";
2
- import type { Embedder } from "../../types.js";
3
1
  import { language } from "./language.js";
4
- export declare const embedder: Embedder<Options>;
5
- /**
6
- * Register the embedder to the EmbeddedEmbedders
7
- */
2
+ export declare const embedder: import("../../types.js").Embedder;
8
3
  declare module "../types.js" {
9
4
  interface EmbeddedEmbedders {
10
5
  [language]: typeof embedder;