@pierre/diffs is an open source diff and code rendering library. It's built on Shiki for syntax highlighting and theming, is super customizable, and comes packed with features. Made with love by The Pierre Computer Company.
Currently v1.0.7
Choose from stacked (unified) or split (side-by-side). Both use CSS Grid and Shadow DOM under the hood, meaning fewer DOM nodes and faster rendering.
11 unmodified lines12131415161718ThemesType,} from '../types';export function createSpanFromToken(token: ThemedToken) {const element = document.createElement('div');const style = getTokenStyleObject(token);element.style = stringifyTokenStyle(style);19202122232425262728293031323334353637return element;}export function createRow(line: number) {const row = document.createElement('div');row.dataset.line = `${line}`;const lineColumn = document.createElement('div');lineColumn.dataset.columnNumber = '';lineColumn.textContent = `${line}`;const content = document.createElement('div');content.dataset.columnContent = '';row.appendChild(lineColumn);row.appendChild(content);return { row, content };}30 unmodified lines11 unmodified lines12131415161718192021222324252627ThemesType,} from '../types';export function createSpanFromToken(token: ThemedToken) {const element = document.createElement('span');const style = token.htmlStyle ?? getTokenStyleObject(token);element.style = stringifyTokenStyle(style);element.textContent = token.content;element.dataset.span = ''return element;}export function createRow(line: number) {const row = document.createElement('div');row.dataset.line = `${line}`;282930const content = document.createElement('div');content.dataset.columnContent = '';31323334row.appendChild(content);return { row, content };}30 unmodified lines
We built @pierre/diffs on top of Shiki for syntax highlighting and general theming. Our components automatically adapt to blend in with your theme selection, including across color modes.
123456789101112use std::io;fn main() {println!("What is your name?");let mut name = String::new();io::stdin().read_line(&mut name).unwrap();println!("Hello, {}", name.trim());}fn add(x: i32, y: i32) -> i32 {return x + y;}123456789101112use std::io;fn main() {println!("Enter your name:");let mut name = String::new();io::stdin().read_line(&mut name).expect("read error");println!("Hello, {}!", name.trim());}fn add(a: i32, b: i32) -> i32 {a + b}
Love the Pierre themes? Install our Pierre Theme pack with light and dark flavors.
Your diffs, your choice. Render changed lines with classic diff indicators (+/–), full-width background colors, or vertical bars. You can even highlight inline changes—character or word based—and toggle line wrapping, hide numbers, and more.
12345const std = @import("std");const Allocator = std.heap.page_allocator;const ArrayList = std.ArrayList;pub fn main() !void {678910const stdout_writer_instance = std.io.getStdOut().writer();try stdout_writer_instance.print("Hi You, {s}! Welcome to our application.\n", .{"World"});var list = ArrayList(i32).init(allocator);defer list.deinit();11121314const configuration_options = .{ .enable_logging = true, .max_buffer_size = 1024, .timeout_milliseconds = 5000 };_ = configuration_options;}12345678910111213141516171819const std = @import("std");const GeneralPurposeAllocator = std.heap.GeneralPurposeAllocator;const ArrayList = std.ArrayList;pub fn main() !void {var gpa = GeneralPurposeAllocator(.{}){};defer _ = gpa.deinit();const allocator = gpa.allocator();const stdout_writer_instance = std.io.getStdOut().writer();try stdout_writer_instance.print("Hello There, {s}! Welcome to the updated Zig application.\n", .{"Zig"});var list = ArrayList(i32).init(allocator);defer list.deinit();try list.append(42);const configuration_options = .{ .enable_logging = true, .max_buffer_size = 2048, .timeout_milliseconds = 10000, .retry_count = 3 };_ = configuration_options;}
@pierre/diffs adapts to any font, font-size, line-height, and even font-feature-settings you may have set. Configure font options with your preferred CSS method globally or on a per-component basis.
38 unmodified lines3940414243444543464748495051 if !exists { return nil, false }
now := time.Now() expired := now.After(item.ExpiresAt) if expired { if time.Now().After(item.ExpiresAt) { delete(c.items, key) c.onEviction(key, item.Value) return nil, false }
return item.Value, true10 unmodified linesUse renderHeaderMetadata to inject custom content and components into the file header. Perfect for adding view toggles, theme switchers, copy buttons, or any other file-level actions while preserving the built-in header.
4 unmodified lines5678let apiBaseURL: URLlet timeout: TimeIntervallet maxRetries: Int910111213private init() {self.apiBaseURL = URL(string: "https://api.example.com")!self.timeout = 30.0self.maxRetries = 3141516171819}func headers() -> [String: String] {return ["Content-Type": "application/json","Accept": "application/json"20]2122}}4 unmodified lines567891011121314151617181920212223242526272829let apiBaseURL: URLlet timeout: TimeIntervallet maxRetries: Intlet enableLogging: Boolprivate init() {self.apiBaseURL = URL(string: "https://api.example.com/v2")!self.timeout = 60.0self.maxRetries = 5self.enableLogging = true}func headers(token: String? = nil) -> [String: String] {var headers = ["Content-Type": "application/json","Accept": "application/json","X-API-Version": "2.0"]if let token = token {headers["Authorization"] = "Bearer \(token)"}return headers}}
@pierre/diffs provide a flexible annotation framework for injecting additional content and context. Use it to render your own line comments, annotations from CI jobs, and other third-party content.
2 unmodified lines34567789101011121314151516171819202021from typing import Optional
SECRET_KEY = "your-secret-key"
def create_token(user_id: str, expires_in: int = 3600) -> str:def create_token(user_id: str, role: str = "user", expires_in: int = 3600) -> str: payload = { "sub": user_id, "role": role, "exp": time.time() + expires_in } return jwt.encode(payload, SECRET_KEY, algorithm="HS256")
def verify_token(token: str) -> Optional[str]:def verify_token(token: str) -> Optional[dict]: try: payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"]) if payload["exp"] < time.time(): return None return payload["sub"] return {"user_id": payload["sub"], "role": payload["role"]} except jwt.InvalidTokenError: return NoneShould we validate the role parameter? We could restrict it to a set of allowed values.
Good idea, maybe use a Literal type or an enum.
Agreed, we should also update verify_token to return the role.
Annotations can also be used to build interactive code review interfaces similar to AI-assisted coding tools like Cursor. Use it to track the state of each change, inject custom UI like accept/reject buttons, and provide immediate visual feedback.
4 unmodified lines56789109101111121314 <title>Welcome</title></head><body> <header> <h1>Welcome</h1> <p>Thanks for visiting</p> <h1>Welcome to Our Site</h1> <p>We're glad you're here</p> <a href="/about" class="btn">Learn More</a> </header> <footer> <p>© Acme Inc.</p> </footer>2 unmodified linesTurn on line selection with enableLineSelection: true. When enabled, clicking a line number will select that line. Click and drag to select multiple lines, or hold Shift and click to extend your selection. You can also control the selection programmatically. Also selections will elegantly manage the differences between split and unified views.
16 unmodified lines17181920212223242526}~Vector() {delete[] data;data = nullptr;}void push_back(const T& value) {if (length >= capacity) {reserve(capacity * 2);2728293031323334353637}data[length++] = value;}T& operator[](size_t index) {if (index >= length) {throw std::out_of_range("Index out of bounds");}return data[index];}38394041size_t size() const { return length; }bool empty() const { return length == 0; }void reserve(size_t newCapacity) {10 unmodified lines16 unmodified lines17181920}~Vector() {delete[] data;2122232425262728293031}void push_back(const T& value) {if (length >= capacity) {size_t newCap = capacity == 0 ? 1 : capacity * 2;reserve(newCap);}data[length++] = value;}T& operator[](size_t index) {3233343536373839404142434445return data[index];}void clear() {length = 0;}T& front() { return data[0]; }T& back() { return data[length - 1]; }size_t size() const { return length; }bool empty() const { return length == 0; }void reserve(size_t newCapacity) {10 unmodified lines
In addition to rendering standard Git diffs and patches, you can pass any two files in @pierre/diffs and get a diff between them. This is especially useful when comparing across generative snapshots where linear history isn't always available. Edit the css below to see the diff.
1234.pizza { display: flex; justify-content: center;}Collectively, our team brings over 150 years of expertise designing, building, and scaling the world's largest distributed systems at Cloudflare, Coinbase, Discord, GitHub, Reddit, Stripe, X, and others.