Expand description
GitHub Permalink expansion.
This module provides functionality for parsing GitHub permalink URLs and fetching raw file content to display as code blocks.
Re-exportsยง
use futures_util::future::join_all;๐use regex::Regex;๐use std::sync::LazyLock;๐use super::ExpandContext;๐use super::ExpandError;๐use super::ExpandedContent;๐use super::LinkExpander;๐use crate::config::BabyriteConfig;๐use crate::utils::escape_markdown;๐use crate::utils::inline_code;๐use crate::utils::language_for_path;๐
Structsยง
- GitHub
Expander - GitHub permalink expander.
- GitHub
Permalink - A parsed GitHub permalink.
- Limited
Body ๐ - Accumulates response chunks until its
ReadLimitis met,MAX_BODY_BYTESis exceeded by the retained bytes, orMAX_SKIPPED_BYTESis exceeded by the skipped ones. - Line
Range - A line range extracted from a GitHub permalink fragment.
- Read
Limit ๐ - The leading part of a body that needs to be read.
Enumsยง
- GitHub
Expand Error - Errors that can occur when expanding a GitHub permalink.
Constantsยง
- BOM_
SNIFF_ ๐BYTES - Number of leading bytes needed to tell a UTF-16 BOM from anything else.
- MAX_
BODY_ ๐BYTES - Maximum number of body bytes read from a raw response.
- MAX_
SKIPPED_ ๐BYTES - Maximum number of bytes discarded before the first displayed line.
- PROBE_
BYTES ๐ - Number of bytes read past the last needed line to tell whether more follows.
Staticsยง
- GITHUB_
PERMALINK_ ๐REGEX - Regex pattern for matching GitHub blob URLs.
Functionsยง
- ensure_
not_ ๐empty - Rejects a code block with nothing to show.
- is_
commit_ ๐sha - Returns true if the given string looks like a commit SHA (4-40 hex characters).
- read_
body_ ๐limited - Reads the response body chunk by chunk, stopping as soon as
limitis met. - shorten_
ref ๐ - Shortens a git ref for display. Commit SHAs are truncated to 7 characters; branch/tag names are returned as-is.
- truncate_
lines ๐ - Truncates lines to the given maximum, returning the joined string and whether truncation occurred.