rspress-plugin-api-extractor 0.18.3 → 0.18.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rspress-plugin-api-extractor",
3
- "version": "0.18.3",
3
+ "version": "0.18.4",
4
4
  "private": false,
5
5
  "description": "RSPress plugin for generating API documentation from TypeScript API Extractor models",
6
6
  "keywords": [
@@ -56,10 +56,10 @@
56
56
  "@shikijs/twoslash": "^4.4.3",
57
57
  "@tsdoctor/bundle": "0.5.1",
58
58
  "@tsdoctor/manifest": "0.2.2",
59
- "@tsdoctor/model": "0.8.2",
60
- "@tsdoctor/pages": "0.3.3",
59
+ "@tsdoctor/model": "0.8.3",
60
+ "@tsdoctor/pages": "0.3.4",
61
61
  "@tsdoctor/registry": "0.5.1",
62
- "@tsdoctor/seo": "0.4.1",
62
+ "@tsdoctor/seo": "0.4.2",
63
63
  "@tsdoctor/snapshot": "0.4.0",
64
64
  "@tsdoctor/vfs": "0.4.0",
65
65
  "@typescript/vfs": "^1.6.5",
@@ -6,7 +6,7 @@ import { setTwoslashFile } from "./twoslash-access.js";
6
6
  import { createTwoslashTimingWrapper } from "./twoslash-timing-wrapper.js";
7
7
  import { formatCode } from "./prettier-formatter.js";
8
8
  import { stripTwoslashDirectives } from "@tsdoctor/pages";
9
- import { codeToHast, hastToHtml } from "shiki";
9
+ import { codeToHast } from "shiki";
10
10
  import { visit } from "unist-util-visit";
11
11
 
12
12
  //#region src/remark-with-api.ts
@@ -108,14 +108,14 @@ const remarkWithApi = (options) => {
108
108
  slow: isSlow,
109
109
  level: "debug"
110
110
  }));
111
+ const displayCode = stripTwoslashDirectives(code);
111
112
  if (parent && typeof index === "number") {
112
113
  if (isSsgMd) {
113
- const cleanCode = hastToHtml(hast).replace(/<[^>]*>/g, "").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, "\"").replace(/&#39;/g, "'").trim();
114
+ const cleanCode = displayCode.trim();
114
115
  node.lang = "typescript";
115
116
  node.meta = void 0;
116
117
  node.value = cleanCode;
117
118
  } else {
118
- const displayCode = stripTwoslashDirectives(code);
119
119
  const hastJson = JSON.stringify(hast);
120
120
  const mdxNode = {
121
121
  type: "mdxJsxFlowElement",
@@ -1,4 +1,5 @@
1
1
  import { MarkdownContent } from "../MarkdownContent/index.js";
2
+ import { stripTags } from "../../utils/strip-tags.js";
2
3
  import index_module_default from "./index.module.js";
3
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
5
 
@@ -17,7 +18,7 @@ const EnumMembersTable = ({ members }) => {
17
18
  for (const member of members) {
18
19
  const name = `\`${member.name}\``;
19
20
  const value = member.value ? `\`${member.value}\`` : "";
20
- const description = member.description.replace(/<[^>]*>/g, "").trim();
21
+ const description = stripTags(member.description).trim();
21
22
  markdown += `| ${name} | ${value} | ${description} |\n`;
22
23
  }
23
24
  return /* @__PURE__ */ jsx(Fragment, { children: markdown });
@@ -1,4 +1,5 @@
1
1
  import { MarkdownContent } from "../MarkdownContent/index.js";
2
+ import { stripTags } from "../../utils/strip-tags.js";
2
3
  import index_module_default from "./index.module.js";
3
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
5
 
@@ -17,7 +18,7 @@ const ParametersTable = ({ parameters }) => {
17
18
  for (const param of parameters) {
18
19
  const name = `\`${param.name}\``;
19
20
  const type = param.type ? `\`${param.type}\`` : "";
20
- const description = param.description.replace(/<[^>]*>/g, "").trim();
21
+ const description = stripTags(param.description).trim();
21
22
  markdown += `| ${name} | ${type} | ${description} |\n`;
22
23
  }
23
24
  return /* @__PURE__ */ jsx(Fragment, { children: markdown });
@@ -0,0 +1,28 @@
1
+ //#region src/runtime/utils/strip-tags.ts
2
+ /**
3
+ * Remove every `<...>` tag from `text`, keeping the text between tags.
4
+ *
5
+ * A linear scan with the same result as `text.replace(/<[^>]*>/g, "")`: each
6
+ * `<` that has a later `>` is dropped through that `>`, and a `<` with no `>`
7
+ * after it is kept along with the rest of the string. The regex form
8
+ * backtracks quadratically on a long run of unclosed `<`.
9
+ *
10
+ * This is text cleanup for markdown output, not HTML sanitization; the result
11
+ * is rendered as a React text child, which escapes it.
12
+ */
13
+ function stripTags(text) {
14
+ let out = "";
15
+ let i = 0;
16
+ while (i < text.length) {
17
+ const open = text.indexOf("<", i);
18
+ if (open === -1) return out + text.slice(i);
19
+ const close = text.indexOf(">", open + 1);
20
+ if (close === -1) return out + text.slice(i);
21
+ out += text.slice(i, open);
22
+ i = close + 1;
23
+ }
24
+ return out;
25
+ }
26
+
27
+ //#endregion
28
+ export { stripTags };