Skip to content

Commit

Permalink
chore(docs): resolve pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wingkwong committed Oct 20, 2024
1 parent ab1aab9 commit 86ec1fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions apps/docs/components/docs/components/codeblock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const Codeblock = forwardRef<HTMLPreElement, CodeblockProps>(
const isCopy = token.types.includes("copy");

return isCopy ? (
<span className="copy-token" style={{whiteSpace: "inherit"}}>
<span key={key} className="copy-token" style={{whiteSpace: "inherit"}}>
{token.folderContent?.map((folderTokens) => {
return folderTokens.map((token, index) => {
// Hack for wrap line
Expand Down Expand Up @@ -257,7 +257,7 @@ const Codeblock = forwardRef<HTMLPreElement, CodeblockProps>(
};

return isFolder ? (
<details open={folderLine.open ? true : undefined}>
<details key={`${folderLine.index}`} open={folderLine.open ? true : undefined}>
<summary className="cursor-pointer">
{renderLine(folderLine.summaryContent as any, folderLine.index!, "span")}
</summary>
Expand Down
18 changes: 10 additions & 8 deletions apps/docs/components/docs/components/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function transformTokens(tokens: TransformTokens, folderLine = 10) {
}

let startToken: TransformTokens[0][0] = null as any;
let mergedStarFlagList = [...startFlag];
let mergedStartFlagList = [...startFlag];

token.forEach((t) => {
if (defaultFoldFlagList.some((text) => t.content.includes(text))) {
Expand All @@ -53,10 +53,10 @@ export function transformTokens(tokens: TransformTokens, folderLine = 10) {
}

fold = true;
mergedStarFlagList.push(...specialStartFlag);
mergedStartFlagList.push(...specialStartFlag);
}

if (mergedStarFlagList.includes(t.content)) {
if (mergedStartFlagList.includes(t.content)) {
startToken = t;
}

Expand Down Expand Up @@ -113,7 +113,9 @@ export function transformTokens(tokens: TransformTokens, folderLine = 10) {
...endToken,
];
(startToken as TransformTokensTypes).index = index;
isShowFolder && !fold && ((startToken as TransformTokensTypes).open = true);
if (isShowFolder && !fold) {
(startToken as TransformTokensTypes).open = true;
}

result.push([startToken]);

Expand Down Expand Up @@ -142,11 +144,11 @@ function checkIsFolder(
{specialStartFlag, specialEndFlag}: SpecialOptions = {},
) {
const stack: string[] = [];
const mergedStarFlagList = specialStartFlag ? [...startFlag, ...specialStartFlag] : startFlag;
const mergedStartFlagList = specialStartFlag ? [...startFlag, ...specialStartFlag] : startFlag;
const mergedEndFlagList = specialEndFlag ? [...endFlag, ...specialEndFlag] : endFlag;

for (const t of token) {
if (mergedStarFlagList.includes(t.content)) {
if (mergedStartFlagList.includes(t.content)) {
stack.push(t.content);
} else if (mergedEndFlagList.includes(t.content)) {
stack.pop();
Expand All @@ -162,7 +164,7 @@ function findEndIndex(
{specialStartFlag, specialEndFlag}: SpecialOptions = {},
) {
const stack: string[] = ["flag"];
const mergedStarFlagList = specialStartFlag ? [...startFlag, ...specialStartFlag] : startFlag;
const mergedStartFlagList = specialStartFlag ? [...startFlag, ...specialStartFlag] : startFlag;
const mergedEndFlagList = specialEndFlag ? [...endFlag, ...specialEndFlag] : endFlag;

for (let i = startIndex; i < tokens.length; i++) {
Expand All @@ -171,7 +173,7 @@ function findEndIndex(
for (const line of token) {
const transformLine = line.content.replace(/\$/g, "");

if (mergedStarFlagList.includes(transformLine)) {
if (mergedStartFlagList.includes(transformLine)) {
stack.push("flag");
} else if (mergedEndFlagList.includes(transformLine)) {
stack.pop();
Expand Down

0 comments on commit 86ec1fc

Please sign in to comment.