Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: parsing Laravel blade #86

Open
lotsofbytes opened this issue Jul 25, 2022 · 1 comment
Open

Question: parsing Laravel blade #86

lotsofbytes opened this issue Jul 25, 2022 · 1 comment

Comments

@lotsofbytes
Copy link

A laravel blade file is not really a html file. It includes program directives for conditions and loops.
But, because it starts with @ (like @foreach), the laravel directrives get escaped by domReplaceHelpers.

For example,

                 @foreach ($company->members as $m)
                    @if ($m->checkbox)
                      {{ $m->checkbox }}
                    @else
                      <span class="" title="{{ $m->profile }}">{{ $m->name }}</span>
                    @endif
                  @endforeach

will be parsed to:

                ____SIMPLE_HTML_DOM__VOKU__AT____foreach ($company-&gt;members as $m)\n
                         ____SIMPLE_HTML_DOM__VOKU__AT____if ($m-&gt;checkbox)\n
                           {{ $m-&gt;checkbox }}\n
                         ____SIMPLE_HTML_DOM__VOKU__AT____else\n
                           <span class="" title="{{ $m-&gt;profile }}">{{ $m-&gt;name }}</span>\n
                         ____SIMPLE_HTML_DOM__VOKU__AT____endif\n
                       ____SIMPLE_HTML_DOM__VOKU__AT____endforeach\n

So, this works well for me to manipulate html parts of the blade file.

However, a case below messes it up:

       @for ($i = 2; $i <= 6; $i++)
           <div class="form-group">
             <label for="file{{ $i }}" class="col-md-2 control-label">添付
               {{ $i }}</label>
             <div class="col-md-10">
               <input type="file" name="file{{ $i }}" id="file{{ $i }}">
               <input id="filename{{ $i }}" type="hidden" name="filename{{ $i }}"
                 value="">
               {{ HTML::error($errors, 'file{$i}') }}
             </div>
           </div>
         @endfor

You see below, the for part gets truncated.

            ____SIMPLE_HTML_DOM__VOKU__AT____for ($i = 2; $i \n
                    <label for="file{{ $i }}" class="col-md-2 control-label">添付\n
                      {{ $i }}</label>\n
                    <div class="col-md-10">\n
                      <input type="file" name="file{{ $i }}" id="file{{ $i }}"/>\n
                      <input id="filename{{ $i }}" type="hidden" name="filename{{ $i }}" value=""/>\n
                      <x-error name="file{$i}"/>\n
                    </div>\n
                  </x-form></div>\n
                ____SIMPLE_HTML_DOM__VOKU__AT____endfor\n

I believe that because 'i <= 6' includesa html starting tag: <.

I wonder if there is anyway to prevent this from happening.

Thanks in advance.

@lotsofbytes
Copy link
Author

@voku, Do you have any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant