Code.Movie
Syntax highlighting, animated!
Level up your coding content with mighty morphing syntax highlighted source code
<?php
<?php namespace App\Http\Controllers;
<?php namespace App\Http\Controllers; use Illuminate\Support\Facades\DB; use Illuminate\View\View;
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class UserController extends Controller {}<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class UserController extends Controller {
public function index(): View {}
}<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class UserController extends Controller {
public function index(): View {
return view('user.index', []);
}
}<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class UserController extends Controller {
public function index(): View {
return view('user.index', [
'users' => DB::table('users');
]);
}
}<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class UserController extends Controller {
public function index(): View {
return view('user.index', [
'users' => DB::table('users')->paginate(15);
]);
}
}import collections def groupby_unsorted(seq, key=lambda x: x):
import collections
def groupby_unsorted(seq, key=lambda x: x):
indexes = collections.defaultdict(list)import collections
def groupby_unsorted(seq, key=lambda x: x):
indexes = collections.defaultdict(list)
for i, elem in enumerate(seq):import collections
def groupby_unsorted(seq, key=lambda x: x):
indexes = collections.defaultdict(list)
for i, elem in enumerate(seq):
indexes[key(elem)].append(i)import collections
def groupby_unsorted(seq, key=lambda x: x):
indexes = collections.defaultdict(list)
for i, elem in enumerate(seq):
indexes[key(elem)].append(i)
for k, idxs in indexes.items():import collections
def groupby_unsorted(seq, key=lambda x: x):
indexes = collections.defaultdict(list)
for i, elem in enumerate(seq):
indexes[key(elem)].append(i)
for k, idxs in indexes.items():
yield k, (seq[i] for i in idxs)import React from "react";
import React from "react";
type ButtonProps = {};import React from "react";
type ButtonProps = {
onClick: () => void;
};import React from "react";
type ButtonProps = {
onClick: () => void;
};
export const Button = (props: ButtonProps) => {
};import React from "react";
type ButtonProps = {
onClick: () => void;
};
export const Button = (props: ButtonProps) => {
return (
<button></button>
);
};import React from "react";
type ButtonProps = {
onClick: () => void;
};
export const Button = (props: ButtonProps) => {
return (
<button onClick={props.onClick}></button>
);
};import React from "react";
type ButtonProps = {
onClick: () => void;
};
export const Button = (props: ButtonProps) => {
return (
<button onClick={props.onClick}>
{props.children}
</button>
);
};import React, { type PropsWithChildren } from "react";
type ButtonProps = {
onClick: () => void;
};
export const Button = (props: ButtonProps) => {
return (
<button onClick={props.onClick}>
{props.children}
</button>
);
};import React, { type PropsWithChildren } from "react";
type ButtonProps = PropsWithChildren<{
onClick: () => void;
}>;
export const Button = (props: ButtonProps) => {
return (
<button onClick={props.onClick}>
{props.children}
</button>
);
};<!doctype html>
<!doctype html> <html></html>
<!doctype html> <html lang="en"></html>
<!doctype html> <html lang="en"> <head></head> </html>
<!doctype html>
<html lang="en">
<head>
<title>My document</title>
</head>
</html><!doctype html>
<html lang="en">
<head>
<title>My document</title>
</head>
<body></body>
</html><!doctype html>
<html lang="en">
<head>
<title>My document</title>
</head>
<body><!-- TODO: content --></body>
</html><!doctype html>
<html lang="en">
<head>
<title>My document</title>
<style>
/* Embedded CSS */
</style>
</head>
<body><!-- TODO: content --></body>
</html><!doctype html>
<html lang="en">
<head>
<title>My document</title>
<style>
:root { color: red }
</style>
</head>
<body><!-- TODO: content --></body>
</html><!doctype html>
<html lang="en">
<head>
<title>My document</title>
<style>
:root { color: red }
</style>
<script>
/* Embedded JS */
</script>
</head>
<body><!-- TODO: content --></body>
</html><!doctype html>
<html lang="en">
<head>
<title>My document</title>
<style>
:root { color: red }
</style>
<script>
window.alert("42");
</script>
</head>
<body><!-- TODO: content --></body>
</html>defmodule Concat do end
defmodule Concat do def join(a, b, sep) do end end
defmodule Concat do
def join(a, b, sep) do
a <> sep <> b
end
enddefmodule Concat do
def join(a, b, sep) do
a <> sep <> b
end
end
IO.puts(Concat.join("Hello", "world", "_"))defmodule Concat do
def join(a, b, sep) do
a <> sep <> b
end
end
IO.puts(Concat.join("Hello", "world", "_"))
#=> Hello_worlddefmodule Concat do
def join(a, b, sep \\ " ") do # default arguments
a <> sep <> b
end
end
IO.puts(Concat.join("Hello", "world", "_"))
#=> Hello_worlddefmodule Concat do
def join(a, b, sep \\ " ") do # default arguments
a <> sep <> b
end
end
IO.puts(Concat.join("Hello", "world", "_"))
#=> Hello_world
IO.puts(Concat.join("Hello", "world"))
#=> Hello world#[macro_use] extern crate rocket;
#[macro_use] extern crate rocket;
fn hello(name: &str) -> String {}#[macro_use] extern crate rocket;
#[get("/hello/<name>")]
fn hello(name: &str) -> String {}#[macro_use] extern crate rocket;
#[get("/hello/<name>")]
fn hello(name: &str) -> String {
format!("Hello {}", name)
}#[macro_use] extern crate rocket;
#[get("/hello/<name>")]
fn hello(name: &str) -> String {
format!("Hello {}", name)
}
fn rocket() -> _ {}#[macro_use] extern crate rocket;
#[get("/hello/<name>")]
fn hello(name: &str) -> String {
format!("Hello {}", name)
}
#[launch]
fn rocket() -> _ {}#[macro_use] extern crate rocket;
#[get("/hello/<name>")]
fn hello(name: &str) -> String {
format!("Hello {}", name)
}
#[launch]
fn rocket() -> _ {
rocket::build()
}#[macro_use] extern crate rocket;
#[get("/hello/<name>")]
fn hello(name: &str) -> String {
format!("Hello {}", name)
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount()
}#[macro_use] extern crate rocket;
#[get("/hello/<name>")]
fn hello(name: &str) -> String {
format!("Hello {}", name)
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/")
}#[macro_use] extern crate rocket;
#[get("/hello/<name>")]
fn hello(name: &str) -> String {
format!("Hello {}", name)
}
#[launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![hello])
}Supported languages and frameworks
Quick start tutorial
// Watch this space!
import json from "@codemovie/code-movie/languages/json";
import json from "@codemovie/code-movie/languages/json"; const language = json();
import json from "@codemovie/code-movie/languages/json"; const language = json(); let keyframes = [];
import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
];import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
{ code: `["World"]` },
];import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
{ code: `["World"]` },
{ code: `["Hello", "World"]` },
];import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
{ code: `["World"]` },
{ code: `["Hello", "World"]` },
{ code: `[\n "Hello",\n "World"\n]` },
];import { animateHTML } from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
{ code: `["World"]` },
{ code: `["Hello", "World"]` },
{ code: `[\n "Hello",\n "World"\n]` },
];import { animateHTML } from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
{ code: `["World"]` },
{ code: `["Hello", "World"]` },
{ code: `[\n "Hello",\n "World"\n]` },
];
animateHTML(keyframes, {
tabSize: 2,
language,
});import { animateHTML } from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
{ code: `["World"]` },
{ code: `["Hello", "World"]` },
{ code: `[\n "Hello",\n "World"\n]` },
];
let html = animateHTML(keyframes, {
tabSize: 2,
language,
});import { animateHTML } from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
{ code: `["World"]` },
{ code: `["Hello", "World"]` },
{ code: `[\n "Hello",\n "World"\n]` },
];
let html = animateHTML(keyframes, {
tabSize: 2,
language,
});
import "@codemovie/code-movie-runtime";import { animateHTML } from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
{ code: `["World"]` },
{ code: `["Hello", "World"]` },
{ code: `[\n "Hello",\n "World"\n]` },
];
let html = animateHTML(keyframes, {
tabSize: 2,
language,
});
import "@codemovie/code-movie-runtime";
document.body.innerHTML =
`<code-movie-runtime controls keyframes="0 1 2 3">
${html}
</code-movie-runtime>`;import {
animateHTML,
monokaiDark,
} from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";
const language = json();
let keyframes = [
{ code: `[]` },
{ code: `["World"]` },
{ code: `["Hello", "World"]` },
{ code: `[\n "Hello",\n "World"\n]` },
];
let html = animateHTML(keyframes, {
tabSize: 2,
language,
theme: monokaiDark
});
import "@codemovie/code-movie-runtime";
document.body.innerHTML =
`<code-movie-runtime controls keyframes="0 1 2 3">
${html}
</code-movie-runtime>`;This express tutorial walks you through the process of creating your first animation with Code.Movie. Let's assume that we have the package @codemovie/code-movie installed, have a build process for resolving module names going, and write code for a modern-ish browser. Ready? Continue by clicking the button labelled "next step".
We first need to import the language module for the code that we want to highlight and animate. For this tutorial that's JSON, so let's import the module for that.
Language modules export functions that need to be called once to instantiate. Some language modules can be configured at this stage to enable or disable certain features (like JSX support and type annotations for JS), but that's not the case for JSON. Let's call the language function and carry on.
Now we need some content to highlight and animate! For this we list code keyframes as strings in an array of objects.
Declare what that code should look like for each step of the animation and let the library deal with computing the required transitions.
This list does not need to be hand-written, but could just as well be auto-generated from sources like a file's git history or your favorite LLM.
The code does not even need to be strictly correct. Even though Code.Movie uses real parsers under the hood, they are fault-tolerant. You can totally highlight and animate examples of bad and broken code, if that's your thing.
For the purposes of this tutorial, hand-crafted JavaScript objects with valid JSON work just fine. And this should be enough!
Now we can import the main animation function.
The main animation function parses the code according to the language module, computes the animation, and finally turns it into plain HTML and CSS.
The resulting HTML string is huge and contains everything a browser needs to display the animation. It consists of HTML and CSS only - no runtime JavaScript required!
The animation is advanced by switching between the classes frame0, frame1, frameN etc. on the element with the class cm-animation contained in the HTML. This by itself is not very user-friendly. We can add the companion web component <code-movie-runtime> (via the package @codemovie/code-movie-runtime) to our code to get a minimal user interface with equally minimal effort.
Wrap the HTML returned by animateHTML() in <code-movie-runtime> tags, dump it into the page and we are technically done! If you check out the result at CodePen, you may notice the one remaining problem... the rather uninspiring design!
This is fortunately rather easy to fix: import a theme, pass it to animateHTML() and things suddenly look a lot more inspired! This concludes the quick start. You can check out the full documentation for more details on animations, decorations, theming, and much more.
Why?
Animations make changes easy to follow, improving slide decks, codings tutorials, tools or video content. Also animations look pretty, are easy to create, and work reliably with zero dependencies – so why not?
How?
Frames of code are run through a semantic diffing algorithm and the resulting deltas get turned into animation information … and finally into bog-standard HTML and CSS. No runtime JS required!
Get started!
Code.Movie is just JavaScript library that's fast enough to run in web frontends, but also works server-side. Grab it from NPM or a CDN, add it to your project, follow the tutorial, done!
Latest update: Entry and exit transformations and smaller bundles in 0.0.43
Code.Movie 0.0.43 adds support for entry and exit transformations without any breaking changes. The core module also became significantly smaller.
Performant
Fast enough to compute client-side animations on the fly. Throw a script into your page, done.
Flexible
Works in browsers as well as with Node.js and friends. Strings in, strings out!
Robust
Fault-tolerant parsers based on Lezer effortlessly deal with even the most broken code.
Reliable
Zero run-time dependencies - only HTML and CSS. Zero compile-time dependencies as well!
Customizable
Several themes, 140+ CSS variables and multiple styling hooks are available.
Deterministic
No AI involved at any stage. Only hand-crafted heuristics built by a real person.