Repository navigation
Conversation
server/remark-code-snippet.ts
|
Amplify deployment status
|
This was referenced Oct 26, 2026
aatuvai
force-pushed
the
aatuvai/2026-10-23-code-snippet-refactor
branch
from
October 27, 2026 06:49
0fcd702 to
6f863f2
Compare
Move the parsing of ```code snippets (commands, comments, multiline and heredoc commands, and inline <Var /> tags) out of server/remark-code-snippet.ts into src/utils/codeSnippet.ts, so that runtime components can use the same logic. The Remark plugin now builds its MDX nodes from the parser's output instead of parsing the text itself.
aatuvai
force-pushed
the
aatuvai/2026-10-23-code-snippet-refactor
branch
from
October 30, 2026 13:10
6f863f2 to
b159a49
Compare
This branch was successfully deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
server/remark-code-snippet.tsturns```codefences into copyable command snippets. It parses the snippet text and builds the MDX nodes in the same pass, which means the parsing could only run inside the remark plugin.This PR moves the parser out of the plugin, so a follow-up PR can add a runtime component that can use the same parsing logic in the browser.
Summary
src/utils/codeSnippet.ts, a parser with no dependencies that turns snippet text into a list of commands, comments, code lines and line breaks, with inline<Var />tags.remark-code-snippetnow builds its MDX nodes from the parser's output instead of parsing the text itself.Changes
src/utils/codeSnippet.ts(new file)parseCodeSnippethandles$commands,> host $commands,#descriptions,##comments, multiline commands ending in\, heredocs and empty lines.parseInlinesplits a line into text and<Var />tags.server/remark-code-snippet.tsparseCodeSnippetand a mapping from its nodes to the existingsnippet,command,commandline,commandcomment,codelineandbrelements.lint, the first diagnostic fails the file. Without it, errors are logged and warnings are ignored.<Var isGlobal="false" />and<Var isGlobal={false} />are no longer treated as global. Before, anyisGlobalattribute made the variable global.<Var />attributes can use single quotes or{...}. Before, anameordescriptionwritten that way crashed the build.<Var />without anameis reported as an error and left as text. Before, it crashed the build with aTypeError.<<'EOF, is now reported as an unclosed heredoc. Before, it crashed the build.src/utils/codeSnippet.test.ts(new) covers the parser, including the edge cases above.server/remark-code-snippet.test.tsis unchanged and passes.