So, I'm trying to migrate a database from Textpattern CMS to something more generic. There are some textpattern-specific commands inside of articles that pull in images. I want to turn these into generic HTML image links. At the moment, they look like this in the sql file:
<txp:upm_image image_id="4" form="dose" />
I want to turn these into something more like this:
<img src="4.jpg" class="dose" />
I've had some luck with TextWrangler doing some regex stuff, but I'm stumped. Any ideas on how to find & replace all of these image paths?
EDIT:
For future reference, here's what I ended up doing in PHP to output it:
$body = $post['Body_html'];
$pattern = '/txp:upm_image image_id="([0-9]+)" form="([^"]*)"/i';
$replacement = 'img src="/images/$1.jpg" class="$2"';
$body = preg_replace($pattern, $replacement, $body);
// outputed <img src="/images/59.jpg" class="dose" />
I wouldn't use grep; it's sed you want
$ echo '<txp:upm_image image_id="4" form="dose" />' | sed -e 's/^.*image_id="\([[:digit:]]*\)".*form="\([[:alpha:]]*\)".*/<img src="\1.jpg" class="\2" \/>/'
<img src="4.jpg" class="dose" />
$
if your class has alphanumeric characters, use [[:alnum:]]
(works on macos darwin)
Not sure which tool you are using but try this regex solution: Search for this:
<txp:upm_image\s+image_id="(\d+)"\s+form="([^"]*)"\s*\/>
And replace with this:
<img src="$1.jpg" class="$2" />
Note that this only works for txp tags having the same form as your example. It will fail if there are txp tags having extra attributes, or if they are in a different order.
Related
Suppose I have the following
[uri]$URL = "https://www.example.com/folder/folder2"
I would like to get this part along with the first local path, i.e. https://www.example.com/folder
In other words, I dont want folder2 etc... because i plan to append this portion to an api path, so eventually i'd have something like $URL + "/api/v2.0/" or https://www.example.com/folder/api/v2.0/
I figured it out using -split
($URL -split "folder2")[0]
this gives https://www.example.com/folder/
I have an array of 150 buttons that link to 150 pictures, i need to show the picture once the button is pressed. The information for the buttons is stored in a JSON file. The pictures names are the ID's of the buttons, so 1.jpg, 2.jpg etc.
Now I am facing the problem that I can't write:
fish["image"] = {uri: "asset-library://" + fish.id + ".jpg"};
And the other solution with if statements does not work since I have so many options, any ideas?
Thanks so much
I had a similar problem. I built a function that contains a huge switch statement and has static requires for every case.
function getImage(id) {
switch(id) {
case 1:
return require('./img/1.jpg');
case 2:
return require('./img/2.jpg');
...
}
}
Now you can do
fish["image"] = getImage(fish.id);
I also had to use over 100 icons, so instead of writing the cases by hand, I built a script that generates the function automatically.
I had too this problem for a component I developed. I used base64 image in json file. But maybe it's not a good fit for you, I hope it can help.
<Image
style={styles.imgStyle}
source={{uri: CountryFlags[country.cca2]}}
/>
You can see it here : https://github.com/xcarpentier/react-native-country-picker-modal/blob/master/src/index.js#L137-L139
And if you have a folder with files on it, simply convert images like that :
#!/bin/sh
list=`ls ./flags | grep '[A-Z]'`
echo "{"
for item in $list
do
header="data:image/png;base64,"
img64=`ls ./flags/$item | xargs cat | base64`
echo ${item:0:2} :\'$header$img64\',
done
echo "}"
Here is my sample html code:
when I send this as an email using mutt to my outlook, the output is as follows:
The command I used is:
mutt -e "my_hdr Content-Type: text/html" -s "Subject: my subject" mymail#outlookmail.com < sampletable.html
In the second table there is some different format. First table is not looking good as well.
If there are more than 2 tables, all the alternate tables are having the same format as second one.
How to make my email look good?
PS: I am generating this sample html table code using awk in a bash script.
Thanks in advance.
replace ending <tr> by closing tr : </tr>.
I need to print a barcode on Odoo (v8) pos receipt using posbox.
I tried like this :
<barcode encoding="CODE39"><t t-esc='receipt.coupon_code'/></barcode>
Result : Nothing is printed . But if I make a test like :
<barcode encoding="CODE39">*123456798*</barcode>
It prints the barcode.
I also tried like this without success:
<img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' % ('CODE39', receipt.coupon_code, 600, 100)" style="width:300px;height:50px"/>
Any advice ?
Thanks a lot.
In fact,
<barcode encoding="CODE39"><t t-esc='receipt.coupon_code'/></barcode>
works perfectly...
The problem was the length of receipt.coupon_code.
For information, this coupon_code is randomly generated .
It prints successfully the barcode with an 8 digits code, starting and ending with "*" ( *12345678*, for example)
I created one receipt and I know how to write barcode in receipt for that you have to convert your barcode in image and then split it. You have to make changes in .xml file. Steps are as follow:
Convert this code in image using <img> tag after then split that like this:
<img t-if="field_name" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s&humanreadable=%s' % ('Code128', field_name.split(' ')[1], 600, 100, 1)" style="width:300px;height:50px"/>
Here field_name is that field of py where your barcode is stored.
Long story short - I'm capturing SQLs from vendor tool to Oracle database by using Wireshark. It already has decoder for TNS protocol (which is great) and I can access text of SQL by
Right Click->Copy->Bytes(Printable Text Only).
The problem is that there are tons of packets and doing right-click on each of them could take ages. I was wondering if there any way to export 'Printable Text Only' right from Wireshark. Ideally I want to have a text file with statements.
Any help will be highly appreciated.
Finally found away to do this. First, use tshark capturing tns packets:
tshark -R tcp.port==1521 -T fields -e data.data -d tcp.port==1521,tns > input.txt
Then you could use home brew Ruby script below to transform from bytes to text:
file = ARGV[0]
print_all = ARGV[1]
File.open(file, "r").each {|line|
line.gsub(",", ":").split(':').each {|byte|
chr = Integer('0x' + byte).chr
print chr if ((' '..'~').include?(chr) or chr == "\n") or (print_all.downcase == 'all' if print_all)
} if !line.chomp.empty?
}
Examples are:
encode.rb input.txt > output.txt
will export printable text only from input to output
encode.rb input.txt all > output.txt
will export all text from input to output
An easy way of looking at them all that has worked for me is just Right Click -> Follow TCP Stream.
A note: unprintable characters are displayed as .s. If there are a bunch of these interspersed between all the text you want to extract (as there was for me), switch it to ASCII, save it and open it in your favourite text editor (vim for me), then run a search and replace similar to /\.//g.
I don't know how to do it with TNS. but you can do something like this using tshark, for example to look at http requests.
tshark -T fields -e http.request.uri
So if you can look at the options in the TNS decoder, you should be able to grab that field and redirect the output to a file.