-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
172 additions
and
100 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { parsers } from "./parsers.js"; | ||
export { printers } from "./printers.js"; | ||
export { options } from "./options.js"; | ||
export type * from "./options.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
import type { CoreCategoryType, SupportOptions } from "prettier"; | ||
import type { Embedder } from "./embedders/index.js"; | ||
|
||
export const options: SupportOptions = { | ||
embeddedLanguages: { | ||
type: "path", | ||
category: "Global" satisfies CoreCategoryType, | ||
array: true, | ||
default: [{ value: [] }], | ||
type: "string", | ||
array: false, | ||
default: "[]", | ||
description: | ||
"Config embedded languages formatting supported by this plugin.", | ||
}, | ||
}; | ||
|
||
interface EmbeddedLanguage { | ||
export interface EmbeddedLanguage { | ||
tag: string | string[]; | ||
comment: string | string[]; | ||
embedder: string | Embedder | null; | ||
embedder?: string | null; | ||
} | ||
|
||
export interface PluginOptions { | ||
embeddedLanguages?: EmbeddedLanguage[]; | ||
export interface PrettierPluginEmbedOptions { | ||
embeddedLanguages?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import parserBabel from "prettier/parser-babel"; | ||
import parserEspree from "prettier/parser-espree"; | ||
import parserFlow from "prettier/parser-flow"; | ||
import parserTypescript from "prettier/parser-typescript"; | ||
|
||
// todo: find out which parsers are required and which are optional | ||
export const parsers = { | ||
...parserBabel.parsers, | ||
...parserEspree.parsers, | ||
...parserFlow.parsers, | ||
...parserTypescript.parsers, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { html } from "code-tag"; | ||
import { any } from "code-tag"; | ||
const xml = any; | ||
|
||
() => html` | ||
<div> | ||
<div></div> | ||
</div> | ||
<div></div> | ||
xml` | ||
<svg | ||
xmlns = "http://www.w3.org/2000/svg" | ||
xmlns:xlink = "http://www.w3.org/1999/xlink" | ||
width = "200" | ||
height="100" | ||
viewBox="0 0 200 100" | ||
>${"123"}</svg> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
/// <reference types="vite/client" /> | ||
import { test } from "vitest"; | ||
import { format, type Options } from "prettier"; | ||
import { fileURLToPath } from "node:url"; | ||
import type { EmbeddedLanguage, PrettierPluginEmbedOptions } from "../src"; | ||
|
||
const PLUGIN_EMBED = fileURLToPath( | ||
new URL("../dist/index.js", import.meta.url), | ||
); | ||
|
||
// todo: add tests | ||
test.skip(() => { | ||
/* void */ | ||
test("0", async () => { | ||
const code = (await import("./code/0.ts?raw")).default; | ||
const formattedCode = await format(code, { | ||
plugins: ["@prettier/plugin-xml", PLUGIN_EMBED], | ||
filepath: "0.js", | ||
parser: "babel", | ||
embeddedLanguages: JSON.stringify([ | ||
{ | ||
tag: "xml", | ||
comment: "xml", | ||
embedder: "xml", | ||
}, | ||
] as EmbeddedLanguage[]), | ||
} as Options & PrettierPluginEmbedOptions); | ||
console.log(formattedCode); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters