feat(github-code): block to embed GitHub source with line ranges#1082
Open
markdaugherty wants to merge 7 commits into
Open
feat(github-code): block to embed GitHub source with line ranges#1082markdaugherty wants to merge 7 commits into
markdaugherty wants to merge 7 commits into
Conversation
Adds a github-code block that fetches a file from a GitHub blob URL (with optional #L start-end line range) via raw.githubusercontent.com, renders it in a pre/code block, and highlights it with the existing locally-hosted highlight.js library (atom-one-dark). Includes a copy button matching the guide-template pattern and a View on GitHub link. Adds a drafts test page covering line-range, single-line, and whole-file. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…font Export addCopyButtonsToCodeBlocks from scripts.js and call it from the github-code block instead of duplicating the copy-button implementation. Make the View on GitHub link inherit the header font size so it matches the file-path label. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
|
|
Adopts column-number permalink parsing, trailing-newline fix, line-range validation, path decoding, a ref badge, and a show-more/fewer toggle for long files from the benpeter/code-block reference, while keeping this project's rb/jsx language mappings (ruby and javascript are the only bundled grammars that matter here) and its own highlight.js loading so copy buttons and highlighting still work standalone. Also fixes a race where multiple blocks loading highlight.js at once could silently skip highlighting. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
A bare blob URL alone in its paragraph becomes a github-code block, so docs can drop the file link without authoring a block. The guards keep it to default-content paragraphs: the link text must equal the href, the paragraph must hold only that link, and its parent div must sit directly under main. Links inside prose, lists, blockquotes, or authored block cells are left alone. The block already reads its URL from the anchor, so no block change is needed.
The build registered only bash, css, javascript, ruby, and yaml. HTML and JSON code fell back to no-highlight, so the block renders those files in the themed panel without token colors. Appended the official 11.7.0 compiled grammar modules from cdnjs so html and json samples get syntax coloring.
markdaugherty
marked this pull request as ready for review
July 20, 2026 20:07
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.
Summary
Adds a new
github-codeblock that embeds source code from a GitHub repository, with an optional line-number range.https://github.com/owner/repo/blob/main/path/file.js#L10-L20) — or a GitHub "Copy permalink" URL with column numbers (#L10C1-L20C5) — or just a bare URL with no link markup; the block parses owner/repo/ref/path and the optional line range.github-codeblock, so authors can just drop the link in without building the block table by hand. Links inside prose, lists, blockquotes, or authored block cells are left untouched.raw.githubusercontent.com, slicing to the requested lines (whole file if no range), and strips the trailing blank line raw GitHub files end with.pre > codeand highlights via the existing locally-hosted highlight.js (/libs/highlight/, atom-one-dark), loaded lazily on scroll-into-view — mirroring the guide-template code-block pattern.addCopyButtonsToCodeBlockshelper (now exported fromscripts.js) for the copy button.Preview
https://feature-github-code-block--helix-website--adobe.aem.page/drafts/mdaugherty/github-code-block
Notes
hljsclass itself so the background stays consistent and skips the highlighter when a grammar isn't available (avoids console warnings).addCopyButtonsToCodeBlocks()scans the document and is idempotent (skipspres that already have a button), matching the guide-template behavior.github-codeblocks becoming visible at once could each call the sharedloadScripthelper independently; since that helper resolves as soon as it sees a matching<script>tag (even one still loading), later blocks could silently skip highlighting. The block now memoizes a single load promise per page.Testing
npm run lintclean for JS and CSS.🤖 Generated with Claude Code