@utilfirst/prettier-plugin 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ayan Yenbekbay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # @utilfirst/prettier-plugin
2
+
3
+ Shared Prettier plugin for utilfirst projects. Targets markdown, Prettier 3.
4
+
5
+ ## What it does
6
+
7
+ - Keeps bare URLs with trailing or intra-word underscores literal (e.g. `https://instagram.com/highnote_____` doesn't get rewritten as `**\_**`).
8
+ - Suppresses the blank line Prettier inserts between a paragraph and an immediately following list (lets you write `Intro:\n- item\n` and have it stay flush).
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ pnpm add -D @utilfirst/prettier-plugin
14
+ ```
15
+
16
+ ## Use
17
+
18
+ ```js
19
+ // prettier.config.mjs
20
+ /** @type {import("prettier").Config} */
21
+ export default {
22
+ plugins: ["@utilfirst/prettier-plugin"],
23
+ };
24
+ ```
25
+
26
+ ## Develop
27
+
28
+ ```sh
29
+ pnpm install
30
+ pnpm run setup-hooks # one-time: wire pre-commit via simple-git-hooks
31
+ pnpm test # vitest with inline snapshots
32
+ pnpm run build # tsdown → dist/
33
+ pnpm run lint # eslint + prettier + publint + tsc
34
+ ```
35
+
36
+ ## License
37
+
38
+ MIT
@@ -0,0 +1,7 @@
1
+ import { Root } from "mdast";
2
+ import { Plugin } from "prettier";
3
+
4
+ //#region src/index.d.ts
5
+ declare const plugin: Plugin<Root>;
6
+ //#endregion
7
+ export { plugin as default };
package/dist/index.js ADDED
@@ -0,0 +1,48 @@
1
+ import * as md from "prettier/plugins/markdown";
2
+
3
+ //#region src/index.ts
4
+ const SCAN_RE = /(```[\s\S]*?```|~~~[\s\S]*?~~~|`[^`\n]*`|\[[^\]\n]*\]\([^)\n]*\)|<[^>\n]+>)|https?:\/\/[^\s<>)]+/g;
5
+ function wrapBareUrls(src) {
6
+ return src.replace(SCAN_RE, (match, keep) => keep ? match : `<${match}>`);
7
+ }
8
+ function collapseAutolinks(node) {
9
+ if (node?.type === "link" && node.children?.length === 1 && node.url === node.children[0]?.value) {
10
+ node.type = "html";
11
+ node.value = node.url;
12
+ delete node.children;
13
+ delete node.url;
14
+ delete node.title;
15
+ }
16
+ node?.children?.forEach(collapseAutolinks);
17
+ }
18
+ function suppressIntroListGap(rootDoc, children) {
19
+ if (!Array.isArray(rootDoc)) return;
20
+ const inner = rootDoc[0];
21
+ if (!Array.isArray(inner)) return;
22
+ for (let i = 0; i < children.length - 1; i++) if (children[i]?.type === "paragraph" && children[i + 1]?.type === "list") inner[3 * i + 2] = "";
23
+ }
24
+ const plugin = {
25
+ parsers: { markdown: {
26
+ ...md.parsers.markdown,
27
+ async parse(text, options) {
28
+ const wrapped = wrapBareUrls(text);
29
+ options.originalText = wrapped;
30
+ const ast = await md.parsers.markdown.parse(wrapped, options);
31
+ collapseAutolinks(ast);
32
+ return ast;
33
+ }
34
+ } },
35
+ printers: { mdast: {
36
+ ...md.printers.mdast,
37
+ print(path, options, print) {
38
+ const doc = md.printers.mdast.print(path, options, print);
39
+ const node = path.node;
40
+ if (node.type === "root") suppressIntroListGap(doc, node.children ?? []);
41
+ return doc;
42
+ }
43
+ } }
44
+ };
45
+ var src_default = plugin;
46
+
47
+ //#endregion
48
+ export { src_default as default };
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@utilfirst/prettier-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Shared Prettier plugin for utilfirst projects",
5
+ "keywords": [
6
+ "prettier",
7
+ "prettier-plugin",
8
+ "markdown"
9
+ ],
10
+ "homepage": "https://github.com/utilfirst/utilfirst-prettier-plugin#readme",
11
+ "bugs": "https://github.com/utilfirst/utilfirst-prettier-plugin/issues",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/utilfirst/utilfirst-prettier-plugin.git"
15
+ },
16
+ "license": "MIT",
17
+ "author": "Ayan Yenbekbay <ayan.yenb@gmail.com>",
18
+ "type": "module",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "scripts": {
32
+ "build": "tsdown",
33
+ "fix": "pnpm run --sequential '/^fix:[^:]+$/'",
34
+ "fix:eslint": "pnpm run lint:eslint --fix",
35
+ "fix:prettier": "pnpm run lint:prettier --write",
36
+ "lint": "pnpm run --sequential '/^lint:[^:]+$/'",
37
+ "lint:eslint": "eslint .",
38
+ "lint:prettier": "prettier --check .",
39
+ "lint:publint": "publint",
40
+ "lint:typecheck": "tsc --pretty --noEmit",
41
+ "prepack": "pnpm run build",
42
+ "setup-hooks": "simple-git-hooks",
43
+ "test": "vitest run"
44
+ },
45
+ "simple-git-hooks": {
46
+ "pre-commit": "pnpm exec lint-staged && pnpm run lint:typecheck"
47
+ },
48
+ "lint-staged": {
49
+ "*": "prettier --ignore-unknown --write",
50
+ "*.{js,cjs,mjs,ts,tsx}": "eslint --fix"
51
+ },
52
+ "devDependencies": {
53
+ "@eslint/js": "^10.0.1",
54
+ "@types/mdast": "^4.0.4",
55
+ "@types/node": "^25.9.1",
56
+ "@vitest/coverage-v8": "^4.1.7",
57
+ "eslint": "^10.3.0",
58
+ "lint-staged": "^17.0.4",
59
+ "prettier": "^3.8.3",
60
+ "prettier-plugin-organize-imports": "^4.3.0",
61
+ "prettier-plugin-packagejson": "^3.0.2",
62
+ "prettier-plugin-sh": "^0.18.1",
63
+ "prettier-plugin-sort-json": "^4.2.0",
64
+ "publint": "^0.3.16",
65
+ "simple-git-hooks": "^2.13.1",
66
+ "tsdown": "^0.18.4",
67
+ "typescript": "^6.0.3",
68
+ "typescript-eslint": "^8.59.3",
69
+ "vitest": "^4.0.7"
70
+ },
71
+ "peerDependencies": {
72
+ "prettier": "^3.0.0"
73
+ },
74
+ "packageManager": "pnpm@11.0.9",
75
+ "engines": {
76
+ "node": ">=20.19.0"
77
+ },
78
+ "publishConfig": {
79
+ "access": "public",
80
+ "provenance": true
81
+ }
82
+ }