@htnabe/prettier-plugin-hugo-post 0.0.1-rc.1 → 0.0.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
@@ -1,12 +1,14 @@
1
1
  # @htnabe/prettier-plugin-hugo-post
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@htnabe/prettier-plugin-hugo-post)](https://www.npmjs.com/package/@htnabe/prettier-plugin-hugo-post)
4
- [![GitHub](https://img.shields.io/github/stars/htnabe/prettier-plugin-hugo-post?style=social)](https://github.com/htnabe/prettier-plugin-hugo-post)
4
+ [<img src="https://badges.ws/npm/dt/@htnabe/prettier-plugin-hugo-post" />](https://www.npmjs.com/package/@htnabe/prettier-plugin-hugo-post)
5
5
  [![codecov](https://codecov.io/gh/htnabe/prettier-plugin-hugo-post/graph/badge.svg?token=BR5Y5MAXON)](https://codecov.io/gh/htnabe/prettier-plugin-hugo-post)
6
6
  [![license](https://img.shields.io/npm/l/@htnabe/prettier-plugin-hugo-post)](https://github.com/htnabe/prettier-plugin-hugo-post/blob/main/LICENSE)
7
7
 
8
8
  A Prettier plugin for formatting Hugo content files that mix front matter, Markdown, and Go template syntax.
9
9
 
10
+ This package started as a fork of [prettier-plugin-hugo-post](https://github.com/metcalfc/prettier-plugin-hugo-post).
11
+
10
12
  ## Why this plugin?
11
13
 
12
14
  Hugo content files are not plain Markdown. They often contain:
package/dist/index.mjs CHANGED
@@ -231,16 +231,37 @@ function ensureProperBlockSpacing(content) {
231
231
  for (let i = 0; i < lines.length; i++) {
232
232
  const line = lines[i];
233
233
  const prevLine = i > 0 ? lines[i - 1] : "";
234
- const isEndControl = line.trim().match(/^\{\{\s*end\s*\}\}$/);
235
- const prevIsListItem = prevLine.trim().match(/^[-*+]\s/);
234
+ const trimmedLine = line.trim();
235
+ const trimmedPrevLine = prevLine.trim();
236
+ const isEndControl = trimmedLine.match(/^\{\{\s*end\s*\}\}$/);
237
+ const prevIsListItem = trimmedPrevLine.match(/^[-*+]\s/);
236
238
  if (isEndControl && prevIsListItem) {
237
239
  result.push("");
238
240
  result.push(line);
239
- } else result.push(line);
241
+ continue;
242
+ }
243
+ const prevIsTableRow = isMarkdownTableRow(trimmedPrevLine);
244
+ const currentIsTableRow = isMarkdownTableRow(trimmedLine);
245
+ if (prevIsTableRow && trimmedLine !== "" && !currentIsTableRow) {
246
+ result.push("");
247
+ result.push(line);
248
+ continue;
249
+ }
250
+ result.push(line);
240
251
  }
241
252
  return result.join("\n");
242
253
  }
243
254
  /**
255
+ * Determine whether a trimmed line looks like a Markdown (GFM) table row.
256
+ * This is intentionally conservative to avoid treating Go-template pipelines
257
+ * (e.g. `{{ .Title | upper }}`) or YAML block scalars (`key: |`) as tables.
258
+ */
259
+ function isMarkdownTableRow(trimmedLine) {
260
+ if (trimmedLine === "" || trimmedLine.startsWith("{{")) return false;
261
+ if (!(trimmedLine.startsWith("|") || /\s\|\s/.test(trimmedLine))) return false;
262
+ return trimmedLine.split("|").length - 1 >= 2;
263
+ }
264
+ /**
244
265
  * Format a template expression with proper spacing and structure
245
266
  */
246
267
  function formatTemplateExpression(expr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htnabe/prettier-plugin-hugo-post",
3
- "version": "0.0.1-rc.1",
3
+ "version": "0.0.2",
4
4
  "description": "A Prettier plugin for formatting Hugo content files with YAML, TOML, or JSON front matter, Markdown content, and Go template syntax.",
5
5
  "main": "dist/index.mjs",
6
6
  "types": "dist/index.d.mts",
@@ -42,12 +42,12 @@
42
42
  "prettier-plugin-toml": "^2.0.6"
43
43
  },
44
44
  "devDependencies": {
45
- "@types/node": "^26.2.0",
45
+ "@types/node": "^26.5.1",
46
46
  "@typescript/native-preview": "^7.0.0-dev.20260707.2",
47
47
  "@vitest/coverage-v8": "^4.1.11",
48
48
  "jsdom": "^30.0.1",
49
- "lefthook": "^2.1.10",
50
- "oxlint": "^1.79.0",
49
+ "lefthook": "^2.1.12",
50
+ "oxlint": "^1.82.0",
51
51
  "oxlint-tsgolint": "^7.0.2001",
52
52
  "prettier": "^3.9.6",
53
53
  "ts-node": "^10.9.2",
@@ -78,8 +78,5 @@
78
78
  "printWidth": 100,
79
79
  "bracketSpacing": true,
80
80
  "arrowParens": "avoid"
81
- },
82
- "allowScripts": {
83
- "lefthook@2.1.10": true
84
81
  }
85
82
  }