Skip to content

Add Snippets support to Github Files #832

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
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ntindle
Copy link

@ntindle ntindle commented May 28, 2025

We're looking at migrating over from mkdocs-material and one of the features we use heavily is snippets based on https://facelessuser.github.io/pymdown-extensions/extensions/snippets/

This brings over a simple version of that to cover our needs

Copy link

changeset-bot bot commented May 28, 2025

⚠️ No Changeset found

Latest commit: 6d5f643

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@SamyPesse
Copy link
Member

Hey @ntindle I'll take a look over the weekend and make sure that we support it, through this PR or another

@ntindle
Copy link
Author

ntindle commented Jun 2, 2025

Some of the things we'd want to add, but don't need

  • Support for showing by owner/repo, branch, and tag
  • support for branches on previews showing docs correctly

multi snippets in one code block
image

@ntindle
Copy link
Author

ntindle commented Jun 4, 2025

maybe fixes #446

import { getFileExtension } from './utils';

const embedBlock = createComponent<
{ url?: string },
{ visible: boolean },
{ url?: string; visible?: boolean },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixes the hide/show header

@@ -130,6 +140,710 @@ const embedBlock = createComponent<
},
});

const snippetBlock = createComponent<
Copy link
Author

@ntindle ntindle Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adds a snippet block that takes in a URL and one or more snippet tag

},
});

const simpleGithubBlock = createComponent<
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds a block that lets you query by owner/repo/branch/file/snippets + supports multiple snippets

Comment on lines +23 to +25
**GitHub Snippet**: Insert the snippet block, provide a GitHub URL and a snippet tag (e.g., "BaseOAuthExample"), and the integration will extract and display only the code between the `--8<-- [start:tag]` and `--8<-- [end:tag]` markers. You can also add multiple snippets to combine them into a single code block.

**Simple GitHub Reference**: Insert the simple GitHub block and provide repository details (owner, repo, branch, file path) for an easier way to reference files without full URLs.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these could probably use some work on clarity

Comment on lines +8 to +11
const constructGithubUrl = (owner: string, repo: string, branch: string, filePath: string) => {
return `https://github.com/${owner}/${repo}/blob/${branch}/${filePath}`;
};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically this won't work for self hosted github enterprise server instances, not sure if that matters. If so, we can change the config to include a baseline root URL

@ntindle ntindle marked this pull request as ready for review June 5, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants