@easy-web/markdown 1.3.3 → 1.4.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 +6 -37
- package/dist/compat.test.d.ts +2 -0
- package/dist/compat.test.d.ts.map +1 -0
- package/dist/compat.test.js +9 -0
- package/dist/compat.test.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -54
- package/dist/index.test.js.map +0 -1
- package/dist/plugin.d.ts +0 -12
- package/dist/plugin.d.ts.map +0 -1
- package/dist/plugin.js +0 -35
- package/dist/plugin.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,40 +1,9 @@
|
|
|
1
|
-
# @easy-web/markdown
|
|
1
|
+
# @easy-web/markdown (deprecated)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package is a compatibility layer. The remark plugin that normalises markdown-body image URLs now lives in [`@easy-web/core`](../core/README.md). The default export keeps working and is the core plugin itself, but new code should import from `@easy-web/core/markdown`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
| Old import | New import |
|
|
6
|
+
| :--- | :--- |
|
|
7
|
+
| `import easyWebMarkdown from '@easy-web/markdown'` | `import easyWebMarkdown from '@easy-web/core/markdown'` |
|
|
6
8
|
|
|
7
|
-
|
|
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
|
-
```
|
|
9
|
+
On Astro 7, `markdown.remarkPlugins` runs only when `@astrojs/markdown-remark` is installed in the site.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compat.test.d.ts","sourceRoot":"","sources":["../src/compat.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import coreMarkdown from '@easy-web/core/markdown';
|
|
3
|
+
import easyWebMarkdown from './index.js';
|
|
4
|
+
describe('@easy-web/markdown compatibility export', () => {
|
|
5
|
+
it('re-exports the core remark plugin by identity', () => {
|
|
6
|
+
expect(easyWebMarkdown).toBe(coreMarkdown);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=compat.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compat.test.js","sourceRoot":"","sources":["../src/compat.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,YAAY,MAAM,yBAAyB,CAAC;AACnD,OAAO,eAAe,MAAM,YAAY,CAAC;AAEzC,QAAQ,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACvD,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @easy-web/markdown is a compatibility package; the remark plugin now lives in
|
|
3
|
+
* `@easy-web/core/markdown`. Import from there instead.
|
|
4
|
+
*/
|
|
5
|
+
export { default } from '@easy-web/core/markdown';
|
|
2
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @easy-web/markdown is a compatibility package; the remark plugin now lives in
|
|
3
|
+
* `@easy-web/core/markdown`. Import from there instead.
|
|
4
|
+
*/
|
|
5
|
+
export { default } from '@easy-web/core/markdown';
|
|
2
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-web/markdown",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Remark plugin for the easy-web ecosystem that normalises markdown-body image URLs to paths Astro's built-in image resolver accepts.",
|
|
@@ -19,13 +19,11 @@
|
|
|
19
19
|
"astro": ">=6.0.0 <8.0.0"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"unist-util-visit": "^5"
|
|
22
|
+
"@easy-web/core": "1.4.1"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
|
-
"
|
|
25
|
+
"astro": "^7.3.5",
|
|
27
26
|
"typescript": "^5.5.0",
|
|
28
|
-
"vfile": "^6.0.3",
|
|
29
27
|
"vitest": "^3.2.4"
|
|
30
28
|
},
|
|
31
29
|
"publishConfig": {
|
package/dist/index.test.d.ts
DELETED
package/dist/index.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
package/dist/index.test.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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.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AE,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"}
|
package/dist/plugin.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
package/dist/plugin.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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
|
package/dist/plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;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