Skip to content

Commit

Permalink
fix: 特殊情形 markdown 标题解析失败会阻塞前台页面更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Sep 28, 2022
1 parent c00d36f commit 10db49c
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions packages/website/components/Markdown/tools.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
export const getChildrenText = (children: any): any => {
if (!children) {
return "";
}
let result = "";
children.forEach((c: any) => {
if (typeof c == "string") {
result = result + c;
}
if (typeof c == "object") {
result = result + c?.props?.children;
}
});
return result;
try {
children.forEach((c: any) => {
if (typeof c == "string") {
result = result + c;
} else if (typeof c == "object") {
if (c?.props?.children && typeof c?.props?.children == "string") {
result = result + c?.props?.children;
}
} else {
if (c?.props?.children && typeof c?.props?.children == "string") {
result = result + c?.props?.children;
}
}
});
return result;
} catch (err) {
console.log("获取 heading text 失败:", JSON.stringify(err, null, 2));
return result || "";
}
};

0 comments on commit 10db49c

Please sign in to comment.