@sota1235/remark-link-bookmark 0.0.6 → 0.0.7
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/dist/view.js +14 -7
- package/package.json +17 -14
- package/.envrc +0 -1
- package/dist/convert.test.d.ts +0 -1
- package/dist/convert.test.js +0 -16
- package/dist/mdast.d.ts +0 -3
- package/dist/mdast.js +0 -6
- package/dist/sample.test.d.ts +0 -1
- package/dist/sample.test.js +0 -4
- package/dist/script.d.ts +0 -1
- package/dist/script.js +0 -6
package/dist/view.js
CHANGED
|
@@ -11,6 +11,12 @@ function buildOgpImageHtml(ogImageSrc, ogImageAlt, className) {
|
|
|
11
11
|
? `<img class="${className}" src="${ogImageSrc}" alt="${ogImageAlt}" />`
|
|
12
12
|
: '';
|
|
13
13
|
}
|
|
14
|
+
function removeEmptyLines(str) {
|
|
15
|
+
return str
|
|
16
|
+
.split(/\r?\n/)
|
|
17
|
+
.filter((line) => line.trim() !== '')
|
|
18
|
+
.join('\n');
|
|
19
|
+
}
|
|
14
20
|
export const buildBookmarkHtml = ({ title, description, faviconSrc, ogImageSrc, ogImageAlt, url }, { classPrefix = 'rlb', mergeClassNames }) => {
|
|
15
21
|
const host = new URL(url).host;
|
|
16
22
|
const dompurify = createDOMPurify(new JSDOM('').window);
|
|
@@ -24,8 +30,8 @@ export const buildBookmarkHtml = ({ title, description, faviconSrc, ogImageSrc,
|
|
|
24
30
|
const footerClassName = clsx(`${classPrefix}-footer`, mergeClassNames?.footer);
|
|
25
31
|
const footerLinkClassName = clsx(`${classPrefix}-footer-link`, mergeClassNames?.footerLink);
|
|
26
32
|
const faviconImageClassName = clsx(`${classPrefix}-favicon`, mergeClassNames?.favicon);
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
const footerLinkTextClassName = clsx(`${classPrefix}-footer-link-text`, mergeClassNames?.favicon);
|
|
34
|
+
return removeEmptyLines(dompurify.sanitize(`
|
|
29
35
|
<div class="${containerClassName}">
|
|
30
36
|
<div class="${contentClassName}">
|
|
31
37
|
<div class="${infoClassName}">
|
|
@@ -38,8 +44,10 @@ export const buildBookmarkHtml = ({ title, description, faviconSrc, ogImageSrc,
|
|
|
38
44
|
>
|
|
39
45
|
${title}
|
|
40
46
|
</a>
|
|
41
|
-
</h2
|
|
42
|
-
|
|
47
|
+
</h2>
|
|
48
|
+
${buildDescriptionHtml(description, descriptionClassName)}
|
|
49
|
+
</div>
|
|
50
|
+
${buildOgpImageHtml(ogImageSrc, ogImageAlt ?? url, imageClassName)}
|
|
43
51
|
</div>
|
|
44
52
|
<div class="${footerClassName}">
|
|
45
53
|
<a
|
|
@@ -49,10 +57,9 @@ export const buildBookmarkHtml = ({ title, description, faviconSrc, ogImageSrc,
|
|
|
49
57
|
rel="noopener noreferrer"
|
|
50
58
|
>
|
|
51
59
|
<img class="${faviconImageClassName}" src="${faviconSrc}" alt="${host}" />
|
|
52
|
-
${host}
|
|
60
|
+
<span class="${footerLinkTextClassName}">${host}</span>
|
|
53
61
|
</a>
|
|
54
62
|
</div>
|
|
55
63
|
</div>
|
|
56
|
-
`)
|
|
57
|
-
.trim();
|
|
64
|
+
`)).trim();
|
|
58
65
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sota1235/remark-link-bookmark",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Remark plugin to convert link to bookmark component",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"@types/debug": "4.1.12",
|
|
21
21
|
"@types/dompurify": "3.0.5",
|
|
22
22
|
"@types/jsdom": "21.1.7",
|
|
23
|
+
"@types/node": "22",
|
|
23
24
|
"eslint": "9.14.0",
|
|
24
25
|
"husky": "9.1.6",
|
|
25
26
|
"lint-staged": "15.2.10",
|
|
@@ -29,6 +30,19 @@
|
|
|
29
30
|
"typescript-eslint": "8.13.0",
|
|
30
31
|
"vitest": "^2.1.4"
|
|
31
32
|
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p ./tsconfig.publish.json",
|
|
35
|
+
"build:publish": "tsc -p ./tsconfig.publish.json",
|
|
36
|
+
"watch": "tsc -p ./tsconfig.publish.json --watch",
|
|
37
|
+
"fix": "npm run prettier && npm run eslint:fix",
|
|
38
|
+
"lint": "npm run eslint",
|
|
39
|
+
"eslint": "eslint 'src/**/*.ts'",
|
|
40
|
+
"eslint:fix": "npm run eslint --fix",
|
|
41
|
+
"prettier": "prettier './src/**/*.ts' --write",
|
|
42
|
+
"test": "vitest",
|
|
43
|
+
"test:ci": "vitest",
|
|
44
|
+
"prepare": "husky"
|
|
45
|
+
},
|
|
32
46
|
"keywords": [
|
|
33
47
|
"remark"
|
|
34
48
|
],
|
|
@@ -43,16 +57,5 @@
|
|
|
43
57
|
"npm run fix"
|
|
44
58
|
]
|
|
45
59
|
},
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
"build:publish": "tsc -p ./tsconfig.publish.json",
|
|
49
|
-
"watch": "tsc -p ./tsconfig.publish.json --watch",
|
|
50
|
-
"fix": "npm run prettier && npm run eslint:fix",
|
|
51
|
-
"lint": "npm run eslint",
|
|
52
|
-
"eslint": "eslint 'src/**/*.ts'",
|
|
53
|
-
"eslint:fix": "npm run eslint --fix",
|
|
54
|
-
"prettier": "prettier './src/**/*.ts' --write",
|
|
55
|
-
"test": "vitest",
|
|
56
|
-
"test:ci": "vitest"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
60
|
+
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee"
|
|
61
|
+
}
|
package/.envrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export NODE_AUTH_TOKEN=
|
package/dist/convert.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/convert.test.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest';
|
|
2
|
-
import { remark } from 'remark';
|
|
3
|
-
import { remarkLinkBookmark } from './plugin.js';
|
|
4
|
-
test('Input markdown should be expected', async () => {
|
|
5
|
-
const document = `
|
|
6
|
-
# Sample
|
|
7
|
-
|
|
8
|
-
https://example.com
|
|
9
|
-
|
|
10
|
-
[example](https://example.com/) is inline link
|
|
11
|
-
|
|
12
|
-
[remark-link-card](https://www.npmjs.com/package/remark-link-card) is inline link
|
|
13
|
-
`.trim();
|
|
14
|
-
const file = await remark().use(remarkLinkBookmark, {}).process(document);
|
|
15
|
-
expect(file.toString()).toMatchFileSnapshot('snapshots/output.md');
|
|
16
|
-
});
|
package/dist/mdast.d.ts
DELETED
package/dist/mdast.js
DELETED
package/dist/sample.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/sample.test.js
DELETED
package/dist/script.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): void;
|