@zero-library/common 2.4.0 → 2.4.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/index.cjs.js +23 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +18 -11
- package/dist/index.d.ts +18 -11
- package/dist/index.esm.js +23 -9
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1521,7 +1521,7 @@ var RenderMarkdown_default = ({ content = "", searchValue, customComponents, ...
|
|
|
1521
1521
|
}, [content, searchValue]);
|
|
1522
1522
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ns-markdown", children: reactContent });
|
|
1523
1523
|
};
|
|
1524
|
-
var MarkdownPreview_default = ({ fileUrl, searchValue }) => {
|
|
1524
|
+
var MarkdownPreview_default = ({ fileUrl, searchValue, asPlainText }) => {
|
|
1525
1525
|
const [content, setContent] = React.useState("");
|
|
1526
1526
|
const [error, setError] = React.useState("");
|
|
1527
1527
|
const fetchMarkdown = async () => {
|
|
@@ -1529,29 +1529,41 @@ var MarkdownPreview_default = ({ fileUrl, searchValue }) => {
|
|
|
1529
1529
|
if (res.status !== 200) {
|
|
1530
1530
|
throw new Error(`\u8BF7\u6C42\u5931\u8D25\uFF0C\u72B6\u6001\u7801: ${res.status}`);
|
|
1531
1531
|
}
|
|
1532
|
-
const
|
|
1533
|
-
if (!
|
|
1532
|
+
const content2 = await res.text();
|
|
1533
|
+
if (!content2) {
|
|
1534
1534
|
throw new Error("\u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A");
|
|
1535
1535
|
}
|
|
1536
|
-
|
|
1536
|
+
return content2;
|
|
1537
1537
|
};
|
|
1538
1538
|
const init = async () => {
|
|
1539
1539
|
setContent("");
|
|
1540
1540
|
setError("");
|
|
1541
1541
|
if (fileUrl) {
|
|
1542
1542
|
try {
|
|
1543
|
-
await fetchMarkdown();
|
|
1544
|
-
|
|
1545
|
-
|
|
1543
|
+
const content2 = await fetchMarkdown();
|
|
1544
|
+
setContent(content2);
|
|
1545
|
+
} catch {
|
|
1546
|
+
setError("\u52A0\u8F7D\u6216\u89E3\u6790\u6587\u4EF6\u5931\u8D25");
|
|
1546
1547
|
}
|
|
1547
1548
|
} else {
|
|
1548
|
-
setError("
|
|
1549
|
+
setError("\u6587\u4EF6\u5730\u5740\u9519\u8BEF");
|
|
1549
1550
|
}
|
|
1550
1551
|
};
|
|
1551
1552
|
React.useEffect(() => {
|
|
1552
1553
|
init();
|
|
1553
1554
|
}, [fileUrl]);
|
|
1554
|
-
|
|
1555
|
+
const wrapInCodeFence = (text) => {
|
|
1556
|
+
const matches = text.match(/`+/g) ?? [];
|
|
1557
|
+
const maxRun = matches.reduce((max, run) => Math.max(max, run.length), 0);
|
|
1558
|
+
const fence = "`".repeat(Math.max(3, maxRun + 1));
|
|
1559
|
+
return `${fence}
|
|
1560
|
+
${text}
|
|
1561
|
+
${fence}`;
|
|
1562
|
+
};
|
|
1563
|
+
const newContent = React.useMemo(() => {
|
|
1564
|
+
return content ? asPlainText ? wrapInCodeFence(content) : content : "";
|
|
1565
|
+
}, [content, asPlainText]);
|
|
1566
|
+
return error ? /* @__PURE__ */ jsxRuntime.jsx(antd.Result, { status: "error", title: error }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "height-full width-full", children: /* @__PURE__ */ jsxRuntime.jsx(RenderMarkdown_default, { content: newContent, searchValue }) });
|
|
1555
1567
|
};
|
|
1556
1568
|
|
|
1557
1569
|
// src/hooks/iframe/iframeRelay.ts
|
|
@@ -2388,6 +2400,8 @@ var FilePreview_default = ({ suffix, fileUrl, pdfParams, password, searchValue,
|
|
|
2388
2400
|
case "MD":
|
|
2389
2401
|
case "MARKDOWN":
|
|
2390
2402
|
return /* @__PURE__ */ jsxRuntime.jsx(MarkdownPreview_default, { fileUrl, searchValue });
|
|
2403
|
+
case "TXT":
|
|
2404
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MarkdownPreview_default, { fileUrl, searchValue, asPlainText: true });
|
|
2391
2405
|
case "DOCX":
|
|
2392
2406
|
return /* @__PURE__ */ jsxRuntime.jsx(DocxPreview_default, { fileUrl });
|
|
2393
2407
|
default:
|