A Laravel package for converting HTML codes to Javascript
STEPS:-
- Create a
packages/souravmsh/
directory at the root of the Laravel application.
mkdir packages
cd packages
mkdir souravmsh
- Clone the Repository from github.
git clone https://github.com/souravmsh/html-to-js.git
- Add package repositories to the application-root
composer.json
file
"repositories": [
{
"type": "path",
"url": "./packages/souravmsh/html-to-js"
}
]
"require": {
"souravmsh/html-to-js": "dev-main"
},
- install package via comopser
composer require souravmsh/html-to-js:dev-main
or delete the composer.lock
file and run
composer install
- To use
PHP
$js = HtmlToJs::convert("<html><head><title>teste</title></head><body style='background:red;'>ola <span id='testando'>teste</span> do mundo</body></html>");
HTML
<textarea>
{{ $script->code }}
document.body.appendChild({{ $script->id }});
</textarea>
JS
<script type="text/javascript">
// paste text from textarea
</script>