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

Added PHP short tag handling #1902

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/core/templatablepattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function TemplatablePattern(input_scanner, parent) {
handlebars_comment: pattern.starting_with(/{{!--/).until_after(/--}}/),
handlebars_unescaped: pattern.starting_with(/{{{/).until_after(/}}}/),
handlebars: pattern.starting_with(/{{/).until_after(/}}/),
php: pattern.starting_with(/<\?(?:[=]|php)/).until_after(/\?>/),
php: pattern.starting_with(/<\?(?:[=]|php| )/).until_after(/\?>/),
erb: pattern.starting_with(/<%[^%]/).until_after(/[^%]%>/),
// django coflicts with handlebars a bit.
django: pattern.starting_with(/{%/).until_after(/%}/),
Expand Down
34 changes: 34 additions & 0 deletions js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7115,6 +7115,40 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
bth('<<?= html_element(); ?> <?=language_attributes();?>>abc</<?= html_element(); ?>>');
bth('<input type="text" value="<?=$x["test"] . $x[\'test\']?>">');

// minimal template handling - ()
reset_options();
set_name('minimal template handling - ()');
bth('<h1 class="content-page-header"><? $view["name"]; ?></h1>', '<h1 class="content-page-header"><? $view["name"]; ?></h1>');
bth(
'<? \n' +
'for($i = 1; $i <= 100; $i++;) {\n' +
' #count to 100!\n' +
' echo($i . "</br>");\n' +
'}\n' +
'?>');
test_fragment(
'<? ?>\n' +
'<!DOCTYPE html>\n' +
'\n' +
'<html>\n' +
'\n' +
'<head></head>\n' +
'\n' +
'<body></body>\n' +
'\n' +
'</html>');
bth(
'<? "A" ?>abc<? "D" ?>\n' +
'<? "B" ?>\n' +
'<? "C" ?>');
bth(
'<? \n' +
'echo "A";\n' +
'?>\n' +
'<span>Test</span>');
bth('<<? html_element(); ?> <? language_attributes();?>>abc</<? html_element(); ?>>');
bth('<input type="text" value="<? $x["test"] . $x[\'test\']?>">');

// minimal template handling - ()
reset_options();
set_name('minimal template handling - ()');
Expand Down
2 changes: 1 addition & 1 deletion python/jsbeautifier/core/templatablepattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, input_scanner):
self.handlebars_comment = pattern.starting_with(r"{{!--").until_after(r"--}}")
self.handlebars_unescaped = pattern.starting_with(r"{{{").until_after(r"}}}")
self.handlebars = pattern.starting_with(r"{{").until_after(r"}}")
self.php = pattern.starting_with(r"<\?(?:[=]|php)").until_after(r"\?>")
self.php = pattern.starting_with(r"<\?(?:[=]|php| )").until_after(r"\?>")
self.erb = pattern.starting_with(r"<%[^%]").until_after(r"[^%]%>")
# django coflicts with handlebars a bit.
self.django = pattern.starting_with(r"{%").until_after(r"%}")
Expand Down
6 changes: 5 additions & 1 deletion test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,7 @@ exports.test_data = {
template: "^^^ $$$",
matrix: [

// Php (<?php ... ?> and <?= ... ?>) =.
// Php (<?php ... ?> and <?= ... ?> and <? ... ?>) =.
{
s: '<?php',
e: '?>'
Expand All @@ -2126,6 +2126,10 @@ exports.test_data = {
s: '<?=',
e: '?>'
},
{
s: '<? ',
e: '?>'
},
// erb, ejs, asp: <% ... %>
{
s: '<%',
Expand Down