PHP code example of marque / squidink

1. Go to this page and download the library: Download marque/squidink library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

marque / squidink example snippets


use Marque\SquidInk\SquidInk;

$squidInk = app(SquidInk::class);

// Parse and render in one call
$html = $squidInk->convert($source, 'bbcode', 'html');

// Or keep the document, render it more than once
$document = $squidInk->parse($source, 'markdown');
$html     = $squidInk->render($document, 'html');
$plain    = $squidInk->render($document, 'text');

Schema::create('posts', function (Blueprint $table) {
    $table->text('body');
    $table->string('body_format')->default('markdown');
});

use Marque\SquidInk\Document\Nodes\{Document, Paragraph, Text};
use Marque\SquidInk\Document\Marks\Bold;

$document = new Document;
$document->append((new Paragraph)->append(new Text('hello', [new Bold])));

use Marque\SquidInk\Document\Schema;

// Everything the package supports
$schema = Schema::permissive();

// Text, emphasis and links only — sensible for short comment fields
$schema = Schema::minimal();

// Or name exactly what you want
$schema = new Schema(
    nodes: ['document', 'paragraph', 'text', 'block_quote'],
    marks: ['bold', 'italic', 'link'],
);

use Marque\SquidInk\Contracts\Parser;
use Marque\SquidInk\Document\Nodes\Document;
use Marque\SquidInk\Document\Schema;

final class TextileParser implements Parser
{
    public function name(): string
    {
        return 'textile';   // Stored in your body_format column — keep it stable
    }

    public function parse(string $source, Schema $schema): Document
    {
        $document = new Document;

        // ... build nodes ...

        // Build permissively, then filter once — rather than checking the
        // schema at every step.
        $schema->filter($document);

        return $document;
    }
}

app(SquidInk::class)->registerParser(new TextileParser);

use Marque\SquidInk\Contracts\DescribesSyntax;
use Marque\SquidInk\Editor\Insertion;

final class TextileParser implements Parser, DescribesSyntax
{
    public function actions(): array
    {
        return ['bold', 'italic', 'link'];
    }

    public function insertion(string $action): ?Insertion
    {
        return match ($action) {
            'bold' => new Insertion('bold', 'B', '*', '*', 'text'),
            'italic' => new Insertion('italic', 'I', '_', '_', 'text'),
            'link' => new Insertion('link', 'Link', '"', '":https://', 'link text'),
            default => null,   // Declining is normal — the button is simply omitted
        };
    }
}

use Marque\SquidInk\Contracts\Renderer;
use Marque\SquidInk\Document\Node;

final class MarkdownRenderer implements Renderer
{
    public function name(): string
    {
        return 'markdown';
    }

    public function render(Node $node): string
    {
        // Switch on $node->type(); recurse through $node->children()
    }
}

use Marque\SquidInk\Contracts\Shortcode;
use Marque\SquidInk\Document\Nodes\Shortcode as ShortcodeNode;

final class TorrentShortcode implements Shortcode
{
    public function name(): string
    {
        return 'torrent';
    }

    public function isPaired(): bool
    {
        return false;
    }

    public function render(ShortcodeNode $node, string $format, callable $renderChildren): ?string
    {
        if ($format !== 'html') {
            return null;   // Decline; the renderer falls back to plain children
        }

        return view('torrent-pill', ['id' => $node->attribute('id')])->render();
    }
}
bash
php artisan vendor:publish --tag=squidink-config
bash
php artisan vendor:publish --tag=squidink-assets
blade
<livewire:squidink-editor name="body" parser="markdown" />
bash
php artisan vendor:publish --tag=squidink-views