Open iwasherefirst2 opened 4 years ago
I figured out that the following code changes in js-beautify.coffee
keep the code valid:
text = beautifyHTML(text, options)
# post script (Workaround)
text = text.replace(/<[\n\s]*blade[\n\s]*(.*)[\s\n]*\/[\s\n]*>/ig, "@$1")
but it remains that the formatting is really bad. I don't know how to fix it, so I can't create a PR quite yet for it. Any hits how to fix the bad format?
The script above does half work to fix the problem, my js-beautify.coffee
is now as follows,
C:\Users\aidan\.atom\packages\atom-beautify\src\beautifiers\js-beautify.coffee
when "Blade"
beautifyHTML = require("js-beautify").html
# pre script (Workaround)
text = text.replace(/\@(?!yield)([^\n\s]*)/ig, "<blade $1 />")
text = beautifyHTML(text, options)
# post script (Workaround)
text = text.replace(/<[\n\s]*blade[\n\s]*(.*)[\s\n]*\/[\s\n]*>/ig, "@$1")
text = text.replace(/<blade ([^\n\s]*)\s*\/>/ig, "@$1")
text = text.replace(/\(\ \'/ig, "('")
@debug("Beautified HTML: #{text}")
resolve text
else
I was then able to get my previously not working code, (cut down)
<script>
var table = $('#responses-table').DataTable({
columns: [
{
data: 'name',
name: 'name',
},
@foreach ($form->response_categories as $title => $item)
{
data: '{{ $item }}',
data: '{{ $item }}',
},
@endforeach
],
});
</script>
To grammatically correctly format by doing the following,
<script>
var table = $('#responses-table').DataTable({
columns: [
{
data: 'name',
name: 'name',
},
@foreach ($form["response_categories"] as $title => $item)
{
data: '{{ $item }}',
data: '{{ $item }}',
},
@endforeach
],
});
</script>
Not ideal, better than the default though. Using your version without adapting my code produces the following, which is invalid.
<script>
var table = $('#responses-table').DataTable({
columns: [{
data: 'name',
name: 'name',
}, @foreach ($form - > response_categories as $title => $item) {
data: '{{ $item }}',
data: '{{ $item }}',
}, @endforeach ],
});
</script>
https://github.com/Glavin001/atom-beautify/pull/2422
Fixes this issue but has not been merged.
Description
As soon as blade syntax gets inside
script
tags, its becomes uglified and invalid.Input Before Beautification
This is what the code looked like before:
Expected Output
The beautified code should have looked like this:
Actual Output
The beautified code actually looked like this:
Steps to Reproduce
Atom Beautify: Beautify Language Blade
Debug
Here is a link to the
debug-3.md
Gist: https://gist.github.com/iwasherefirst2/727e88d9bdda3f54585146af62aa3af2Checklist
I have:
Atom Beautify: Help Debug Editor
command in Atom and added link fordebug.md
Gist to this issue