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

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

Related

Xpath - Exclude one branch in Unordered List

I have a navigation menu in which I wish to bold certain areas of the menu using an injection script.
I wish to use a generic xpath to bold each of the items in the menu that I want.
Problem is, the menu has some selections of the same name that I do not bolded, all in one particular sub-menu.
The menu would look something like this:
<ul class="main-menu">
<li class="sub-menu">Employees</li>
<ul>
<li>Address List</li>
</ul>
<li class="sub-menu">Clients</li>
<ul>
<li>Address List</li>
</ul>
<li class="sub-menu">Contractors</li>
<ul>
<li>Address List</li>
<ul>
</ul>
To find the 'Address list', I might use an Xpath similar to this...
//ul[#class="main-menu"]//li[text()="Address List"]
Problem is, that would highlight all "Address List" items, and I do not want anything in the Employees list.
Keep in mind, this is only a sample menu, and I need to highlight more stuff all over the menu, both in sub-menus and on the main list, but I do not want to highlight anything in the Employees sub-menu, I want to exclude just those items in that list.
I've tried 'except' and 'not' but I guess I'm not getting how to use it or am putting it in the wrong context.
Try this on your actual html and see if it works:
//ul[#class="main-menu"]//
li[not(./text()="Employees")]
/following-sibling::ul/li[text()="Address List"]

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.

XPath is broken when changes are made

This is the current situation: There are several files and folders in a specific location.
Once you hover over a file or a folder, an icon appears then you can click on that icon and a menu will appear. From that menu a user can select any action(rename, move,etc). The problem is that the XPath which is provided by FirePath is broken whenever a new file/folder is created/added in the location.
This is the initial line of code which works fine until the XPath is broken:
webDriver.findElement(By.xpath("//*[#id='main_files_view']/ol/li[6]/ul/li[4]")).click();
Whenever a new item is added in the location, the index with value "6" can change to "7" (new position of the file) and the XPath generated is now slightly different:
webDriver.findElement(By.xpath("//*[#id='main_files_view']/ol/li[7]/ul/li[4]")).click();
How can I change that XPath and makes it robust so that no matter the number of items added/removed, the XPath will not break?
Below is the section of the HTML which is related to the XPath provided by FirePath.
When the XPath is provided, the last class is also highlighted.
<li class="storage_item document file_object even ui-draggable" data-thumb-translation="Translated" data-possible-actions="Rename Delete Share Move View" data-file-size="0 bytes" data-item-type="file" data-display-name="solids_A" data-name="solids_A.raas" data-id="bd48453c752043d98afb237b86ee88a3">
<a class="file_name" href="#/Item/Details?id=bd48453c752043d98afb237b86ee88a3&itemtype=File&tab=Default">
<img class="file_list_icon" width="16" height="16" src="https://api-staging.autodesk.com/content/gateway/2013.1.307595.626/z/Content/images/fileIcons/small/raas.png"/>
<div class="name_container">
<ul class="tools">
<li class="preview_trigger"/>
<li class="comment_balloon none has_tooltip" data-tooltip-contents="#comment_balloon_tooltip" data-comments="0">
<li class="categorize action has_tooltip" data-tooltip="Categories"/>
<li class="document_tools has_tooltip" data-tooltip="Actions"/>
</ul>
</li>
I am using Selenium 2.0, on Eclipse IDE.
If the data-name is unique, then you have
//*[#id='main_files_view']/ol/li[#data-name='solids_A.raas']/ul/li[contains(#class, 'document_tools')]
Css Selector is even better than XPath in this case:
#main_files_view li[data-name='solids_A.raas'] .document_tools
Try this:
By.XPath("//*[#id='main_files_view']/ol/li/ul/li[4]")
You do not have to define every index in an xpath and often if it's just one that change, removing that index will work.
In general you should avoid xpaths in your tests. Css selectors are faster (especially in IE) and more readable. If data-name is unique then this should work:
webDriver.findElement(By.cssSelector("#main_files_view li[data-name='solids_A.raas'] li.document_tools"));
If you really need an xpath the one provided by user1177636 will also do the job.

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

HTML formatting in TextMate (automatic 'outdenting')

I'm using TextMate and indentation isn't working as I'd expect - more specifically, it doesn't 'outdent' closing tags for me.
I create a new HTML file, I move the cursor down to the body section ... and I type
<ul>(newline)
It appropriately indents the next line for me so I build the following
<ul>
<li>hello
</li>
</ul>
Clearly, the closing tags "could" be outdented to line up with their start tags. I'm surprised TextMate doesn't do this automatically. Am I missing something? Sometimes I like to type my opening and closing tags and then fill-in the blanks ... but I keep getting this:
<div>
</div>
It indents correctly - but it doesn't understand that this is a closing tag -- which means I've got to move the cursor behind the closing tag and outdent it myself.

Resources