Skip to content

Commit

Permalink
Fix script bugs (#1147)
Browse files Browse the repository at this point in the history
  • Loading branch information
blakehatch authored Jul 12, 2024
1 parent 0e265dc commit 2e85c90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 12 additions & 3 deletions docs/scripts/md_to_mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import remarkStringify from "remark-stringify";
import { visit } from "unist-util-visit";

const DEFAULT_TITLE = "Default Title";
const BLOCK_TYPES = ["warning", "note", "tip"];
const BLOCK_TYPES = ["caution", "note", "tip"];

export function parseMarkdown(markdown: string): Root {
return remark().use(remarkParse).parse(markdown) as Root;
Expand Down Expand Up @@ -98,6 +98,7 @@ function transformBlockquote(blockquote: Blockquote): RootContent | null {
const cleanedContentText = cleanBlockTypeFromContent(
contentText,
blockType,
firstText.match(/^\[\!(\w+)\]/)?.[1] || "",
);

return {
Expand All @@ -111,7 +112,11 @@ function transformBlockquote(blockquote: Blockquote): RootContent | null {
function extractBlockType(firstText: string): string | null {
const match = firstText.match(/^\[\!(\w+)\]/);
if (match?.[1]) {
const blockType = match[1].toLowerCase();
let blockType = match[1];
if (blockType.toUpperCase() === "WARNING") {
blockType = "caution";
}
blockType = blockType.toLowerCase();
if (BLOCK_TYPES.includes(blockType)) {
return blockType;
}
Expand Down Expand Up @@ -146,8 +151,12 @@ function extractBlockquoteContent(blockquote: Blockquote): string {
function cleanBlockTypeFromContent(
contentText: string,
blockType: string,
originalBlockType: string,
): string {
return contentText.replace(`[!${blockType.toUpperCase()}]`, "").trim();
return contentText
.replace(`[!${blockType.toUpperCase()}]`, "")
.replace(`[!${originalBlockType.toUpperCase()}]`, "")
.trim();
}

export function preserveInlineCode(content: RootContent[]): RootContent[] {
Expand Down
7 changes: 6 additions & 1 deletion docs/scripts/metaphase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ const generateTypeDescription = (type: Type): string => {
case "Box":
return `(box of ${getInnerType(0)})`;
case "String":
return "(String)";
return "";
case "HashMap":
return `(list of objects ${getInnerType(0)}: ${getInnerType(1)})`;
default: {
Expand Down Expand Up @@ -546,6 +546,11 @@ title: NativeLink Configuration
description: The NativeLink Configuration Reference
---
:::caution
This page is auto-generated and may contain some minor formatting errors.
If you find any, please feel free to open an issue in our [open-source repository](https://github.com/TraceMachina/nativelink/issues).
:::
This page documents the configuration options for NativeLink.
`;
Expand Down

0 comments on commit 2e85c90

Please sign in to comment.