visual studio auto-formatting - visual-studio

just a little one.
Visual studio's auto formatting takes the below line of code:
<li>All Catered Chalets</li>
and turns it into this line of code:
<li>
<a href=""
<?php print $directorylifts; ?>catered-chalets/index.php">All Catered Chalets
</a>
</li>
Note how it's inserted an extra quotation mark after the href= so the code no longer works.
I could just turn off the auto formatting but I find it helpful. Any ideas how to adjust it to stop this happening?
my files have the .php extension.
Thanks,
Phil.

Related

Trying to sequence numbers for multiple lines in Emmet wrap abbreviation for Sublime

New to the coding game, and familiarizing myself with Sublime Text and its plugins on Windows10.
After much searching, I finally figured out that v 3 and 4 do not offer the inherent ctrl+shift+g macro to wrap with abbreviation, so I manually binded those keys to that command:
{"keys": ["ctrl+shift+g"], "command": "emmet_wrap_with_abbreviation"},
The problem now is I can't get $$ for multiple lines to sequence, i.e. 01-07. It instead outputs 01-01.
For example:
Typed Monday-Sunday on separate lines. Shif+right-click highlight days to tag and wrap individual lines. ctrl+shift+g to bring up emmet wrap abbreviation command line.
In line typed li.day-$$>span
Output:
<li class="day-01"><span>Monday</span></li>
<li class="day-01"><span>Tuesday</span></li>
<li class="day-01"><span>Wednesday</span></li>
<li class="day-01"><span>Thursday</span></li>
<li class="day-01"><span>Friday</span></li>
<li class="day-01"><span>Saturday</span></li>
<li class="day-01"><span>Sunday</span></li>
But should have been:
<li class="day-01"><span>Monday</span></li>
<li class="day-02"><span>Tuesday</span></li>
<li class="day-03"><span>Wednesday</span></li>
<li class="day-04"><span>Thursday</span></li>
<li class="day-05"><span>Friday</span></li>
<li class="day-06"><span>Saturday</span></li>
<li class="day-07"><span>Sunday</span></li>
as it was in a tutorial I was watching. Although, the tutorial was from 2014, so it would have been an older version of Sublime as well as Emmet, if that matters. Additionally, since the binded keys performed the function of bringing up the wrap abbreviation command line, I suspect a function in the line itself, but I'm not sure what or why.
It looks like you’ve used multiple cursors to select each line individually then wrapped it with abbreviation. Instead, you should select text you want to wrap as a single selection.
Also, when wrapping multiline text, you should mark repeated element with *. In your case, abbreviation should look like this: li.day-$$*>span
https://docs.emmet.io/actions/wrap-with-abbreviation/#wrapping-individual-lines

How can I replace HTML with a razor helper in bulk (possibly using resharper search by pattern)?

I have some repeated HTML on a razor page which I want to replace with a razor helper. I'm using resharper 2017 and am hoping that the Search By Pattern feature will save me some time here, but I can't work out how to make it do what I want. I'm not sure if I'm trying to use it for the wrong purpose, or if I'm just using it badly.
This is (a small section of) the HTML I want to replace:
<li role="presentation" data-bind="visible: includeMtbf">
Rolling and Monthly MTBF
</li>
<li role="presentation" data-bind="visible: includeMtbfWithoutMonthly">
Rolling MTBF
</li>
<li role="presentation" data-bind="visible: includeMtbfByArea">
Rolling MTBF by Location
</li>
I've written the following razor helper:
#helper BuildTab(string tabId, string inclusionVariable, string tabText)
{
<li role="presentation" data-bind="visible: #inclusionVariable">
#tabText
</li>
}
Now I just need to replace the original HTML with calls to the helper:
#BuildTab("mtbf-tab", "includeMtbf", "Rolling and Monthly MTBF")
#BuildTab("rolling-mtbf-tab", "includeMtbfWithoutMonthly", "Rolling MTBF")
#BuildTab("mtbf-by-location-tab", "includeMtbfByArea", "Rolling MTBF by Location")
I've done them manually for the sake of clarifying what I'm trying to achieve, but is there a way to get resharper (or visual studio) to do this for me?
I've written the following pattern for resharper to search by:
<li role="presentation" data-bind="visible: $inclusionVariable$">
$tabText$
</li>
but I can't work out how to set up the placeholder types to match the arbitrary text which could appear. With them set to Content Placeholder they don't match correctly, but none of the other types seem appropriate. Is this possible (either using resharper or a visual studio feature that I don't know about)?
I don't believe resharper can handle this, but it seems like a case for using regular expressions to find and replace in all files.
Something like (untested):
Find pattern
<li\s+role="presentation"\s+data-bind="visible:\s*(\w+)">\s*<a\s+href="#([\w\-]+)"\s+role="tab"\s+data-toggle="tab">([\w\s]+)</a>\s*</li>
Replace pattern
#BuildTab("$1", "$2", "$3")
Will all depend on how regular your original code is, but you might be able to modify the search regex to deal with irregularities.

Need an efficient way to avoid repeated code snippets using Laravel 5

I have a view that creates 9 blocks in an HTML page. Each block can either have one large note (like a sticky note) or up to 6 small notes.
On each of the notes there is an option to show a comment.
The code to make those comment options thus appears 18 times in the view - there must be a better way to do it rather than have the code block appear so many times. A function that writes it out perhaps?
This is the code block:
<!-- start comments popover -->
<div class="popover-medium">
<a href="javascript:void(0)" class="icon-entypo icon-text-document btn-note trigger" data-toggle="popover" data-placement=right></a>
<div class="popover-avatar content hide">
<ul class="row popover-content border-bottom list-inline">
<li class="col-xs-9">
<span class="small clearfix"></span>
<span class="small">
#if (!empty($name->comments))
{{$name->comments}}
#else
No comments
#endif
</span>
</li>
</ul>
</div>
</div>
<!-- end comments popover -->
Any ideas/direction would be greatly appreciated!
Add your code block to a new blade file e.g. myblock.blade.php
Then in your main view you can call #include('myblock')
When the page renders it will replace the #include line with your block of code.
Also, its not totally clear what your question is. But it may also be worth noting that you can do this:
#foreach($array as $item)
#include('myblock', ['item'=>$item])
#endforeach
Then just reference $item in your block of code. You may actually not need to pass the $item as an argument to #include as I think when the page renders, the script can use all variables in the page.
Note: Some people struggle with the naming convention of blade views. See my answer to a previous post if you are struggling

Ctrl + k + d not removing blank lines in HTML editor VS2012

When auto formatting (ctrl + k + d) html editor in VS2012 it is not removing blank lines. This used to work in VS2010. I looked in the Tools > Options > Text Editor > HTML > Formatting, but I didn't find anything to fix the issue. This was a handy feature when there was alot of html code. Does anyone know how to get this working in VS2012?
Below is a crude example. Ya, I know you can do this manually but auto formatting makes it easy.
<article>
<ul>
<li>Item 1
blank line
</li>
<li>Item 2
blank line
</li>
blank line
blank line
</ul>
blank line
blank line
blank line
<ul>
<li>Item 1</li>
blank line
blank line
blank line
<li>Item 2</li>
</ul>
</article>
Well it turns out that they removed this feature due to complaints. I had VS2010 Professional SP1 and it used to work. Here is a link from MSDN forums with explanation. MSDN Format Document

Middleman & Haml with Github-style fenced code blocks

I'm starting using Middleman for static web pages & blogging purposes. I'm using it with a ZURB Fondation based template, Middleman-Foundation. It employs Haml, and I'm indeed inclined to use Haml, with Markdown files occasionally.
I'm using redcarpet for markdown, to also make use of Github-style fenced code blocks for source highlighting. But I could not figure out how to setup it for Markdown in Haml.
I've checked middleman-syntax which works for .html.md but not for .html.haml. I've tried to figure it out from Glorify but failed. I've checked this and this too.
What are the basics steps to achieve working fenced code blocks in Haml Markdown to produce highlighted source code.
It would be awesome to have a set of steps from start for this, from gem install middleman and cloning/employing Middleman-Foundation, but any short, actual answer is welcome.
EDIT
I was able to achieve pygmentized code blocks in Haml with the following (sad that it seems not possible to use markdown with fenced code blocks for this...):
%li#simple3Tab This is simple tab 3's content. It's, you know...okay.
%li#simple4Tab
-code("ruby") do
:plain
def my_cool_method(message)
puts message
end
%h3 Buttons
But there's a lasting problem, this is what I'm getting:
As can be seen the first line is not correctly being indented, this is happening because the previous code snippet is not producing a heading linebreak:
<li id='simple3Tab'>This is simple tab 3's content. It's, you know...okay.</li>
<li id='simple4Tab'>
<div class="highlight"><pre><span class="k">def</span> <span class="nf">my_cool_method</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
<span class="nb">puts</span> <span class="n">message</span>
<span class="k">end</span>
</pre></div>
</li>
</ul>
<h3>Buttons</h3>
I cannot figure out how to break the line before the first <span>, following the opening <pre>, so that the code gets correctly indented like the other lines.
Desired:
<li id='simple3Tab'>This is simple tab 3's content. It's, you know...okay.</li>
<li id='simple4Tab'>
<div class="highlight"><pre>
<span class="k">def</span> <span class="nf">my_cool_method</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
<span class="nb">puts</span> <span class="n">message</span>
<span class="k">end</span>
</pre></div>
</li>
</ul>
<h3>Buttons</h3>
I was able to figure it out through trial & error using the bits of information provided by #bhollis, Haml reference, and this SO question pointed by the Glorify author.
This is the magical combination:
%li#simple3Tab This is simple tab 3's content. It's, you know...okay.
%li#simple4Tab
=preserve do
-code("ruby") do
:plain
def my_cool_method(message)
puts "Hello" + message
end
%h3 Buttons
The result (for this one I've enabled an emacs stylesheet):
This not only solved the question about the "missing" heading newline, but also removed the extra indentation that the referred SO question talks about.
I'm still open for shorter and better approaches. Three lines of preamble to input code is a bit inconvenient.
Check out the docs for middleman-syntax: https://github.com/middleman/middleman-syntax
Code highlighting is automatically included in Markdown code blocks (via Redcarpet), but in Haml, it's better to use the "code" helper:
- code("ruby") do
My ruby code here

Resources