@kadal/prettier-plugin 0.4.1 → 0.4.3

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,11 +1,13 @@
1
1
  # @kadal/prettier-plugin
2
2
 
3
+ Prettier for [Kadal Deck](https://deck.kadal.cc) presentations: `deck.mdx` (and `slides.mdx`) formatted the way the engine reads them, in any editor that runs Prettier.
4
+
5
+ [CLI: kadal-deck format](https://deck.kadal.cc/docs/cli/) · [Docs](https://deck.kadal.cc/docs/) · [Source](https://github.com/kadalcc/deck/tree/main/packages/prettier-plugin)
6
+
3
7
  ```sh
4
8
  npm install --save-dev prettier @kadal/prettier-plugin
5
9
  ```
6
10
 
7
- Part of [Kadal Deck](https://deck.kadal.cc/docs/). Prettier for decks: `deck.mdx` (and `slides.mdx`) formatted the way the engine reads them.
8
-
9
11
  ```json
10
12
  // .prettierrc
11
13
  { "plugins": ["@kadal/prettier-plugin"] }
package/dist/split.js CHANGED
@@ -19,6 +19,8 @@
19
19
  const HORIZONTAL = /^---\s*$/;
20
20
  const VERTICAL = /^----+\s*$/;
21
21
  const FRONTMATTER_LINE = /^\s*[A-Za-z_][\w.-]*\s*:(\s|$)/;
22
+ const COMARK_OPEN = /^\s*(:{2,})[A-Za-z][\w-]*(?:[[{].*)?\s*$/;
23
+ const COMARK_CLOSE = /^\s*(:{2,})\s*$/;
22
24
  /** True when every non-empty line could be a YAML mapping line or a continuation (split.ts). */
23
25
  function looksLikeYaml(lines) {
24
26
  let any = false;
@@ -71,6 +73,20 @@ function cutDeck(text) {
71
73
  next: close + 1
72
74
  };
73
75
  };
76
+ const comarkCloseOf = (at, colons) => {
77
+ let code = "";
78
+ for (let k = at + 1; k < lines.length; k++) {
79
+ const l = lines[k];
80
+ const f = /^\s*(`{3,}|~{3,})/.exec(l)?.[1];
81
+ if (f && !code) code = f;
82
+ else if (f && f[0] === code[0] && f.length >= code.length) code = "";
83
+ if (code) continue;
84
+ if (COMARK_CLOSE.exec(l)?.[1].length === colons) return k;
85
+ if (COMARK_OPEN.exec(l)?.[1].length === colons) return -1;
86
+ }
87
+ return -1;
88
+ };
89
+ let comarkUntil = -1;
74
90
  let i = 0;
75
91
  let firstContent = 0;
76
92
  while (firstContent < lines.length && !lines[firstContent].trim()) firstContent++;
@@ -106,7 +122,11 @@ function cutDeck(text) {
106
122
  fence = mark;
107
123
  } else if (mark[0] === fence[0] && mark.length >= fence.length) inFence = false;
108
124
  }
109
- if (!inFence && (HORIZONTAL.test(line) || VERTICAL.test(line))) {
125
+ if (!inFence && i > comarkUntil) {
126
+ const open = COMARK_OPEN.exec(line);
127
+ if (open) comarkUntil = comarkCloseOf(i, open[1].length);
128
+ }
129
+ if (!inFence && i > comarkUntil && (HORIZONTAL.test(line) || VERTICAL.test(line))) {
110
130
  const vertical = VERTICAL.test(line);
111
131
  const fm = frontmatterAt(i + 1);
112
132
  const block = fm ? null : blockAt(i + 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kadal/prettier-plugin",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Prettier for Kadal Deck decks (deck.mdx): separators and frontmatter normalised, YAML formatted with its comments, and every slide's Markdown formatted, with code, notes, magic-move and ::slot:: sugar left exactly as written.",
5
5
  "keywords": [
6
6
  "prettier",
@@ -24,7 +24,7 @@
24
24
  "url": "https://github.com/kadalcc/deck/issues"
25
25
  },
26
26
  "license": "AGPL-3.0-or-later",
27
- "author": "Mithunish Prabhakaran <pmithunish@gmail.com>",
27
+ "author": "Kadal <hello@kadal.cc> (https://kadal.cc)",
28
28
  "type": "module",
29
29
  "sideEffects": false,
30
30
  "files": [