Quantcast
Channel: Recent Gists from assertchris
Viewing all articles
Browse latest Browse all 30

example.php

$
0
0
example.php
<?php
$converter->when(
fn(Heading $node) => // => reflection-based overloading
HtmlElement::fromString( // => complex types from string template syntax
'<h1 class="font-2xl">:text</h1>',
['text' => $node->text]
)
);
$converter->convert('# hello world'); // => <h1 class="font-2xl">hello world</h1>
// benefits:
// - very easy to set up
// - don't need to know how to manually create custom renderers or about the internal structure
// - can further manipulate complex types once the basics are bootstrapped using this approach
$converter->when(
fn(Heading $node) => HtmlElement::fromString(
match ($node->level) {
default => '<h1 class="font-2xl">:text</h1>',
2 => '<span><a href="#:id">link</a><h2 class="font-xl">:text</h2></span>',
3 => '<h3 id=":id" class="font-lg">:text</h3>',
},
[
'text' => $node->text,
'id' => slug($node->text),
]
)
);

Viewing all articles
Browse latest Browse all 30

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>