@astrojs/markdoc 0.8.3 → 0.9.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.
@@ -137,21 +137,27 @@ function getEntryInfo({ fileUrl, contents }) {
137
137
  }
138
138
  async function emitOptimizedImages(nodeChildren, ctx) {
139
139
  for (const node of nodeChildren) {
140
- if (node.type === "image" && typeof node.attributes.src === "string" && shouldOptimizeImage(node.attributes.src)) {
141
- const resolved = await ctx.pluginContext.resolve(node.attributes.src, ctx.filePath);
142
- if (resolved?.id && fs.existsSync(new URL(prependForwardSlash(resolved.id), "file://"))) {
143
- const src = await emitESMImage(
144
- resolved.id,
145
- ctx.pluginContext.meta.watchMode,
146
- ctx.pluginContext.emitFile
147
- );
148
- node.attributes.__optimizedSrc = src;
149
- } else {
150
- throw new MarkdocError({
151
- message: `Could not resolve image ${JSON.stringify(
152
- node.attributes.src
153
- )} from ${JSON.stringify(ctx.filePath)}. Does the file exist?`
154
- });
140
+ let isComponent = node.type === "tag" && node.tag === "image";
141
+ if ((node.type === "image" || isComponent) && typeof node.attributes.src === "string") {
142
+ let attributeName = isComponent ? "src" : "__optimizedSrc";
143
+ if (shouldOptimizeImage(node.attributes.src)) {
144
+ const resolved = await ctx.pluginContext.resolve(node.attributes.src, ctx.filePath);
145
+ if (resolved?.id && fs.existsSync(new URL(prependForwardSlash(resolved.id), "file://"))) {
146
+ const src = await emitESMImage(
147
+ resolved.id,
148
+ ctx.pluginContext.meta.watchMode,
149
+ ctx.pluginContext.emitFile
150
+ );
151
+ node.attributes[attributeName] = src;
152
+ } else {
153
+ throw new MarkdocError({
154
+ message: `Could not resolve image ${JSON.stringify(
155
+ node.attributes.src
156
+ )} from ${JSON.stringify(ctx.filePath)}. Does the file exist?`
157
+ });
158
+ }
159
+ } else if (isComponent) {
160
+ node.attributes[attributeName] = node.attributes.src;
155
161
  }
156
162
  }
157
163
  await emitOptimizedImages(node.children, ctx);
@@ -11,7 +11,7 @@ function parseInlineCSSToReactLikeObject(css) {
11
11
  return void 0;
12
12
  }
13
13
  function convertCssDirectiveNameToReactCamelCase(original) {
14
- const replaced = original.replace(/-([a-z0-9])/gi, (_match, char) => {
14
+ const replaced = original.replace(/-([a-z\d])/gi, (_match, char) => {
15
15
  return char.toUpperCase();
16
16
  });
17
17
  return replaced;
@@ -14,9 +14,9 @@
14
14
  const COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
15
15
  const NEWLINE_REGEX = /\n/g;
16
16
  const WHITESPACE_REGEX = /^\s*/;
17
- const PROPERTY_REGEX = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/;
17
+ const PROPERTY_REGEX = /^([-#/*\\\w]+(\[[\da-z_-]+\])?)\s*/;
18
18
  const COLON_REGEX = /^:\s*/;
19
- const VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/;
19
+ const VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*\)|[^};])+)/;
20
20
  const SEMICOLON_REGEX = /^[;\s]*/;
21
21
  const TRIM_REGEX = /^\s+|\s+$/g;
22
22
  const NEWLINE = "\n";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/markdoc",
3
3
  "description": "Add support for Markdoc in your Astro site",
4
- "version": "0.8.3",
4
+ "version": "0.9.0",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -70,18 +70,14 @@
70
70
  "astro": "^3.0.0 || ^4.0.0"
71
71
  },
72
72
  "devDependencies": {
73
- "@types/chai": "^4.3.10",
74
73
  "@types/html-escaper": "^3.0.2",
75
74
  "@types/markdown-it": "^13.0.6",
76
- "@types/mocha": "^10.0.4",
77
- "chai": "^4.3.7",
78
75
  "devalue": "^4.3.2",
79
76
  "linkedom": "^0.16.4",
80
- "mocha": "^10.2.0",
81
- "vite": "^5.0.10",
82
- "@astrojs/markdown-remark": "4.1.0",
83
- "astro": "4.2.0",
84
- "astro-scripts": "0.0.14"
77
+ "vite": "^5.0.12",
78
+ "@astrojs/markdown-remark": "4.2.1",
79
+ "astro-scripts": "0.0.14",
80
+ "astro": "4.3.6"
85
81
  },
86
82
  "engines": {
87
83
  "node": ">=18.14.1"
@@ -93,7 +89,6 @@
93
89
  "build": "astro-scripts build \"src/**/*.ts\" && tsc",
94
90
  "build:ci": "astro-scripts build \"src/**/*.ts\"",
95
91
  "dev": "astro-scripts dev \"src/**/*.ts\"",
96
- "test": "mocha --exit --timeout 20000",
97
- "test:match": "mocha --timeout 20000 -g"
92
+ "test": "astro-scripts test --timeout 40000 \"test/**/*.test.js\""
98
93
  }
99
94
  }