{"id":16955622,"url":"https://github.com/marceauka/wysiwyg-preprocessor","last_synced_at":"2025-04-11T21:34:06.837Z","repository":{"id":56943296,"uuid":"62954083","full_name":"MarceauKa/WYSIWYG-Preprocessor","owner":"MarceauKa","description":"A PHP library for processing wysiwyg/textarea output.","archived":false,"fork":false,"pushed_at":"2017-03-07T18:03:32.000Z","size":37,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T17:47:07.171Z","etag":null,"topics":["bbcode","links","php","php-library","wysiwyg","wysiwyg-preprocessor"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarceauKa.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-09T14:49:28.000Z","updated_at":"2024-06-25T08:03:41.000Z","dependencies_parsed_at":"2022-08-21T02:10:26.300Z","dependency_job_id":null,"html_url":"https://github.com/MarceauKa/WYSIWYG-Preprocessor","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarceauKa%2FWYSIWYG-Preprocessor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarceauKa%2FWYSIWYG-Preprocessor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarceauKa%2FWYSIWYG-Preprocessor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarceauKa%2FWYSIWYG-Preprocessor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarceauKa","download_url":"https://codeload.github.com/MarceauKa/WYSIWYG-Preprocessor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248483558,"owners_count":21111480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bbcode","links","php","php-library","wysiwyg","wysiwyg-preprocessor"],"created_at":"2024-10-13T22:12:48.458Z","updated_at":"2025-04-11T21:34:06.760Z","avatar_url":"https://github.com/MarceauKa.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WYSIWYG Preprocessor\r\n\r\n[![Build Status](https://travis-ci.org/MarceauKa/WYSIWYG-Preprocessor.svg?branch=master)](https://travis-ci.org/MarceauKa/WYSIWYG-Preprocessor)\r\n\r\nWYSIWYG Preprocessor is **a PHP library with no dependencies**. It's a sort of **toolbox for processing your HTML textareas**.  \r\n\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Customizing modifiers](#customizing-modifiers)\r\n- [Modifiers](#modifiers)\r\n    - [BBCode](#bbcode)\r\n    - [Parse Variables](#parse-variables)\r\n    - [Absolute Path](#absolute-path)\r\n    - [Words Filter](#words-filter)\r\n    - [Empty Paragraphs](#empty-paragraphs)\r\n    - [Mail to Link](#mail-to-link)\r\n    - [NlToBr](#nltobr)\r\n    - [StripTags](#striptags)\r\n    - [URL to Link](#url-to-link)\r\n    - [Youtube Link to Iframe](#youtube-link-to-iframe)\r\n- [Your own modifiers](#your-own-modifiers)\r\n- [Unit Tests](#unit-tests)\r\n- [Authors](#authors)\r\n\r\n## Installation\r\n\r\nSources are managed with Composer.\r\n\r\n```bash\r\ncomposer require akibatech/wysiwygpreprocessor \"0.*\"\r\n```\r\n\r\n## Basic usage\r\n\r\nFor the given textarea, \r\n\r\n```php\r\n$textarea = \"Check my website http://website.com. Keep in touch at hello@website.com !\";\r\n```\r\n\r\nWe want to transform the link and the email adress to HTML tags\r\n\r\n```php  \r\nuse Akibatech\\Wysiwyg\\Processor;  \r\nuse Akibatech\\Wysiwyg\\Modifier;  \r\n\r\n$processor = new Processor();  \r\n\r\n$processor-\u003eaddModifier(new Modifier\\UrlToLink)  \r\n          -\u003eaddModifier(new Modifier\\MailToLink)  \r\n          -\u003eprocess($textarea);  \r\n\r\necho $processor-\u003egetOutput();  \r\n```\r\n\r\nResults in :  \r\n\r\n```html\r\nCheck my website \u003ca href=\"http://website.com\"\u003ehttp://website.com\u003c/a\u003e. Keep in touch at \u003ca href=\"mailto:hello@website.com\"\u003ehello@website.com\u003c/a\u003e !\r\n```\r\n\r\n## Customizing modifiers\r\n\r\nModifiers are easily customizable.  \r\nImagine you want to target all links to a new page or adding to it a custom class.  \r\n\r\n```php  \r\n$textarea = 'Check out my new site: personnal-website.com';\r\n\r\n$modifier = new Akibatech\\Wysiwyg\\Modifier\\UrlToLink();\r\n\r\n$modifier-\u003esetOptions([\r\n    'class' =\u003e 'custom-link',\r\n    'target' =\u003e '_blank'\r\n])\r\n\r\n$processor = new Akibatech\\Wysiwyg\\Processor();\r\n\r\n$processor-\u003eaddModifier($modifier)\r\n          -\u003eprocess($textarea);\r\n\r\necho $processor-\u003egetOutput();\r\n```\r\n\r\nResults in :  \r\n\r\n```html\r\nCheck out my new site: \u003ca href=\"personnal-website.com\" class=\"custom-link\" target=\"_blank\"\u003epersonnal-website.com\u003c/a\u003e\r\n```\r\n\r\n## Modifiers\r\n\r\n### BBCode\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\BbCode**  \r\nDescription: Apply a basic BBCode to enhance your content.  \r\n\r\nExample input: ```[b]Hello[/b]```  \r\nExample output: ```\u003cstrong\u003eHello\u003c/strong\u003e```  \r\n\r\nOptions:  \r\nDefaults tags are: b, i, u, left, right, center, quote, link, img, size and color.  \r\nOptions are wilcard BBCode tag. Key is the wanted BBCode tag and option is the HTML replacement.  \r\nIf pattern is given as array, it can access Tag option like ```[link=http://github.com]my profile[/link]``` as ```\u003ca href=\"$1\"\u003e$2\u003c/a\u003e```.   \r\n```php  \r\n[  \r\n    // New tag called [yellow]text in yellow[/yellow]  \r\n    'yellow' =\u003e '\u003cspan style=\"color: yellow;\"\u003e$1\u003c/span\u003e',  \r\n    // Disable default \"b\" tag  \r\n    'b' =\u003e null  \r\n]  \r\n```\r\n\r\n### Parse Variables\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\ParseVariables**  \r\nDescription: Replace a preset of variables.  \r\n\r\nExample input: ```Hello %name%!```  \r\nExample output: ```Hello John!```  \r\n\r\nOptions:  \r\nYou can specify the delimiter and the accepted variables.\r\n```php  \r\n[  \r\n    // My custom delimiter. Vars are parsed in this delimiter. Default is \"%\".  \r\n    'in' =\u003e '%',  \r\n    // Accepted vars\r\n    'accept' =\u003e [\r\n        'name' =\u003e 'Joe', // %name% =\u003e Joe\r\n        'email' =\u003e 'email@example.com' // %email% =\u003e email@example.com\r\n    ]\r\n]  \r\n```\r\n\r\n### Absolute Path\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\AbsolutePath**  \r\nDescription: Will replace \"href\" and \"src\" attributes with absolute values.  \r\n\r\nExample input: ```\u003cimg src=\"../../files/sea.jpg\" /\u003e```  \r\nExample output: ```\u003cimg src=\"/files/sea.jpg\" /\u003e```  \r\n\r\nOptions:  \r\nYou can specify a custom prefix for your paths.\r\n```php  \r\n[  \r\n    // Custom prefix. Default is '/'.  \r\n    'prefix' =\u003e 'http://site.com/', // \u003cimg src=\"http://site.com/files/sea.jpg\" /\u003e\r\n]  \r\n```\r\n\r\n### Words Filter\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\WordsFilter**  \r\nDescription: Remove a words list from a text. Act as a censorship system.  \r\n\r\nExample input: ```Cunt!```  \r\nExample output: ```[censored]!```  \r\n\r\nOptions:  \r\nThe list and the replacement.\r\n```php  \r\n[  \r\n    // Words list as an array.  \r\n    'words' =\u003e ['word1', 'word2'], // No defaults words.\r\n    // Replacement\r\n    'replace' =\u003e '[censored]' // Wanted replacement, default to [censored]\r\n]  \r\n```\r\n\r\n### Empty Paragraphs\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\EmptyParagraphs**  \r\nDescription: Delete empty paragraphs from your content.  \r\n\r\nExample input:  ```\u003cp\u003e\u003c/p\u003e\u003cp\u003eHello\u003c/p\u003e\u003cp\u003e\u0026nbsp;\u003c/p\u003e```  \r\nExample output: ```\u003cp\u003eHello\u003c/p\u003e```  \r\n\r\nOptions:  \r\nNone.  \r\n\r\n### Mail to Link\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\MailToLink**  \r\nDescription: Transforms emails adresses in clickable link tag.  \r\n\r\nExample input: ```email@company.com```  \r\nExample output: ```\u003ca href=\"mailto:email@company.com\"\u003eemail@company.com\u003c/a\u003e```  \r\n\r\nOptions:    \r\n```php  \r\n[  \r\n    // Will replace \"@\" by \"\u003cat\u003e\", set to false to disable...  \r\n    'at' =\u003e '\u003cat\u003e',  \r\n]  \r\n```\r\n\r\n### NlToBr\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\NlToBr**  \r\nDescription: Replace line breaks into HTML line breaks. Similar to php native function nl2br().  \r\n\r\nExample input: ```hello  \r\nworld```  \r\nExample output: ```hello\u003cbr\u003eworld```  \r\n\r\nOptions:    \r\n```php  \r\n[  \r\n    // Linebreak symbol to search. Defaults to \"\\n\"  \r\n    'search' =\u003e \"\\n\",  \r\n    // HTML to replace. Defaults to \"\u003cbr\u003e\"  \r\n    'replace' =\u003e '\u003cbr /\u003e'  \r\n]  \r\n```\r\n\r\n### StripTags\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\StripTags**  \r\nDescription: Remove HTML tags from input. Similar to php native function strip_tags().  \r\n\r\nExample input: ```\u003cp\u003ehello world\u003c/p\u003e```  \r\nExample output: ```hello world```  \r\n\r\nOptions:    \r\n```php  \r\n[  \r\n    // Allowed HTML tags (see strip_tags documentation). Defaults, none.  \r\n    'allow' =\u003e \"\u003ca\u003e\",  \r\n]  \r\n```\r\n\r\n### URL to Link\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\UrlToLink**  \r\nDescription: Transforms web adresses in clickable link tag.  \r\n\r\nExample input: ```https://www.github.com```  \r\nExample output: ```\u003ca href=\"https://www.github.com\"\u003ehttps://www.github.com\u003c/a\u003e```  \r\n\r\nOptions:    \r\n```php  \r\n[  \r\n    // Add a custom class to all generated tags. No defaults.    \r\n    'class' =\u003e 'link',  \r\n    // Customize the link target. No defaults.  \r\n    'target' =\u003e '_blank'  \r\n]  \r\n```\r\n\r\n### Youtube Link to Iframe\r\n\r\nClass: **Akibatech\\Wysiwyg\\Modifier\\YoutubeLinkToIframe**  \r\nDescription: Transforms youtube links (long and shorts) to a embed video player (iframe).  \r\n\r\nExample input: ```My new video: https://youtu.be/wBqM2ytqHY4```  \r\nExample output: ```My new video: \u003ciframe src=\"https://www.youtube.com/embed/wBqM2ytqHY4?controls=1\u0026rel=0\u0026showinfo=1\" class=\"youtube-iframe\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen\u003e\u003c/iframe\u003e```  \r\n\r\nOptions:    \r\n```php  \r\n[\r\n    // Custom class added to the player\r\n    'class'  =\u003e 'youtube-iframe',\r\n    // Custom width (in px) or null\r\n    'width'  =\u003e 560,\r\n    // Custom height (in px) or null\r\n    'height' =\u003e 315,\r\n    // Allow fullscreen\r\n    'allow_fullscreen' =\u003e true,\r\n    // Enable youtube suggestions when video ends\r\n    'with_suggestions' =\u003e false,\r\n    // Display video info\r\n    'with_infos' =\u003e true,\r\n    // Display video controls\r\n    'with_controls' =\u003e true\r\n]\r\n```\r\n\r\n## Your own modifiers\r\n\r\nYou can easily extends the preprocessor by adding your own modifiers.  \r\nAll you need is to create a class implementing **ModifierInterface**. \r\nYou're also encouraged to extends **AbstractModifier** to access common methods (setOptions, getOptions, ...).  \r\n\r\nBasically, a modifier receive the input to transform through a public method **handle($input)**.  \r\nOptions are handled by a public method **defaultOptions()** returning an array of available options. And in your modifier body, you can access these options with the instance attribute **options**.\r\n\r\n### Callable modifier\r\n\r\nYou also have the possibility to add a dynamic modifier.  \r\nThe method \"addModifier\" also accepts a callback function.  \r\n\r\nExample :  \r\n```php\r\n$processor-\u003eaddModifier(function($input) {\r\n    return str_rot13('hello'); // Will return \"uryyb\"\r\n});\r\n```\r\n\r\n## Unit Tests\r\n\r\nWYSIWYG Preprocessor is tested with PHPUnit.  \r\nMake sure you have composer dev dependencies installed and type :\r\n\r\n```bash\r\nvendor/bin/phpunit\r\n```\r\n\r\n## Authors\r\n\r\nAuthor: [Marceau Casals](https://marceau.casals.fr) and [all contributors](https://github.com/MarceauKa/WYSIWYG-Preprocessor/graphs/contributors)  \r\nLicence: [MIT](https://en.wikipedia.org/wiki/MIT_License)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarceauka%2Fwysiwyg-preprocessor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarceauka%2Fwysiwyg-preprocessor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarceauka%2Fwysiwyg-preprocessor/lists"}