@easy-web/markdown 1.0.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/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @easy-web/markdown
2
+
3
+ Remark plugin for the easy-web ecosystem. Normalises `/src/assets/...` image URLs in markdown body to relative paths Astro's built-in markdown image resolver accepts.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pnpm add @easy-web/markdown
9
+ ```
10
+
11
+ ## Usage (Astro 6)
12
+
13
+ ```ts
14
+ // astro.config.mjs
15
+ import { defineConfig } from 'astro/config';
16
+ import easyWebMarkdown from '@easy-web/markdown';
17
+
18
+ export default defineConfig({
19
+ markdown: {
20
+ remarkPlugins: [easyWebMarkdown],
21
+ },
22
+ });
23
+ ```
24
+
25
+ ## Usage (Astro 7 — opt-in required)
26
+
27
+ Astro 7 replaced the default markdown pipeline with Sätteri. To keep using remark plugins, install `@astrojs/markdown-remark` and configure:
28
+
29
+ ```ts
30
+ import { unified } from '@astrojs/markdown-remark';
31
+ import easyWebMarkdown from '@easy-web/markdown';
32
+
33
+ export default defineConfig({
34
+ markdown: {
35
+ processor: unified({
36
+ remarkPlugins: [easyWebMarkdown],
37
+ }),
38
+ },
39
+ });
40
+ ```
@@ -0,0 +1,2 @@
1
+ export { default } from './plugin.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default } from './plugin.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,54 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { unified } from 'unified';
3
+ import { visit } from 'unist-util-visit';
4
+ import { VFile } from 'vfile';
5
+ import easyWebMarkdown from './index.js';
6
+ function getImageUrls(tree) {
7
+ const urls = [];
8
+ visit(tree, 'image', (node) => {
9
+ urls.push(node.url);
10
+ });
11
+ return urls;
12
+ }
13
+ function makeImageTree(url) {
14
+ return {
15
+ type: 'root',
16
+ children: [
17
+ {
18
+ type: 'paragraph',
19
+ children: [{ type: 'image', url, alt: 'test', title: null }],
20
+ },
21
+ ],
22
+ };
23
+ }
24
+ describe('easyWebMarkdown remark plugin', () => {
25
+ it('rewrites /src/assets/ URL to relative path from md file', () => {
26
+ const tree = makeImageTree('/src/assets/images/foo.png');
27
+ const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
28
+ const processor = unified().use(easyWebMarkdown);
29
+ processor.runSync(tree, file);
30
+ expect(getImageUrls(tree)).toEqual(['../../../assets/images/foo.png']);
31
+ });
32
+ it('passes through relative ../../ URL unchanged', () => {
33
+ const tree = makeImageTree('../../assets/foo.png');
34
+ const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
35
+ const processor = unified().use(easyWebMarkdown);
36
+ processor.runSync(tree, file);
37
+ expect(getImageUrls(tree)).toEqual(['../../assets/foo.png']);
38
+ });
39
+ it('passes through external URL unchanged', () => {
40
+ const tree = makeImageTree('https://example.com/foo.png');
41
+ const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
42
+ const processor = unified().use(easyWebMarkdown);
43
+ processor.runSync(tree, file);
44
+ expect(getImageUrls(tree)).toEqual(['https://example.com/foo.png']);
45
+ });
46
+ it('passes through /uploads/ public-folder URL unchanged', () => {
47
+ const tree = makeImageTree('/uploads/foo.png');
48
+ const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
49
+ const processor = unified().use(easyWebMarkdown);
50
+ processor.runSync(tree, file);
51
+ expect(getImageUrls(tree)).toEqual(['/uploads/foo.png']);
52
+ });
53
+ });
54
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,eAAe,MAAM,YAAY,CAAC;AAEzC,SAAS,YAAY,CAAC,IAAU;IAC9B,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAW,EAAE,EAAE;QACnC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,GAAW;IAChC,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,WAAW;gBACjB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;aAC7D;SACF;KACF,CAAC;AACJ,CAAC;AAED,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,IAAI,GAAG,aAAa,CAAC,4BAA4B,CAAC,CAAC;QACzD,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,EAAE,IAAI,EA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,MAAM,IAAI,GAAG,aAAa,CAAC,kBAAkB,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,EAAE,IAAI,EAAE,uCAAuC,EAAE,CAAC,CAAC;QAC1E,MAAM,SAAS,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACjD,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Plugin } from 'unified';
2
+ import type { Root } from 'mdast';
3
+ /**
4
+ * Remark plugin for easy-web.
5
+ * Rewrites markdown image URLs starting with `/src/assets/` to relative paths
6
+ * from the markdown file's location — a format Astro's built-in image resolver accepts.
7
+ *
8
+ * URLs NOT starting with `/src/assets/` are passed through unchanged.
9
+ */
10
+ declare const easyWebMarkdown: Plugin<[], Root>;
11
+ export default easyWebMarkdown;
12
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAS,MAAM,OAAO,CAAC;AAGzC;;;;;;GAMG;AACH,QAAA,MAAM,eAAe,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,CA2BrC,CAAC;AAEF,eAAe,eAAe,CAAC"}
package/dist/plugin.js ADDED
@@ -0,0 +1,35 @@
1
+ import { visit } from 'unist-util-visit';
2
+ import { posix as path } from 'node:path';
3
+ /**
4
+ * Remark plugin for easy-web.
5
+ * Rewrites markdown image URLs starting with `/src/assets/` to relative paths
6
+ * from the markdown file's location — a format Astro's built-in image resolver accepts.
7
+ *
8
+ * URLs NOT starting with `/src/assets/` are passed through unchanged.
9
+ */
10
+ const easyWebMarkdown = () => {
11
+ return (tree, file) => {
12
+ const rawPath = (file.history?.[0] ?? file.path);
13
+ if (!rawPath)
14
+ return;
15
+ // Normalise to forward slashes (Astro always provides POSIX paths)
16
+ const filePath = rawPath.replace(/\\/g, '/');
17
+ visit(tree, 'image', (node) => {
18
+ if (!node.url.startsWith('/src/assets/'))
19
+ return;
20
+ // Locate the /src/ boundary in the md file's path
21
+ const srcBoundary = filePath.lastIndexOf('/src/');
22
+ if (srcBoundary === -1)
23
+ return;
24
+ const projectRoot = filePath.substring(0, srcBoundary);
25
+ const fileDir = path.dirname(filePath);
26
+ // Asset absolute path: projectRoot + /src/assets/...
27
+ const assetAbsolute = projectRoot + node.url;
28
+ // Compute relative path from .md directory to asset
29
+ const relativePath = path.relative(fileDir, assetAbsolute);
30
+ node.url = relativePath;
31
+ });
32
+ };
33
+ };
34
+ export default easyWebMarkdown;
35
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,eAAe,GAAqB,GAAG,EAAE;IAC7C,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QACpB,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAuB,CAAC;QACvE,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,mEAAmE;QACnE,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE7C,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAW,EAAE,EAAE;YACnC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC;gBAAE,OAAO;YAEjD,kDAAkD;YAClD,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAClD,IAAI,WAAW,KAAK,CAAC,CAAC;gBAAE,OAAO;YAE/B,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;YACvD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAEvC,qDAAqD;YACrD,MAAM,aAAa,GAAG,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC;YAE7C,oDAAoD;YACpD,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YAE3D,IAAI,CAAC,GAAG,GAAG,YAAY,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@easy-web/markdown",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "packageManager": "pnpm@10.34.4",
7
+ "description": "Remark plugin for the easy-web ecosystem that normalises markdown-body image URLs to paths Astro's built-in image resolver accepts.",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "sideEffects": false,
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "test": "vitest run",
22
+ "typecheck": "tsc --noEmit"
23
+ },
24
+ "peerDependencies": {
25
+ "astro": ">=6.0.0 <8.0.0"
26
+ },
27
+ "dependencies": {
28
+ "unified": "^11",
29
+ "unist-util-visit": "^5"
30
+ },
31
+ "devDependencies": {
32
+ "@types/mdast": "^4",
33
+ "typescript": "^5.5.0",
34
+ "vfile": "^6.0.3",
35
+ "vitest": "^3.2.4"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "provenance": true
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/achimismaili/easy-web.git",
44
+ "directory": "packages/easy-web-markdown"
45
+ }
46
+ }