### Install Shiki npm Package Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Instructions to install the Shiki npm package, which is a prerequisite for using the Tiptap PHP Shiki extension for advanced syntax highlighting. Shiki provides beautiful syntax highlighting powered by the same engine as many code editors. ```bash npm install shiki ``` -------------------------------- ### Initialize Tiptap Editor with Shiki for Code Block Highlighting Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Example demonstrating how to initialize the Tiptap Editor in PHP to utilize the CodeBlockShiki extension for syntax highlighting. It shows how to disable the default 'codeBlock' from StarterKit and include the CodeBlockShiki node. ```php (new \Tiptap\Editor([ 'extensions' => [ new \Tiptap\Extensions\StarterKit([ 'codeBlock' => false, ]), new \Tiptap\Nodes\CodeBlockShiki(), ], ])) ->setContent('
<?php phpinfo()
') ->getHTML(); ``` -------------------------------- ### Load Custom Extensions in Tiptap Editor Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Example showing how to explicitly load a custom array of extensions, such as `StarterKit` and `Link` mark, when initializing the Tiptap Editor. This allows for fine-grained control over the editor's functionality beyond the default `StarterKit`. ```php new \Tiptap\Editor([ 'extensions' => [ new \Tiptap\Extensions\StarterKit, new \Tiptap\Marks\Link, ], ]) ``` -------------------------------- ### Run Tiptap PHP Test Suite with File Watcher Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Starts the Tiptap PHP test suite in watch mode using Composer, requiring `nodemon` to be installed globally. This command automatically re-runs tests upon file changes, facilitating continuous development. ```bash composer test-watch ``` -------------------------------- ### Install Tiptap PHP Package via Composer Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md This snippet shows how to install the Tiptap PHP package using Composer, the PHP dependency manager. ```bash composer require ueberdosis/tiptap-php ``` -------------------------------- ### Sanitize Tiptap Content Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Example of using the `sanitize()` method to clean (or 'sanitize') content, removing potentially harmful elements. This method works with JSON strings, PHP arrays, and HTML, returning the content in the same format as the input. ```php (new \Tiptap\Editor) ->sanitize('

Example Text

'); // Returns: // '

Example Text

' ``` -------------------------------- ### Extend Tiptap PHP Bold Mark to Render Custom HTML Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Provides an example of extending an existing Tiptap PHP mark, `Bold`, to override its `renderHTML` method. This custom extension renders `` tags instead of the default `` tags. ```php instead of return ['b', 0]; } } new \Tiptap\Editor([ 'extensions' => [ new Paragraph, new Text, new CustomBold, ], ]) ``` -------------------------------- ### Configure Tiptap Editor on Initialization Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Demonstrates how to pass initial configuration options directly to the Tiptap Editor's constructor. This includes setting the initial 'content' of the editor and specifying an array of 'extensions' to load. ```php new \Tiptap\Editor([ 'content' => '

Example Text

', 'extensions' => [ new \Tiptap\Extensions\StarterKit, ], ]) ``` -------------------------------- ### Configure Tiptap PHP StarterKit Extension Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Illustrates how to configure the Tiptap PHP StarterKit, including disabling specific features like `codeBlock` and applying HTML attributes to nested extensions like `heading`. ```php new \Tiptap\Editor([ 'extensions' => [ new Tiptap\Extensions\StarterKit([ 'codeBlock' => false, 'heading' => [ 'HTMLAttributes' => [ 'class' => 'my-custom-class', ], ] ]), ], ]) ``` -------------------------------- ### Configure Tiptap Editor with CodeBlockHighlight Extension for Syntax Highlighting Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Demonstrates how to replace the default `CodeBlock` extension with `CodeBlockHighlight` to enable syntax highlighting for code blocks. This requires disabling the default `codeBlock` in `StarterKit` and adding the new extension. ```php (new \Tiptap\Editor([ 'extensions' => [ new \Tiptap\Extensions\StarterKit([ 'codeBlock' => false ]), new \Tiptap\Nodes\CodeBlockHighlight() ] ])) ->setContent('
<?php phpinfo()
') ->getHTML(); ``` -------------------------------- ### Run Tiptap PHP Test Suite Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Executes the test suite for the Tiptap PHP project using Composer. This command runs all defined tests to ensure code quality and functionality. ```bash composer test ``` -------------------------------- ### Configure Shiki Theme and Default Language in Tiptap Editor Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Illustrates how to pass additional configuration options to the CodeBlockShiki constructor, allowing customization of the syntax highlighting theme, default language, and whether to guess the language if not explicitly provided. ```php (new \Tiptap\Editor([ 'extensions' => [ new \Tiptap\Extensions\StarterKit([ 'codeBlock' => false, ]), new \Tiptap\Nodes\CodeBlockShiki([ 'theme' => 'github-dark', // default: nord, see https://github.com/shikijs/shiki/blob/main/docs/themes.md 'defaultLanguage' => 'php', // default: html, see https://github.com/shikijs/shiki/blob/main/docs/languages.md 'guessLanguage' => true, // default: true, if the language isn’t passed, it tries to guess the language with highlight.php ]), ], ])) ->setContent('
<?php phpinfo()
') ->getHTML(); ``` -------------------------------- ### Include Highlight.js CSS for Syntax Highlighting Styling Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md This HTML snippet shows how to include the necessary CSS file from Highlight.js CDN to apply styling and colors to syntax-highlighted code blocks generated by `CodeBlockHighlight`. ```html ``` -------------------------------- ### Build a Custom Tiptap PHP Node Extension Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Demonstrates how to create a completely custom Tiptap PHP Node extension. It includes defining static properties like `name` and `priority`, and implementing methods like `addOptions`, `parseHTML`, and `renderHTML` for custom parsing and rendering logic. ```php [], ]; } public function parseHTML() { return [ [ 'tag' => 'my-custom-tag[data-id]', ], [ 'tag' => 'my-custom-tag', 'getAttrs' => function ($DOMNode) { return ! \Tiptap\Utils\InlineStyle::hasAttribute($DOMNode, [ 'background-color' => '#000000', ]) ? null : false; }, ], [ 'style' => 'background-color', 'getAttrs' => function ($value) { return (bool) preg_match('/^(black)$/', $value) ? null : false; }, ], ]; } public function renderHTML($node) { return ['my-custom-tag', ['class' => 'foobar'], 0]; } } ``` -------------------------------- ### Configure Tiptap PHP Heading Extension Levels Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Demonstrates how to configure the Heading extension in Tiptap PHP to specify allowed heading levels (e.g., 1, 2, 3) by passing an array to its constructor within the Editor configuration. ```php new \Tiptap\Editor([ 'extensions' => [ // … new \Tiptap\Nodes\Heading([ 'levels' => [1, 2, 3], ]), ], ]) ``` -------------------------------- ### Convert Tiptap Content to Plain Text Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Demonstrates how to use the `getText()` method on a Tiptap Editor instance to convert HTML content into a plain text string. This functionality is particularly useful for scenarios like populating a search index. ```php (new \Tiptap\Editor) ->setContent('

Heading

Paragraph

') ->getText(); // Returns: // "Heading // // Paragraph" ``` -------------------------------- ### Configure Block Separator for Plain Text Conversion Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Shows how to customize the separator used between blocks when converting Tiptap content to plain text. The `getText()` method accepts an options array, allowing the 'blockSeparator' to be configured. ```php (new \Tiptap\Editor) ->setContent('

Heading

Paragraph

') ->getText([ 'blockSeparator' => "\n", ]); // Returns: // "Heading // Paragraph" ``` -------------------------------- ### Convert Tiptap HTML to PHP Array Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Demonstrates how to convert an HTML string into a Tiptap-compatible PHP array document structure using the `setContent` and `getDocument` methods of the `Tiptap\Editor` class. ```php (new \Tiptap\Editor) ->setContent('

Example Text

') ->getDocument(); ``` -------------------------------- ### Convert Tiptap JSON (PHP Array) to HTML Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Illustrates how to convert a Tiptap-compatible PHP array representing JSON content back into an HTML string using the `setContent` and `getHTML` methods of the `Tiptap\Editor` class. ```php (new \Tiptap\Editor) ->setContent([ 'type' => 'doc', 'content' => [ [ 'type' => 'paragraph', 'content' => [ [ 'type' => 'text', 'text' => 'Example Text', ] ] ] ] ]) ->getHTML(); ``` -------------------------------- ### Convert Tiptap HTML to JSON String Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Shows how to convert an HTML string into a Tiptap-compatible JSON string using the `setContent` and `getJSON` methods of the `Tiptap\Editor` class. ```php (new \Tiptap\Editor) ->setContent('

Example Text

') ->getJSON(); ``` -------------------------------- ### Modify Tiptap Nodes Recursively with Descendants Method Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Illustrates how to iterate through all nodes recursively using the `descendants()` method, similar to the JavaScript package. It highlights the crucial detail of passing the node by reference (`&`) to enable direct modification of the original node's attributes. ```php $editor->descendants(function (&$node) { if ($node->type !== 'heading') { return; } $node->attrs->level = 1; }); ``` -------------------------------- ### Add Custom HTML Attributes to Tiptap PHP Heading Extension Source: https://github.com/ueberdosis/tiptap-php/blob/main/README.md Shows how to pass custom HTML attributes, such as a CSS class, to a Tiptap PHP Heading extension. This allows for custom styling or behavior of the rendered HTML elements. ```php new \Tiptap\Editor([ 'extensions' => [ // … new \Tiptap\Nodes\Heading([ 'HTMLAttributes' => [ 'class' => 'my-custom-class', ], ]), ], ]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.