Code.Movie

Blog / PHP support in 0.0.32

Code.Movie 0.0.32 adds support for PHP! Code.Movie is a JavaScript library that animates source code for the web - imagine a combination of git diffs, virtual DOM diffing, syntax highlighting, code annotations and CSS animations.

1234567891011
<?php$animals=['dog','cat','cow','duck','goose'];$animal=array_find($animals,staticfn(str_starts_with($value,'c'),);string:bool$value)=>var_dump($animal);//string(3)"cat"
➡️
<?php

$animals = [];
<?php

$animals = ['dog', 'cat', 'cow', 'duck', 'goose'];
<?php

$animals = ['dog', 'cat', 'cow', 'duck', 'goose'];

$animal = array_find();
<?php

$animals = ['dog', 'cat', 'cow', 'duck', 'goose'];

$animal = array_find(
    $animals,
);
<?php

$animals = ['dog', 'cat', 'cow', 'duck', 'goose'];

$animal = array_find(
    $animals,
    static fn ($value) =>
        str_starts_with($value, 'c'),
);
<?php

$animals = ['dog', 'cat', 'cow', 'duck', 'goose'];

$animal = array_find(
    $animals,
    static fn (string $value): bool =>
        str_starts_with($value, 'c'),
);
<?php

$animals = ['dog', 'cat', 'cow', 'duck', 'goose'];

$animal = array_find(
    $animals,
    static fn (string $value): bool =>
        str_starts_with($value, 'c'),
);

var_dump($animal);
<?php

$animals = ['dog', 'cat', 'cow', 'duck', 'goose'];

$animal = array_find(
    $animals,
    static fn (string $value): bool =>
        str_starts_with($value, 'c'),
);

var_dump($animal); // string(3) "cat"

New language: PHP

As the above animation shows, PHP is now supported by Code.Movie. Core library, playground and documentation have been updated accordingly. Import the language module from the core library and go from there as usual:

import { animateHTML } from "@codemovie/code-movie";
import php from "@codemovie/code-movie/languages/php";

let html = animateHTML([{ code: '<?php echo "Hello World!"; ?>' }], {
  tabSize: 4,
  language: php(),
});
1234567
import { animateHTML } from "@codemovie/code-movie";
import php from "@codemovie/code-movie/languages/php";

let html = animateHTML([{ code: '<?php echo "Hello World!"; ?>' }], {
  tabSize: 4,
  language: php(),
});

The usual caveats apply: I don't speak or use PHP myself, so syntax and animation heuristics may at this point not be as good as with other languages. Bug reports are welcome!

Other changes

  • New exceptions for decoration coordinates that exceed the document (eg. a line decoration with { fromLine: 1, toLine: 5} in a document with only 3 lines) instead of the previous undefined and apparently random behavior
  • Improve animation heuristics for ECMAScript
  • Fully support @scope in CSS