explaingit

googlearchive/code-prettify

5,769JavaScriptAudience · developerComplexity · 1/5Setup · easy

TLDR

An archived JavaScript library from Google that adds color-coded syntax highlighting to code blocks on any web page, include one script tag, add a CSS class to your code element, and the language is detected automatically.

Mindmap

mindmap
  root((code-prettify))
    What it does
      Syntax highlighting
      Auto language detect
      CSS theming
    Languages Supported
      Python Java C
      JavaScript HTML
      Go Rust Ruby
    Use Cases
      Static HTML pages
      Blog code snippets
      Legacy CMS sites
    Setup
      One script tag
      One CSS class
    Status
      Archived by Google
      No longer maintained
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add syntax highlighting to a static HTML documentation site without a build step or npm dependency.

USE CASE 2

Display code samples with automatic language detection on a blog or CMS that allows injecting a script tag.

USE CASE 3

Study the archived codebase as a reference for how tokenizer-based syntax highlighting was implemented in plain JavaScript.

Tech stack

JavaScriptCSS

Getting it running

Difficulty · easy Time to first run · 5min

This project is archived and no longer maintained, consider highlight.js or Prism.js for new projects.

In plain English

Code Prettify is an archived JavaScript library originally created by Google that adds syntax highlighting to code snippets displayed on web pages. Syntax highlighting means coloring different parts of code (keywords, strings, comments, etc.) so they are easier to read visually. This library is no longer maintained, and the repository is marked as inactive. To use it, you include a single script tag in your HTML page and then mark any block of code with the class "prettyprint". The library automatically detects what programming language the code is written in and applies appropriate colors, so you do not have to specify the language yourself. You can optionally specify a language extension if you want to override that detection. Line numbers can be added with a separate class, and the visual styles can be changed through CSS. The library works with a wide range of languages out of the box, including C, C++, Java, Python, Bash, JavaScript, HTML, XML, CSS, SQL, and Rust. Additional language extensions are included in the repository for languages like Go, Haskell, Scala, Swift, Lua, Ruby, and YAML, among others. It handles code that contains embedded HTML links or other markup without breaking the display. The library was used in production on both Google Code and Stack Overflow, according to the README. It was tested with older browser versions including Internet Explorer 6 and early versions of Firefox and Safari. The README includes answers to several practical questions: how to prevent specific sections from being highlighted, how to control line numbering, how to handle code coming from Markdown renderers that do not allow adding CSS classes, and why it may behave unexpectedly on WordPress sites. Because this project is archived and no longer maintained, developers looking for an actively supported syntax highlighting library would need to look elsewhere.

Copy-paste prompts

Prompt 1
Show me the minimal HTML to include code-prettify on a static page and display a Python code block with syntax highlighting and line numbers.
Prompt 2
I am migrating from code-prettify to highlight.js. Show me what code-prettify markup looks like and what the equivalent highlight.js markup would be.
Prompt 3
How does code-prettify detect the programming language of a code block automatically, and how do I override that detection for a language it misidentifies?
Prompt 4
Show me how to apply a custom color theme to code-prettify by overriding its CSS classes.
Open on GitHub → Explain another repo

← googlearchive on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.