prettier-plugin-mdc 0.1.0 → 0.1.1

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
@@ -2,24 +2,52 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/prettier-plugin-mdc?color=a1b858&label=)](https://www.npmjs.com/package/prettier-plugin-mdc)
4
4
 
5
+ A [Prettier](https://prettier.io/) plugin for formatting [MDC (Markdown Components)](https://content.nuxt.com/docs/files/markdown#mdc-syntax) syntax used in [Nuxt Content](https://content.nuxt.com/).
6
+
5
7
  ## 💎 Features
6
8
 
9
+ - Preserve YAML front matter in components
10
+ - Support for nested components
11
+ - Compatible with GFM (GitHub Flavored Markdown) and math syntax
12
+
7
13
  ## 📦 Installation
8
14
 
9
15
  ```bash
10
- $ npm install prettier-plugin-mdc
11
- $ yarn add prettier-plugin-mdc
12
- $ pnpm add prettier-plugin-mdc
16
+ npm install -D prettier-plugin-mdc
17
+ # or
18
+ yarn add -D prettier-plugin-mdc
19
+ # or
20
+ pnpm add -D prettier-plugin-mdc
13
21
  ```
14
22
 
15
23
  ## 🚀 Usage
16
24
 
17
- ```ts
25
+ Add the plugin to your Prettier configuration:
18
26
 
27
+ ```json
28
+ // .prettierrc
29
+ {
30
+ "plugins": ["prettier-plugin-mdc"]
31
+ }
19
32
  ```
20
33
 
21
- ## 📝 License
34
+ Or in `prettier.config.js`:
22
35
 
23
- [MIT](./LICENSE). Made with ❤️ by [Ray](https://github.com/so1ve)
36
+ ```js
37
+ export default {
38
+ plugins: ["prettier-plugin-mdc"],
39
+ };
40
+ ```
41
+
42
+ Then format your `.mdc` or `.md` files:
24
43
 
25
- [link](https://nuxtjs.org)
44
+ ```bash
45
+ prettier --write "**/*.mdc"
46
+ prettier --write "**/*.md"
47
+ ```
48
+
49
+ For MDC Syntax Reference, please check [remark-mdc](https://github.com/nuxt-content/remark-mdc).
50
+
51
+ ## License
52
+
53
+ [MIT](./LICENSE). Made with ❤️ by [Ray](https://github.com/so1ve)
package/dist/index.mjs CHANGED
@@ -71,7 +71,7 @@ const extendedInlineNodes = [
71
71
  "inlineCode",
72
72
  "emphasis"
73
73
  ];
74
- const hasInlineAttribute = (node) => extendedInlineNodes.includes(node.type) && "attributes" in node;
74
+ const extendedInlineNodesHaveAttributes = (node) => extendedInlineNodes.includes(node.type) && "attributes" in node;
75
75
  const escapeQuotes = (value, quote) => value.replace(new RegExp(quote, "g"), `\\${quote}`);
76
76
 
77
77
  //#endregion
@@ -257,6 +257,8 @@ function printLink(path, print, options) {
257
257
  parts.push(" ", quote, node.title, quote);
258
258
  }
259
259
  parts.push(")");
260
+ const attrStr = printAttributes(node, options);
261
+ if (attrStr) parts.push(attrStr);
260
262
  return parts;
261
263
  }
262
264
 
@@ -271,8 +273,8 @@ const printers = { [AST_FORMAT]: {
271
273
  },
272
274
  print(path, options, print, args) {
273
275
  const { node } = path;
274
- if (hasInlineAttribute(node)) return [mdastPrinter.print(path, options, print, args), printAttributes(node, options)];
275
276
  if (isLinkNode(node) && linkNeedsCustomPrinting(node)) return printLink(path, print, options);
277
+ if (extendedInlineNodesHaveAttributes(node)) return [mdastPrinter.print(path, options, print, args), printAttributes(node, options)];
276
278
  if (isTextComponentNode(node)) return printTextComponent(path, print, options);
277
279
  else if (isContainerComponentNode(node)) return printContainerComponent(path, print, options);
278
280
  else if (isComponentContainerSectionNode(node)) return printComponentContainerSection(path, print);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-mdc",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "author": "Ray <i@mk1.io> (@so1ve)",
5
5
  "type": "module",
6
6
  "description": "Prettier plugin for MDC syntax",