-
-
Notifications
You must be signed in to change notification settings - Fork 290
feat: add llms markdown in doc pages #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shreya1510ss
wants to merge
9
commits into
keploy:main
Choose a base branch
from
shreya1510ss:add-llms-markdown
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7548ed0
feat(docs): add llms.txt/markdown generation plugin and Copy/View-as-…
shreya1510ss 7ed125a
feat(docs): formatted the code
shreya1510ss 9da4179
fix(docs): patch llms plugin for MDX partials, fix copy-button timer …
shreya1510ss 35336c3
fix(docs): handle quoted text with < or > in leftover component tag s…
shreya1510ss 986babe
fix(docs): fix 404 on copy/view as markdown for section index page
shreya1510ss 311dd28
fix(docs): preserve code-block content when stripping tags, fix copy-…
shreya1510ss da566b4
fix(docs): pinned the version for npm
shreya1510ss ae501bb
Revert "fix(docs): pinned the version for npm"
shreya1510ss b78e8cd
fix(docs): pinned the version of docusaurus-plugin
shreya1510ss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| diff --git a/node_modules/docusaurus-plugin-llms/lib/utils.js b/node_modules/docusaurus-plugin-llms/lib/utils.js | ||
| index ed9850cf..a714772e 100644 | ||
| --- a/node_modules/docusaurus-plugin-llms/lib/utils.js | ||
| +++ b/node_modules/docusaurus-plugin-llms/lib/utils.js | ||
| @@ -466,7 +466,7 @@ async function resolvePartialImports(content, filePath, importChain = new Set()) | ||
| // Pattern 1: import PartialName from './_partial.mdx' | ||
| // Pattern 2: import { PartialName } from './_partial.mdx' | ||
| // Create a fresh regex for each invocation to avoid lastIndex state leakage | ||
| - const createImportRegex = () => /^\s*import\s+(?:(\w+)|{\s*(\w+)\s*})\s+from\s+['"]([^'"]+_[^'"]+\.mdx?)['"];?\s*$/gm; | ||
| + const createImportRegex = () => /^\s*import\s+(?:(\w+)|{\s*(\w+)\s*})\s+from\s+['"]([^'"]+\.mdx?)['"];?\s*$/gm; | ||
| const imports = new Map(); | ||
| // First pass: collect all imports | ||
| let match; | ||
| @@ -474,10 +474,7 @@ async function resolvePartialImports(content, filePath, importChain = new Set()) | ||
| while ((match = importRegex.exec(content)) !== null) { | ||
| const componentName = match[1] || match[2]; | ||
| const importPath = match[3]; | ||
| - // Only process imports for partial files (containing underscore) | ||
| - if (importPath.includes('_')) { | ||
| - imports.set(componentName, importPath); | ||
| - } | ||
| + imports.set(componentName, importPath); | ||
| } | ||
| // Resolve each partial import | ||
| for (const [componentName, importPath] of imports) { | ||
| @@ -555,10 +552,63 @@ function cleanMarkdownContent(content, excludeImports = false, removeDuplicateHe | ||
| // - import "..."; (side-effect imports) | ||
| cleaned = cleaned.replace(/^\s*import\s+.*?;?\s*$/gm, ''); | ||
| } | ||
| + // Fenced code blocks (```lang ... ```) often contain '<...>' text that looks | ||
| + // exactly like a tag to the regexes below but isn't one -- a placeholder like | ||
| + // `wsl --install -d <Distribution Name>`, or a literal XML sample response | ||
| + // like `<User>...</User>`. None of the tag-stripping rules know about code | ||
| + // fences, so mask every whole fenced block out first and restore it verbatim | ||
| + // once stripping is done, the same way quoted prop strings are masked below. | ||
| + // Fences nested inside list items are indented (e.g. " ```shell"), so the | ||
| + // leading whitespace before the backticks is optional and not part of the | ||
| + // backreference -- only the backtick run itself has to match on both ends. | ||
| + const codeBlocks = []; | ||
| + cleaned = cleaned.replace(/^[ \t]*(`{3,})[^\n]*\n[\s\S]*?^[ \t]*\1[ \t]*$/gm, (block) => { | ||
| + codeBlocks.push(block); | ||
| + return `@@KEPLOY_CODEBLOCK_${codeBlocks.length - 1}@@`; | ||
| + }); | ||
| // Remove HTML tags, but preserve XML content in code blocks | ||
| // We need to be selective to avoid removing XML content from code blocks | ||
| // This regex targets common HTML tags while being more conservative about XML | ||
| cleaned = cleaned.replace(/<\/?(?:div|span|p|br|hr|img|a|strong|em|b|i|u|h[1-6]|ul|ol|li|table|tr|td|th|thead|tbody)\b[^>]*>/gi, ''); | ||
| + // Remove leftover custom (PascalCase) React component tags that MDX imports | ||
| + // resolve at real build time but that this plugin doesn't render. Self-closing | ||
| + // tags carry no readable child text, so they're dropped entirely; paired tags | ||
| + // often wrap real content (e.g. <TabItem>...</TabItem>), so only the tag | ||
| + // markers are stripped and their inner text is preserved. Order matters: the | ||
| + // self-closing pass must run first, or the second regex would partially match it. | ||
| + // | ||
| + // Docs also use <YOUR_INGRESS_HOST>-style ALL_CAPS placeholders for readers to | ||
| + // fill in their own values — these also start with a capital letter, so a real | ||
| + // component name is only treated as such when it contains a lowercase letter | ||
| + // and no underscore (true of every actual component in this codebase, never | ||
| + // true of these placeholders). | ||
| + const isRealComponentName = (name) => /[a-z]/.test(name) && !name.includes('_'); | ||
| + // Prop values can legitimately contain '<' or '>' inside quoted strings (e.g. | ||
| + // tools={["Linux kernel >= 5.10"]}), which would otherwise be mistaken for the | ||
|
shreya1510ss marked this conversation as resolved.
|
||
| + // tag's own boundary. Mask '<'/'>' found inside quoted spans first (escape-aware, | ||
| + // so a backslash-escaped quote like \" doesn't fool it into ending the string | ||
| + // early), run the simple original tag regex, then restore what remains. | ||
| + // The quote-matching alternatives are mutually exclusive at every position | ||
| + // (backslash-led vs not), so there's no ambiguity for the engine to backtrack | ||
| + // over -- this avoids the catastrophic-backtracking trap a naive version of | ||
| + // this fix hit earlier on ordinary prose full of apostrophes (don't, it's). | ||
| + const LT_MASK = '@@KEPLOY_LT@@'; | ||
| + const GT_MASK = '@@KEPLOY_GT@@'; | ||
| + // Only double-quoted strings need masking: every real prop value in this | ||
| + // codebase that contains '<' or '>' uses double quotes (verified against the | ||
| + // actual docs content). Single quotes are deliberately NOT masked here -- | ||
| + // they appear constantly as English contractions (it's, don't, Let's), and | ||
| + // masking them paired each stray apostrophe with whichever one came next in | ||
| + // the document, sometimes many paragraphs later, incorrectly treating | ||
| + // everything in between (including real tags) as "inside a string". | ||
| + const masked = cleaned.replace(/"(?:[^"\\]|\\.)*"/g, (q) => q.split('<').join(LT_MASK).split('>').join(GT_MASK)); | ||
| + const stripped = masked | ||
| + .replace(/<([A-Z]\w*)(?:\s+[^<>]*?)?\/>/g, (match, tagName) => isRealComponentName(tagName) ? '' : match) | ||
| + .replace(/<\/?([A-Z]\w*)(?:\s+[^<>]*?)?>/g, (match, tagName) => isRealComponentName(tagName) ? '' : match); | ||
| + cleaned = stripped.split(LT_MASK).join('<').split(GT_MASK).join('>'); | ||
| + // Restore fenced code blocks now that tag-stripping is done, so their | ||
| + // original content (placeholders, XML samples, etc.) is left untouched. | ||
| + cleaned = cleaned.replace(/@@KEPLOY_CODEBLOCK_(\d+)@@/g, (_match, index) => codeBlocks[Number(index)]); | ||
| // Remove redundant content that just repeats the heading (if requested) | ||
| if (removeDuplicateHeadings) { | ||
| // Split content into lines and process line by line | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import React, {useEffect, useRef, useState} from "react"; | ||
| import {Copy, Check, FileText, AlertCircle} from "lucide-react"; | ||
|
|
||
| /** | ||
| * MarkdownPageActions - "Copy page" / "View as Markdown" links, rendered | ||
| * directly under the page title (mirrors the docs.sarvam.ai / Mintlify | ||
| * pattern: title, then a thin actions row, then a divider, then body). | ||
| * Point at the .md twin generated by docusaurus-plugin-llms at build time. | ||
| */ | ||
| export default function MarkdownPageActions({mdUrl}) { | ||
| const [copyState, setCopyState] = useState("idle"); | ||
| const resetTimeoutRef = useRef(null); | ||
|
|
||
| useEffect(() => { | ||
| return () => clearTimeout(resetTimeoutRef.current); | ||
| }, []); | ||
|
|
||
| if (!mdUrl) return null; | ||
|
|
||
| const handleCopy = async () => { | ||
| clearTimeout(resetTimeoutRef.current); | ||
| setCopyState("copying"); | ||
| try { | ||
| const res = await fetch(mdUrl); | ||
| if (!res.ok) throw new Error(`Request failed: ${res.status}`); | ||
| const text = await res.text(); | ||
| await navigator.clipboard.writeText(text); | ||
| setCopyState("copied"); | ||
| } catch (e) { | ||
| setCopyState("error"); | ||
| } finally { | ||
| resetTimeoutRef.current = setTimeout(() => setCopyState("idle"), 2000); | ||
| } | ||
| }; | ||
|
|
||
| const copyLabel = | ||
| copyState === "copying" | ||
| ? "Copying…" | ||
| : copyState === "copied" | ||
| ? "Copied" | ||
| : copyState === "error" | ||
| ? "Copy failed" | ||
| : "Copy as Markdown"; | ||
|
shreya1510ss marked this conversation as resolved.
|
||
|
|
||
| const CopyIcon = | ||
| copyState === "copied" ? Check : copyState === "error" ? AlertCircle : Copy; | ||
|
|
||
| const copyColorClasses = | ||
| copyState === "copied" | ||
| ? "text-green-600 dark:text-green-500" | ||
| : copyState === "error" | ||
| ? "text-red-600 dark:text-red-500" | ||
| : "text-gray-500 dark:text-gray-400"; | ||
|
|
||
| const linkBase = | ||
| "inline-flex items-center gap-1 text-[12px] leading-[1.2] py-[0.2rem] px-2 m-0 " + | ||
| "no-underline transition-colors duration-150 hover:text-[#ff914d] " + | ||
| "[&>svg]:shrink-0 [&>svg]:opacity-75"; | ||
|
|
||
| return ( | ||
| <div className="flex items-center mt-1.5 mb-3 pb-3 border-b border-black/[0.08] dark:border-white/10"> | ||
| <button | ||
| type="button" | ||
| className={`${linkBase} pl-0 w-[150px] justify-start whitespace-nowrap bg-transparent border-0 cursor-pointer disabled:cursor-default disabled:opacity-70 ${copyColorClasses}`} | ||
| onClick={handleCopy} | ||
| disabled={copyState === "copying"} | ||
| > | ||
| <CopyIcon size={12} strokeWidth={2} aria-hidden="true" /> | ||
| {copyLabel} | ||
| </button> | ||
| <a | ||
| className={`${linkBase} border-l border-black/[0.12] dark:border-white/[0.14] text-gray-500 dark:text-gray-400`} | ||
| href={mdUrl} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| <FileText size={12} strokeWidth={2} aria-hidden="true" /> | ||
| View as Markdown | ||
| </a> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docsDiris hardcoded toversioned_docs/version-4.0.0— will need updating when we cut the next docs version, since the buttons show on whatever the latest version is (gated onisLatestVersion).