@darajs/components 1.20.1 → 1.20.2
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/common/markdown/markdown.d.ts.map +1 -1
- package/dist/common/markdown/markdown.js +40 -1
- package/dist/common/markdown/markdown.js.map +1 -1
- package/dist/dara_components-1.20.2-py3-none-any.whl +0 -0
- package/dist/umd/dara.components.umd.js +119827 -159992
- package/package.json +14 -13
- package/dist/dara_components-1.20.1-py3-none-any.whl +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../js/common/markdown/markdown.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../js/common/markdown/markdown.tsx"],"names":[],"mappings":"AAKA,OAAO,EACH,KAAK,oBAAoB,EACzB,KAAK,QAAQ,EAKhB,MAAM,cAAc,CAAC;AAGtB,UAAU,aAAc,SAAQ,oBAAoB;IAChD;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CACvC;AAyCD;;GAEG;AACH,iBAAS,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,GAAG,CAAC,OAAO,CAsBnD;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import rehypeRaw from 'rehype-raw';
|
|
3
|
-
import {
|
|
3
|
+
import { visit } from 'unist-util-visit';
|
|
4
|
+
import { injectCss, prependBaseUrl, useComponentStyles, useVariable, } from '@darajs/core';
|
|
4
5
|
import { Markdown as UiMarkdown } from '@darajs/ui-components';
|
|
5
6
|
const CustomMarkdown = injectCss(UiMarkdown);
|
|
7
|
+
/**
|
|
8
|
+
* Rehype plugin that prepends the window.dara.base_url to all /static url attributes
|
|
9
|
+
*/
|
|
10
|
+
function prependBaseUrlToStaticUrls() {
|
|
11
|
+
return (tree) => {
|
|
12
|
+
visit(tree, 'element', (node) => {
|
|
13
|
+
if (!node.properties) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// Attributes that may contain URLs
|
|
17
|
+
const urlAttrs = ['src', 'href', 'data', 'srcset', 'action'];
|
|
18
|
+
for (const attr of urlAttrs) {
|
|
19
|
+
const value = node.properties[attr];
|
|
20
|
+
if (typeof value === 'string') {
|
|
21
|
+
// Special case: srcset can contain multiple URLs
|
|
22
|
+
if (attr === 'srcset') {
|
|
23
|
+
node.properties[attr] = value
|
|
24
|
+
.split(',')
|
|
25
|
+
.map((part) => {
|
|
26
|
+
const [url, size] = part.trim().split(/\s+/, 2);
|
|
27
|
+
if (url) {
|
|
28
|
+
return `${prependBaseUrl(url)}${size ? ` ${size}` : ''}`;
|
|
29
|
+
}
|
|
30
|
+
return part.trim();
|
|
31
|
+
})
|
|
32
|
+
.join(', ');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
node.properties[attr] = prependBaseUrl(value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|
|
6
42
|
/**
|
|
7
43
|
* A component for rendering markdown
|
|
8
44
|
*/
|
|
@@ -10,9 +46,12 @@ function Markdown(props) {
|
|
|
10
46
|
const [style, css] = useComponentStyles(props);
|
|
11
47
|
const [markdown] = useVariable(props.markdown);
|
|
12
48
|
const rehypePlugins = [];
|
|
49
|
+
// raw must be before prependBaseUrlToStaticUrls, as we want
|
|
50
|
+
// the prepended base url to be applied to the raw html as well
|
|
13
51
|
if (props.html_raw) {
|
|
14
52
|
rehypePlugins.push(rehypeRaw);
|
|
15
53
|
}
|
|
54
|
+
rehypePlugins.push(prependBaseUrlToStaticUrls);
|
|
16
55
|
return (_jsx(CustomMarkdown, { "$rawCss": css, className: props.className, style: style, markdown: markdown, rehypePlugins: rehypePlugins }));
|
|
17
56
|
}
|
|
18
57
|
export default Markdown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../js/common/markdown/markdown.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../js/common/markdown/markdown.tsx"],"names":[],"mappings":";AACA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAGH,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,WAAW,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAa/D,MAAM,cAAc,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;AAE7C;;GAEG;AACH,SAAS,0BAA0B;IAC/B,OAAO,CAAC,IAAU,EAAE,EAAE;QAClB,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBACnB,OAAO;YACX,CAAC;YAED,mCAAmC;YACnC,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAE7D,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;gBACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC5B,iDAAiD;oBACjD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;wBACpB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK;6BACxB,KAAK,CAAC,GAAG,CAAC;6BACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;4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