I'm using Sublime Text 2 for some find&replace operations. I'm looking for a regex that replaces only the h1 classes tags to bootstrap breadcrumbs, but doesn't affect the content inside them. Each h1 tag has a different text and as there're over 700 files, doing this manually is a hard work!
For example, i'd like to replace this:
<h1 class="xyz">SOME CONTENT</h1>
To this:
<ol class="breadcrumb">
<li>
anylink
</li>
<li>
<span>SOME CONTENT</span>
</li>
</ol>
That "SOME CONTENT" would be the text that I want to keep.
It is possible?
I'm using this code to find the tags and content:
<h1 class="xyz">[^<>]*</h1>
But if i replace to this:
<ol class="breadcrumb">
<li>
anylink
</li>
<li>
<span>[^<>]*</span>
</li>
</ol>
It replaces the text (which I want to keep) with the expression [^<>]*.
Any idea?
Here is another example (I do not think it is necessary to include the closing >):
<h1 class="xyz">([^<]*)</h1>
The capturing group ([^<]*) its saying “Anything that is not a < zero to more times”
And then you should use the captured group with \1 or $1, (I do not know how it works on sublime)
<ol class="breadcrumb">
<li>
anylink
</li>
<li>
<span>\1</span> <!-- or $1, the one sublime text uses -->
</li>
</ol>
You can achieve it like this :
find using :
<h1 class="xyz">([^<>]*)</h1>
replace with :
<ol class="breadcrumb">
<li>
anylink
</li>
<li>
<span>$1</span>
</li>
</ol>
In the search field, you'll need to capture the text you want in a group with brackets :
<h1 class="xyz">([^<>]*)</h1>
And in the replace field, use the captured group with $1 like this :
<ol class="breadcrumb">
<li>
anylink
</li>
<li>
<span>$1</span>
</li>
</ol>
Hope it helps.
Related
<li> text text ( text ) </li>
I don't know it confuses me, an a tag inside li tag between 2 parentheses ?
Yes:
<li> text text ( text ) </li>
If not, you wouldn't be able to do things like
<ul>
<li>this is a list item with an inline link</li>
</ul>
Html is a very flexible language and some bad codes works that you think that will never works! But your code has no problem.
And you could write that in this way:
<li> text text (text) </li>
I have an eBay shop and when I make a listing I have a pre made template and I just import information to this template.
I have a short description, features, and specifications. And I need to add automatically <li></li> to every line and a pre made HTML table with custom style, Which will know how to separate with "/" symbol like I have in my private listing tool.
Is this even possible? And if it is any idea how?
I do not believe Magento works in that manner however there is an easy efficient way to accomplish this manually.
Try putting the code in Sumblime text 3 with teh Emmet plugin.
From there you can type a command like ul>li*8 (the 8 is the # of items or <li></li> tags) and then press the tab key.
the results will be
<ul>
<li> </li>
<li> </li>
<li> </li>
<li> </li>
<li> </li>
<li> </li>
<li> </li>
<li> </li>
</ul>
From there you can fill in the blanks between the <li></li>.
Can you guys please tell me that the following code is valid or invalid ? can i use div tag inside list?
<ul>
<li> Sample
<ul>
<li> Main </li>
<div>
<p> </p>
</div>
</ul>
</li>
</ul>
No, it's not valid because <div> tag is not allowed inside a <ul> element, you'll need to add it inside a <li> tag to make it valid:
<li> Main </li>
<li><div><p> </p></div></li>
I recommend you to use http://validator.w3.org/check instead of asking here in SO.
I have the following HTML:
<ul>
<li>
Home
</li>
<li>
About
<ul>
<li>
History
</li>
<li>
Contact
<ul>
<li>
Email
</li>
<li>
Phone
</li>
</ul>
</li>
</ul>
</li>
<li>
FAQ
</li>
</ul>
I want to be able to select nodes based on part of the a tag href using an XPATH expression.
I don't have the full href, only the last part.
So say I want to find the node that links to "History.aspx" I would use something like:
//#href()[. = 'History.aspx']
It looks like you want //a[contains(#href, 'History.aspx')] to get the entire anchor node. if you want just the href path, then //a[contains(#href, 'History.aspx')]/#href.
Hope that helps.
How do you get Internet Explorer 6 and 7 to not literally interpret whitespace and line breaks in HTML list items? In the image below, I have marked the undesired whitespace in red. I would prefer to not squeeze everything into one giant line of code. It's very hard to read that way. Is there a CSS alternative?
<ol>
<li>
<img>
Sentence 1
Sentence 2
</li>
<li>
<img>
sentence
</li>
<li>
sentence
</li>
</ol>
Here is some useful information Closing gaps in ie
Use a different browser? haha, but in all seriousness, i would suggest just formatting your code to show it properly. Perhaps encapsulating the sentances in spans could do it
<ol>
<li>
<img>
<span>Sentence 1</span>
<span>Sentence 2</span>
</li>
<li>
<img>
<span>sentence</span>
</li>
<li>
<span>sentence</span>
</li>
</ol>