js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

Add an option to not indent lines containing only php (& the php tags )

Open tenzap opened this issue 3 years ago • 0 comments

Description

  • Add an option to not indent lines containing only <?php ?>

When I say not indent, I mean "put them at the head of the line" (if they aren't already), I don't mean "leave it like in the original"

  • This could be extended to not indent lines that have both opening & closing php tags on the same line like <?php echo 'do something' ?> (provided that there is nothing but spaces before <?php and after ?>)

  • Concerning the lines like below (that have only PHP and only the closing or opening php tag), ~~I don't know what's best. Maybe it would be consistent to also align them left, without indentation. <?php echo 'do something' But it could be ugly with echo 'do something' ?>~~ Probably, in case <?php is multiline, the closing tag ?> should be put apart, alone on a new line on the same level as the opening tag.

This is inspired by this thread

Like one of the comments, I find too that it is easier to distinct what is php, js or HTML when reading such files.

Input

With this new feature, when I give like this input:

<script type="text/javascript">
	// javascript code
	var data='a';
	<?php
	// php code
	// php code
	// php code
	// php code
	?>
	var data2='b';
	<?php // php code ?>
	var data3='<?php echo 'c' ?>';
</script>
       <?php echo 'do something';
    echo 'some more';?>
<p>yes!</p>
<span style="<?php echo 'do something';
    echo 'some more';?>">aaa</span>
<div>
	<?php if (isset($contact)): ?>
		<input name="groups" id="groups" value="<?php echo $this->Phonebook_model->get_groups($contact->row('id_pbk'), $this->session->userdata('id_user'))->GroupNames?>" type="hidden" />
	<?php elseif ( ! empty($group_id)):?>
		<input name="groups" id="groups" value="<?php echo $this->Phonebook_model->group_name($group_id, $this->session->userdata('id_user'))?>" type="hidden" />
	<?php else : ?>
		<input name="groups" id="groups" value="" type="hidden" />
	<?php endif;?>
</div>

Expected Output

I'd like to see this output:

<script type="text/javascript">
	// javascript code
	var data='a';
<?php
	// php code
	// php code
	// php code
	// php code
?>
	var data2='b';
<?php // php code ?>
	var data3='<?php echo 'c' ?>';
</script>
<?php echo 'do something';
    echo 'some more';
?>
<p>yes!</p>
<span style="<?php echo 'do something';
    echo 'some more';?>">aaa</span>
</div>
<?php if (isset($contact)): ?>
	<input name="groups" id="groups" value="<?php echo $this->Phonebook_model->get_groups($contact->row('id_pbk'), $this->session->userdata('id_user'))->GroupNames?>" type="hidden" />
<?php elseif ( ! empty($group_id)):?>
	<input name="groups" id="groups" value="<?php echo $this->Phonebook_model->group_name($group_id, $this->session->userdata('id_user'))?>" type="hidden" />
<?php else : ?>
	<input name="groups" id="groups" value="" type="hidden" />
<?php endif;?>
</div>

Environment

OS: linux debian 11

tenzap avatar Dec 07 '21 10:12 tenzap