Sublime, search whole file that contain specific words and replace whole line of code - sublimetext

<img src="/assets/default/img/activity/36.svg"
<script src="/assets/default/js/lines.js"></script>
<link rel="stylesheet" href="/assets/default/vendors/chartjs/chart.min.css"/>
and so on...
Notice that each of these has the same words which contains /assets/default/. How do I replace the whole line from the start of double quote to end of quote to {{ asset('the whole words inside double quote') }}?
So expected to be like this:
<img src="{{ asset('assets/default/img/activity/36.svg') }}"
<script src="{{ asset('assets/default/js/lines.js') }}"></script>
<link rel="stylesheet" href="{{ asset('assets/default/vendors/chartjs/chart.min.css') }}"/>

I guess you are asking about a regular expression search replace. Bring up the normal find/replace panel (Find -> Replace ...), and clicke the E button (or maybe .* depending on your ST version) to turn on regular expressions.
You want to find things that start with your file path, and you want to capture the variable part of the path and use it again. You can do that with an expression like this (in the Find input):
"/assets/default(.+?)"
Sublime will hightlight matches in the source as you type, so you can confirm it is working as you write.
Now you want to replace that with the asset() version, including the variable part you captured in brackets above. You can do that with the following (in the Replace input):
"{{ asset('/assets/default$1') }}"

If you want to find and replace text in a number of files at once, press Command+Shift+F or Control+Shift+H to open Sublime Text's Find in Files tool that can search and replace across as many files as you have open or select from its menu.
For detail please click here

Related

Laravel change img src on data fetch

I am retrieving text which contains images saved in WYSIWYG editor(Summernote). Is there a way to replace src attribute value in img tags using asset()?
Example:
<img src="images/image.jpg"/>...
To:
<img src="https://.../images.jpg"/>
I want solution which would cover all bases: spaces in image name, different extensions...
Sure, just use the curly brace syntax in your blade to render the asset()
<img src="{{ asset('whatever_you_want') }}"/>
I don't think you can do it in Blade. You could, in your model, add a function that replaces all images to full paths. This could be done through a regex pattern that looks for URLs in tags.
I would, however, make sure the full path to the image is included in the text in the database. This way, you always have access to the right path to the image, and you're not relying on a piece of code to display the right image.

Blade - How to #push content to start of a #stack?

In blade, you can create stacks. See the following for more information:
https://laravel.com/docs/5.2/blade#stacks
However the above link only shows how to push elements to the end of the stack.
I want to append an element to the start of the stack. How can I do this?
e.g.
#push('foo')pizza #endpush
#push('foo')like #endpush
#push('foo')I #endpush
#stack('foo')
outputs:
pizza like I
I want it to output:
I like pizza
This is something that I wouldn't recommend doing because this is the way Laravel is built.
But, if for any reason, you need it so much and you don't see any other way to accomplish it, You can tweak the framework itself.
The file Factory.php is located in Illuminate\View. over there you have a function called extendPush() and you can change the "Append" method by replacing the line:
$this->pushes[$section][$this->renderCount] .= $content;
with this:
$this->pushes[$section][$this->renderCount] = $content . $this->pushes[$section][$this->renderCount];
in the last else statement.
Again, I wouldn't recommend tweaking the framework but if it's that important to your project than this is what I can offer.
You can create in your blade #stacks everywhere. If you like a stack in the header put in your blade:
<head>
...
#stack('myScriptsAbove')
...
</head>
Then you can push the scripts from other blades to it. Like that #push('myScriptsAbove)`.
In my case, the Parent-Blade file's #push(...), did somehow append after that of Child-Blade file.
But nowadays, we can simply use #prepend, like:
#prepend('css')
<link href="{{ asset('css/app.css') }}" rel="stylesheet"/>
#endprepend
Seems in Blade, #stack works like LIFO queue (Last-In-First-Out);
So, #push and #prepend each do the exact opposite of what I did expect.

Regex encapsulate full line and surround it

I can find examples of surrounding a line but not surrounding and replacing, and I'm a bit new to Regex.
I'm trying to ease up my markdown, so that I do not need to add in html just to get it to center images.
With pandoc, I apparently need to surround and image with DIV tags to get it to be centered, right justified, or what ever.
Instead of typing that every time, I'd like to just preprocess my markdown with a ruby script and have ruby add in the DIV's for me.
So I can type:
center![](image.jpg)
and then run a ruby script that will change it to
<div class="center">
![](image.jpg)
</div>
I want the regex to find "center!" and get rid of the word "center" and surround the rest with DIV tags.
How would I accomplish this?
A little example using gsub:
s = "a\ncenter![](image.jpg)\nb\n"
puts s.gsub(/^center(.*)$/, "<div class=\"center\">\n\\1\n</div>")
Result is:
a
<div class="center">
![](image.jpg)
</div>
b
Should get you started. The (.*) captures the content after center, and \\1 adds it back into the replacement. In this example I assumed that the item was on a line by itself - ^ indicates the start of a line and $ indicates the end of a line. If that isn't the case, you'll need to determine what makes what your regex unique so that it doesn't replace any random usage of "center" in your text.

Xpath of a text containing Bold text

I am trying to click on the link whose site is www.qualtrapharma.com‎ by searching in google
"qualtra" but there is problem in writing xpath as <cite> tag contains <B> tag inside it. How to do any any one suggest?
<div class="f kv" style="white-space:nowrap">
<cite class="vurls">
www.
<b>qualtra</b>
pharma.com/
</cite>
<div>
You may overcome this by using the '.' in the XPath, which stands for the 'text in the current node'.
The XPath would look like the following:
//cite[.='www.qualtrapharma.com/']

scrapy: Remove elements from an xpath selector

I'm using scrapy to crawl a site with some odd formatting conventions. The basic idea is that I want all the text and subelements of a certain div, EXCEPT a few at the beginning, and a few at the end.
Here's the gist.
<div id="easy-id">
<stuff I don't want>
text I don't want
<div id="another-easy-id" more stuff I don't want>
text I want
<stuff I want>
...
<more stuff I want>
text I want
...
<div id="one-more-easy-id" more stuff I *don't* want>
<more stuff I *don't* want>
NB: The indenting implies closing tags, so everything here is a child of the first div -- the one with id="easy-id"
Because text and nodes are mixed, I haven't been able to figure out a simple xpath selector to grab the stuff I want. At this point, I'm wondering if it's possible to retrieve the result from xpath as an lxml.etree.elementTree, and then hack at it using the .remove() method.
Any suggestions?
I am guessing you want everything from the div with ID another-easy-id up to but not including the one-more-easy-id div.
Stack overflow has not preserved the indenting, so I do not know where the end of the first div element is, but I'm going to guess it ends before the text.
In that case you might want
//div[#id = 'another-easy-id']/following:node()
[not(preceding::div[#id = 'one-more-easy-id']) and not(#id = 'one-more-easy-id')]
If this is XHTML you'll need to bind some prefix, h, say, to the XHTML namespace and use h:div in both places.
EDIT: Here's the syntax I went with in the end. (See comments for the reasons.)
//div[#id='easy-id']/div[#id='one-more-easy-id']/preceding-sibling::node()[preceding-sibling::div[#id='another-easy-id']]

Resources