@grafana/plugin-docs-parser 0.0.4 → 0.0.5-canary.2611.25322408244.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/dist/index.d.ts
CHANGED
package/dist/parser.js
CHANGED
|
@@ -26,7 +26,10 @@ function parseMarkdown(content, options) {
|
|
|
26
26
|
}
|
|
27
27
|
const processor = unified().use(remarkParse).use(remarkGfm).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw).use(rehypeStripH1).use(rehypeSlug);
|
|
28
28
|
if (options?.assetBaseUrl) {
|
|
29
|
-
processor.use(rehypeRewriteAssetPaths, {
|
|
29
|
+
processor.use(rehypeRewriteAssetPaths, {
|
|
30
|
+
assetBaseUrl: options.assetBaseUrl,
|
|
31
|
+
file: options.file
|
|
32
|
+
});
|
|
30
33
|
}
|
|
31
34
|
processor.use(rehypeRewriteDocLinks);
|
|
32
35
|
processor.use(rehypeSanitize, sanitizeSchema);
|
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
2
|
|
|
3
|
+
const SYNTHETIC_ORIGIN = "https://_resolver_.local";
|
|
4
|
+
function isAbsoluteHttpUrl(value) {
|
|
5
|
+
return /^https?:\/\//i.test(value);
|
|
6
|
+
}
|
|
7
|
+
function ensureTrailingSlash(value) {
|
|
8
|
+
return value.endsWith("/") ? value : value + "/";
|
|
9
|
+
}
|
|
10
|
+
function resolveSrc(src, assetBaseUrl, file) {
|
|
11
|
+
const baseWithSlash = ensureTrailingSlash(assetBaseUrl);
|
|
12
|
+
const isAbs = isAbsoluteHttpUrl(assetBaseUrl);
|
|
13
|
+
const fullBase = isAbs ? new URL(baseWithSlash) : new URL(baseWithSlash, SYNTHETIC_ORIGIN);
|
|
14
|
+
let dirBase = fullBase;
|
|
15
|
+
if (file) {
|
|
16
|
+
const lastSlash = file.lastIndexOf("/");
|
|
17
|
+
if (lastSlash >= 0) {
|
|
18
|
+
dirBase = new URL(file.slice(0, lastSlash + 1), fullBase);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const resolved = new URL(src, dirBase);
|
|
22
|
+
if (isAbs) {
|
|
23
|
+
return resolved.toString();
|
|
24
|
+
}
|
|
25
|
+
return resolved.pathname + resolved.search + resolved.hash;
|
|
26
|
+
}
|
|
3
27
|
function rehypeRewriteAssetPaths(options) {
|
|
4
|
-
const base = options.assetBaseUrl.replace(/\/$/, "");
|
|
5
28
|
return (tree) => {
|
|
6
29
|
visit(tree, "element", (node) => {
|
|
7
30
|
if (node.tagName !== "img") {
|
|
@@ -14,7 +37,7 @@ function rehypeRewriteAssetPaths(options) {
|
|
|
14
37
|
if (src.startsWith("http://") || src.startsWith("https://") || src.startsWith("//") || src.startsWith("data:") || src.startsWith("blob:") || src.startsWith("/")) {
|
|
15
38
|
return;
|
|
16
39
|
}
|
|
17
|
-
node.properties.src =
|
|
40
|
+
node.properties.src = resolveSrc(src, options.assetBaseUrl, options.file);
|
|
18
41
|
});
|
|
19
42
|
};
|
|
20
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/plugin-docs-parser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5-canary.2611.25322408244.0",
|
|
4
4
|
"description": "A lightweight library for parsing Grafana plugin documentation from markdown to HAST.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"hast-util-to-html": "^9.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "8d1a525dd6712cdfa70c3fad9f678a9f7e06bb0d"
|
|
64
64
|
}
|