Skip to content
Novus Examples

Source code for syntax highlighters

Idiomatic hello-world programs and realistic snippets across sixteen languages, exercising comments, string escapes, interpolation, numeric literals, and language keywords — for testing syntax highlighters, editor themes, and tree-sitter grammars.

121 of 121 files
Preview of Python — Hello World
py
168 B
Actual file preview for Python — Hello World

Python — Hello World

The classic hello-world in idiomatic Python 3, with a shebang, a module docstring, and the standard main guard — the minimal correct program for testing highlighters and interpreters.

File
PY · Python
Preview of TypeScript — Hello World
mts
144 B
Actual file preview for TypeScript — Hello World

TypeScript — Hello World

The classic hello-world in TypeScript (shipped as .mts to avoid the MPEG-TS .ts collision) — a typed function for testing TypeScript-aware highlighters and the tsc compiler.

File
MTS · TypeScript
Preview of TypeScript — Shapes (union, generics, enum)
mts
1.1 KB
Actual file preview for TypeScript — Shapes (union, generics, enum)

TypeScript — Shapes (union, generics, enum)

A realistic TypeScript snippet with an enum, a discriminated union, generics, exhaustive switch handling, and a typed reduce — for testing the type checker, highlighters, and the TS ESLint parser.

File
MTS · TypeScript
Preview of HTML — Hello World
html
220 B
Actual file preview for HTML — Hello World

HTML — Hello World

A minimal, valid HTML5 document — doctype, head, and a single heading — for testing HTML parsers, highlighters, and validators against the simplest well-formed page.

File
HTML · HTML
Preview of HTML — Semantic article page
html
1 KB
Actual file preview for HTML — Semantic article page

HTML — Semantic article page

A realistic semantic HTML page with landmark elements (header, nav, main, article, footer), a figure with alt text and caption, and lists — for testing HTML parsers, accessibility tooling, and highlighters.

File
HTML · HTML
Preview of CSS — Hello World
css
205 B
Actual file preview for CSS — Hello World

CSS — Hello World

A minimal stylesheet that centres a heading with grid — the simplest useful CSS file for testing highlighters, CSS parsers, and minifiers.

File
CSS · Css
Preview of Java — Hello World
java
163 B
Actual file preview for Java — Hello World

Java — Hello World

The classic hello-world in Java — a public class with the standard main method — for testing highlighters, javac, and Java parsers.

File
JAVA · Java
Preview of C — Hello World
c
123 B
Actual file preview for C — Hello World

C — Hello World

The classic hello-world in C — an include, main, and printf — for testing highlighters, C compilers, and parsers against the canonical first program.

File
C · C
Preview of C++ — Series (class template, STL)
cpp
924 B
Actual file preview for C++ — Series (class template, STL)

C++ — Series (class template, STL)

A realistic C++ snippet with a class template, STL algorithms (max_element, accumulate), std::move, and range handling — for testing highlighters, g++/clang++, and parsers against real templates.

File
CPP · C++
Preview of Go — Hello World
go
111 B
Actual file preview for Go — Hello World

Go — Hello World

The classic hello-world in Go — package main, an import, and fmt.Println, tab-indented like gofmt — for testing highlighters, the Go compiler, and parsers.

File
GO · Go
Preview of Rust — Shapes (enum, trait, pattern matching)
rs
942 B
Actual file preview for Rust — Shapes (enum, trait, pattern matching)

Rust — Shapes (enum, trait, pattern matching)

A realistic Rust snippet with an enum carrying data, a trait and impl, exhaustive match, iterators, and Option handling — for testing highlighters, rustc, clippy, and parsers against real ownership-era code.

File
RS · Rust
Preview of PHP — Invoice (enum, class, promoted properties)
php
1.1 KB
Actual file preview for PHP — Invoice (enum, class, promoted properties)

PHP — Invoice (enum, class, promoted properties)

A realistic modern-PHP snippet with strict types, a namespace, a backed enum, a final class with constructor-promoted readonly properties, and array_reduce with an arrow function — for testing highlighters, PHPStan, and parsers.

File
PHP · PHP
Preview of Shell — Hello World
sh
79 B
Actual file preview for Shell — Hello World

Shell — Hello World

The classic hello-world in Bash — a shebang and echo, with LF line endings so it runs on Unix — for testing highlighters, ShellCheck, and shell parsers.

File
SH · Shell
Preview of Shell — Backup script (strict mode, functions)
sh
706 B
Actual file preview for Shell — Backup script (strict mode, functions)

Shell — Backup script (strict mode, functions)

A realistic Bash script using strict mode (set -euo pipefail), functions, default parameters, a loop, and conditionals — an illustrative fixture (review before running) for testing highlighters, ShellCheck, and shfmt.

File
SH · Shell
Preview of SQL — Hello World
sql
72 B
Actual file preview for SQL — Hello World

SQL — Hello World

The classic first query in SQL — a single SELECT of a literal — for testing highlighters, SQL parsers, and query editors.

File
SQL · Sql
Preview of SQL — Library schema (DDL, view, join)
sql
994 B
Actual file preview for SQL — Library schema (DDL, view, join)

SQL — Library schema (DDL, view, join)

A realistic SQL script with CREATE TABLE constraints and foreign keys, INSERT seed data, a CREATE VIEW, and a grouped aggregate query with a join — for testing SQL parsers, formatters, and highlighters.

File
SQL · Sql
Preview of Swift — Task list (struct, protocol, optionals)
swift
1013 B
Actual file preview for Swift — Task list (struct, protocol, optionals)

Swift — Task list (struct, protocol, optionals)

A realistic Swift snippet with an enum, a protocol, a struct with a computed property, optionals and optional binding, and higher-order functions — for testing highlighters, the Swift compiler, SwiftLint, and parsers.

File
SWIFT · Swift
Preview of Service Worker (sw.js)
js
916 B
Actual file preview for Service Worker (sw.js)

Service Worker (sw.js)

A sample cache-first service worker handling install, activate, and fetch events with an offline fallback — for testing service-worker registration, JS parsers, and PWA tooling.

File
JS · Pwa · JavaScript
Preview of Minified JS bundle referencing an external source map
js
118 B
Actual file preview for Minified JS bundle referencing an external source map

Minified JS bundle referencing an external source map

A one-line minified bundle built from two ES modules, ending in the `//# sourceMappingURL=` comment that points at the v3 map shipped beside it. For testing that a debugger, error reporter or bundler analyser follows the annotation and resolves the map relative to the bundle.

File
JS · Build Output
Use case
Web assetsCode parsing+1· Paired fixture
Preview of Minified JS bundle with an inline base64 source map
js
579 B
Actual file preview for Minified JS bundle with an inline base64 source map

Minified JS bundle with an inline base64 source map

The same bundle with its v3 map embedded as a base64 data: URI in the sourceMappingURL comment - the single-file form dev builds emit. For testing that a tool decodes an inline map instead of trying to fetch it as a relative path.

File
JS · Build Output · base64
Use case
Web assetsCode parsing+1· Conversion set
Preview of Minified CSS with an external source map
css
86 B
Actual file preview for Minified CSS with an external source map

Minified CSS with an external source map

A minified stylesheet closing with the CSS form of the annotation, `/*# sourceMappingURL= */` - the comment syntax differs from JavaScript's and is a common reason a CSS map is silently ignored. For testing stylesheet source-map resolution.

File
CSS · Build Output
Use case
Web assetsCode parsing+1· Paired fixture
Preview of Terraform Required Providers and Backend
tf
665 B
Actual file preview for Terraform Required Providers and Backend

Terraform Required Providers and Backend

The terraform settings block: a version constraint range, two pinned providers, a local backend, default tags, and a second aliased provider configuration. The fictional examplecloud provider means nothing resolves to a real service.

File
TF · Terraform
Preview of Terraform Variables with Validation Blocks
tf
1.4 KB
Actual file preview for Terraform Variables with Validation Blocks

Terraform Variables with Validation Blocks

Seven Terraform variables covering string, number, map and a map(object) with an optional attribute and a default, plus two validation blocks with error messages. The sensitive variable's default is explicitly a SAMPLE note, not a credential.

File
TF · Terraform
Preview of Terraform Resources with count and for_each
tf
1.1 KB
Actual file preview for Terraform Resources with count and for_each

Terraform Resources with count and for_each

The resource graph: a network, a for_each subnet set, a counted instance resource, a data source, and a bucket on an aliased provider. Both repetition meta-arguments appear, plus lifecycle and an explicit depends_on edge.

File
TF · Terraform
Preview of Terraform Locals, for Expressions, and dynamic Blocks
tf
1.1 KB
Actual file preview for Terraform Locals, for Expressions, and dynamic Blocks

Terraform Locals, for Expressions, and dynamic Blocks

The expression-heavy half of the stack: for expressions producing both a map and a filtered list, conditional expressions selecting whole objects, and a dynamic block that generates two firewall rules from a local list.

File
TF · Terraform
Preview of Terraform Module Calls with Meta-Arguments
tf
629 B
Actual file preview for Terraform Module Calls with Meta-Arguments

Terraform Module Calls with Meta-Arguments

Three module calls covering the shapes a dependency grapher has to handle: a local path with explicit provider passing, a versioned registry source under for_each, and a count-gated conditional module.

File
TF · Terraform
Preview of Terraform Outputs and Splat Expressions
tf
734 B
Actual file preview for Terraform Outputs and Splat Expressions

Terraform Outputs and Splat Expressions

Five Terraform outputs exercising a splat expression over a counted resource, a for expression over a for_each module, and a sensitive output that must stay redacted when propagated from a sensitive input.

File
TF · Terraform
Preview of Terraform Default terraform.tfvars
tfvars
405 B
Actual file preview for Terraform Default terraform.tfvars

Terraform Default terraform.tfvars

A terraform.tfvars assigning the staging defaults, including a nested map-of-objects value. Pairs with the production overrides file, which replaces that map wholesale rather than merging into it.

File
TFVARS · Terraform
Preview of Terraform Production tfvars Overrides
tfvars
506 B
Actual file preview for Terraform Production tfvars Overrides

Terraform Production tfvars Overrides

The production tfvars overrides. Its point is a semantic that surprises people: a complex-typed variable is replaced whole, not deep-merged, so the staging app-b subnet does not survive the override.

File
TFVARS · Terraform
Preview of HCL2 Image Build Definition
hcl
1.2 KB
Actual file preview for HCL2 Image Build Definition

HCL2 Image Build Definition

A generic HCL2 image-build definition exercising the grammar rather than any vendor schema: labelled blocks, a list variable, locals, an indent-stripping heredoc with an interpolation inside it, and a for expression producing a list.

File
HCL · Hcl
Preview of HCL2 Orchestrator Job Definition
hcl
1.2 KB
Actual file preview for HCL2 Orchestrator Job Definition

HCL2 Orchestrator Job Definition

A deeply nested HCL2 job definition — job, group, task, service, check — with duration strings, a port mapping, and restart and update policies. Four levels of block nesting, which is where hand-rolled HCL readers usually break.

File
HCL · Hcl
Preview of HCL2 Policy Document
hcl
1.2 KB
Actual file preview for HCL2 Policy Document

HCL2 Policy Document

A generic HCL2 policy document with three severity-graded rules, condition blocks using all_of / none_of / one_of, and a dated exemption. Grants nothing to anything; it exists so policy tooling has a realistic document to read.

File
HCL · Hcl
Preview of Dockerfile, Multi-Stage Build Definition
dockerfile
1.2 KB
Actual file preview for Dockerfile, Multi-Stage Build Definition

Dockerfile, Multi-Stage Build Definition

A three-stage Dockerfile with a syntax directive, build args interpolated into FROM lines, a heredoc COPY, multi-line LABEL and ENV continuations, a non-root USER, and HEALTHCHECK in exec form. Inert: every base image is a fictional example.invalid reference.

File
DOCKERFILE · Docker
Preview of Makefile Targets and TAB Indentation
mk
932 B
Actual file preview for Makefile Targets and TAB Indentation

Makefile Targets and TAB Indentation

A Makefile whose recipe lines are indented with real TAB characters, as make requires. Covers simple, conditional, appended and substitution-reference variables, .PHONY, and .DEFAULT_GOAL. Every recipe is echo-only, so running it does nothing.

File
MK · Build
Preview of Makefile Pattern Rules and Conditionals
mk
608 B
Actual file preview for Makefile Pattern Rules and Conditionals

Makefile Pattern Rules and Conditionals

Pattern rules with the automatic variables $@, $<, $^ and $*, ifeq/ifdef conditional directives, a vpath search path, and a define block invoked through $(call). All recipe lines are TAB-indented and echo-only.

File
MK · Build
Preview of Gradle Build Script (Groovy DSL)
gradle
1.2 KB
Actual file preview for Gradle Build Script (Groovy DSL)

Gradle Build Script (Groovy DSL)

A Gradle Groovy DSL build script with a plugins block, a Java toolchain, five dependency configurations, task configuration via named() and a registered task. Every coordinate and repository is fictional, so nothing resolves.

File
GRADLE · Build
Preview of Gradle Settings Script with Version Catalog
gradle
980 B
Actual file preview for Gradle Settings Script with Version Catalog

Gradle Settings Script with Version Catalog

A Gradle settings script — the file that actually defines a multi-project build — with pluginManagement, a repositories mode, a version catalog declaring libraries, a bundle and a plugin, and one project remapped to a custom directory.

File
GRADLE · Build
Preview of gradle.properties with Escapes and Continuations
properties
943 B
Actual file preview for gradle.properties with Escapes and Continuations

gradle.properties with Escapes and Continuations

A gradle.properties exercising the .properties grammar rather than Gradle: a \uXXXX escape, a backslash line continuation, all three key/value separator forms, and a key containing escaped separator characters.

File
PROPERTIES · Build
Preview of Java Properties Parser Edge Cases
properties
684 B
Actual file preview for Java Properties Parser Edge Cases

Java Properties Parser Edge Cases

The .properties edge cases collected in one file: both comment markers, empty values, a value whose trailing spaces are significant, unescaped = and : inside values, a # that is not a comment, escape sequences, an escaped space in a key, and a duplicate key.

File
PROPERTIES · Build
Preview of TOML Build Configuration with Array of Tables
toml
1.1 KB
Actual file preview for TOML Build Configuration with Array of Tables

TOML Build Configuration with Array of Tables

A build-tool configuration in TOML, chosen for the constructs YAML has no direct equivalent for: three [[build.step]] array-of-tables entries carrying an ordered pipeline, a quoted glob key, and all three TOML date-time flavours.

File
TOML · Build