Do not escape URL or data URI - rythm

I have an issue with Rythm improperly escaping some parts of the template.
My use cases are as follows.
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath d='M256 8C119.033 8 8 119.033 8 256s111.033 248 248 248 248-111.033 248-248S392.967 8 256 8zm0 48c110.532 0 200 89.451 200 200 0 110.532-89.451 200-200 200-110.532 0-200-89.451-200-200 0-110.532 89.451-200 200-200m140.204 130.267l-22.536-22.718c-4.667-4.705-12.265-4.736-16.97-.068L215.346 303.697l-59.792-60.277c-4.667-4.705-12.265-4.736-16.97-.069l-22.719 22.536c-4.705 4.667-4.736 12.265-.068 16.971l90.781 91.516c4.667 4.705 12.265 4.736 16.97.068l172.589-171.204c4.704-4.668 4.734-12.266.067-16.971z'/%3E%3C/svg%3E">
An image tag with properly encoded data URI will be escaped and ruined. Rythm will escape svg+xml
I have tried storing the data URI in a variable and then using
<img src="#iconData.raw()">
or wraping the image tag in
#raw() {
#myVariable
}
The output is always modified by Rythm:
<img src="data:image/svg+xml,%3Csvg
What else can I do to completely disable escaping and output the content "as is" without ANY modifications? Thanks a lot for any tips :)

Related

Calculate routes via GET - Polyline incorrect

Iam testing routing API(https://developer.here.com/documentation/routing-api/api-reference-swagger.html) and all seems to be working as expect except polyline.
Here I share my service invocation
curl --location --request GET 'https://router.hereapi.com/v8/routes?transportMode=car&origin=3.4844257,-76.5256287&destination=3.478483,-76.517984&routingMode=fast&return=elevation,polyline,actions,instructions,summary&apiKey=1234'
As part of response we have the next field:
"polyline": "B2Fkt10Grm4-xE8yTU4mBnBnG8pBAzP0tBAjD4IA_E8LAvMokBT3IkXTzF8QTnG8QTvMsiBTrJjDA3_BjXoB_sB_OAriB3NAzKjDAnLsTAnLkhBnBzKsdA_J8fTnLkcT3DwHAvC8GArJoQAnL8QA7LsTA7V0jBT_M8UA",
As you know the polyline field is encoded.
According to documentation I proceeded to decoded it with a library/code suggested from:
https://github.com/heremaps/flexible-polyline/tree/master/java
The result of decode the field in not correct. The list of points (Lat,Long,Elevation) returned are not matched with the correct location. In the example, the coordinates are from Colombia and the results, after decodification, returns a list of points in a middle of the Atlanthic ocean.
Further, in order to discard library issues I was checking decoding de polyline with other decoder as:
https://developers.google.com/maps/documentation/utilities/polylineutility
https://open-polyline-decoder.60devs.com/
And the result is the same.
So, seems to be the problems is HereAPI side(API routing v8)
Any ideas? Maybe I am invoking the API in the incorrect way
The decoder on https://github.com/heremaps/flexible-polyline/tree/master/java works correct, see please code with your encoded string:
private void testSOLatLngDecoding() {
List<LatLngZ> computed = decode("B2Fkt10Grm4-xE8yTU4mBnBnG8pBAzP0tBAjD4IA_E8LAvMokBT3IkXTzF8QTnG8QTvMsiBTrJjDA3_BjXoB_sB_OAriB3NAzKjDAnLsTAnLkhBnBzKsdA_J8fTnLkcT3DwHAvC8GArJoQAnL8QA7LsTA7V0jBT_M8UA");
List<String> seqCrds = new ArrayList<>();
for (int i = 0; i < computed.size(); ++i) {
LatLngZ c = computed.get(i);
List<String> crds = new ArrayList<>();
crds.add(String.valueOf(c.lat));
crds.add(String.valueOf(c.lng));
crds.add(String.valueOf(c.z));
seqCrds.add(String.join(",", crds));
//assertEquals(computed.get(i), pairs.get(i));
}
System.out.println(String.join(",", seqCrds));
}
We have a javascript tool "Encode/Decode to/from Flexible polyline" on https://demo.support.here.com/examples/v3.1/enc_dec_flexible_polyline
see please result:
Please double check code on your side.
I would suggest removing your API key from the get request you posted in your question.
Using the polyline that you provided gets decoded into the following, which is in Columbia. As a result, I think you need to check the decoder you are using and/or what is being fed into it.
Index
Lat
Lon
Elev
0
3.48437
-76.52567
1003
1
3.48438
-76.52505
1001
2
3.48428
-76.52438
1001
3
3.48403
-76.52365
1001
4
3.48398
-76.52351
1001
5
3.4839
-76.52332
1001
6
3.4837
-76.52274
1000
7
3.48356
-76.52237
999
8
3.48347
-76.5221
998
9
3.48337
-76.52183
997
10
3.48317
-76.52128
996
11
3.48302
-76.52133
996
12
3.482
-76.5217
998
13
3.48128
-76.52194
998
14
3.48073
-76.52216
998
15
3.48056
-76.52221
998
16
3.48038
-76.5219
998
17
3.4802
-76.52137
996
18
3.48003
-76.5209
996
19
3.47987
-76.52039
995
20
3.47969
-76.51994
994
21
3.47963
-76.51982
994
22
3.47959
-76.51971
994
23
3.47944
-76.51945
994
24
3.47926
-76.51918
994
25
3.47907
-76.51887
994
26
3.47872
-76.5183
993
27
3.478512
-76.517966
993

How to do colouring the contents of a mail while sending via unix terminal using mailx command?

I have a file(.txt) with below details(I am having more than 50 files but listed only 4) and while sending that file via mail I want to implement some coloring to it. I am not sure while it is possible or not, Could you please help me on this please ?
date filename_now avg_timestamp space count status
Nov 4 CHCK01_20161104.txt 06:39 2.15M 17153 Delayed --> RED
Nov 4 TRIPS11_20161104.txt 09:03 0.00M 024 On_Time --> GREEN
Nov 4 AR02_20161104.txt 09:31 0.00M 007 No_Files --> YELLOW
Nov 4 AR01_20161104.txt 09:31 0.04M 433 Delayed --> RED
This it I am getting in my mail(MS outlook), Can I implement coloring for the status field as requested?
Thanks a lot for your time.
If all you want to do is surround your lines with HTML font tags based on the value of the status column, this awk code should do the trick:
{
if ( /On_Time/ ) print "<font color=\"#00FF00\">", $0, "</font>"
if ( /Delayed/ ) print "<font color=\"#FF0000\">", $0, "</font>"
if ( /No_Files/ ) print "<font color=\"#FFFF00\">", $0, "</font>"
}

How to read a file containing numbers in Octave using textscan

I am trying to import data from text file named xMat.txt which has the data in the following format.
200 space separated elements in one line and some 767 lines.
This is how xMat.txt looks.
386.0 386.0 388.0 394.0 402.0 413.0 ... .0 800.0 799.0 796
801.0 799.0 799.0 802.0 802.0 80 ... 399.0 397.0 394.0 391
.
.
.
This is my file - for reference.
When I try to read the file using
file = fopen('xMat.txt','r')
c = textscan(file,'%f');
I get the output as:
> c = { [1,1] =
> 386
> 386
> 388
> 394
> 402
> 413
> 427
> 442
> 458
> 473
> 487
> 499
> 509
> 517
> 524 ... in column format
What I need is a matrix of size (767X200). How can I do this?
I wouldn't use textscan in this case because your text file is purely numeric. Your text file contains 767 rows of 200 numbers per row where each number is delimited by a space. You couldn't get it to be any better suited for use with dlmread (MATLAB doc, Octave doc). dlmread can do this for you in one go:
c = dlmread('xMat.txt');
c will contain a 767 x 200 array for you that contains the data stored in the text file xMat.txt. Hopefully you can dump textscan in this case because what you're really after is trying to read your data into Octave... and dlmread does the job for you quite nicely.

Xtext 2.8+ formatter, formatting HiddenRegion with comment

I am using Xtext 2.9 formatter and I am trying to format hiddenRegion which contains comment. Here is part of my document region i am trying to format:
Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement
Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion
35 0 H
35 15 S ""xxx::a::b"" Refblock:namespace=Namespace
50 0 H
50 1 S "}" Refblock:RCBRACKET
E Refblock PackageHead:Block=Refblock path:PackageHead/Block=Package'xxx_constants'/head=Model/packages[0]
51 0 H
51 1 S ":" PackageHead:COLON
E PackageHead Package:head=PackageHead path:Package'xxx_constants'/head=Model/packages[0]
52 >>>H "\n " Whitespace:TerminalRule'WS'
"# asd" Comment:TerminalRule'SL_COMMENT'
15 "\n " Whitespace:TerminalRule'WS'<<<
B Error'ASSD' Package:expressions+=Expression path:Package'xxx_constants'/expressions[0]=Model/packages[0]
67 5 S "error" Error:'error'
72 1 H " " Whitespace:TerminalRule'WS'
and corresponding part of the grammar
Model:
{Model}
(packages+=Package)*;
Expression:
Error | Warning | Enum | Text;
Package:
{Package}
'package' name=Name head=PackageHead
(BEGIN
(imports+=Import)*
(expressions+=Expression)*
END)?;
Error:
{Error}
('error') name=ENAME parameter=Parameter COLON
(BEGIN
(expressions+=Estatement)+
END)?;
PackageHead:
Block=Refblock COLON;
Problem is that when i try prepend some characters before error keyword
for example
error.regionFor.keyword('error').prepend[setSpace("\n ")]
This indentation is prepended before the comment and not behind it. This results into improper formatting in case of single line comment before the 'error' keyword.
To provide more clarity, here is example code from my grammar and description of desired behavior:
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
This is expected result: (one space to the left)
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
and this is the actual result with prepend method
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
As the document structure says, the HiddenRegion is in this case is the statement:
# asd
error
How can i prepend my characters directly before the keyword 'error' and not before the comment? Thanks.
I assume you're creating an indentation-sensitive language, because you're explicitly calling BEGIN and END.
For indentation-sensitive language my answer is: You'll want to overwrite
org.eclipse.xtext.formatting2.internal.HiddenRegionReplacer.applyHiddenRegionFormatting(List<ITextReplacer>)
The methods append[] and prepend[] you're using are agnostic to comments and at a later time applyHiddenRegionFormatting() is called to decide how that formatting is weaved between comments.
To make Xtext use your own subclass of HiddenRegionReplacer, overwrite
org.eclipse.xtext.formatting2.AbstractFormatter2.createHiddenRegionReplacer(IHiddenRegion, IHiddenRegionFormatting)
For languages that do not do whitespace-sensitive lexing/parsing (that's the default) the answer is to not call setSpace() to create indentation or line-wraps.
Instead, do
pkg.interior[indent]
pkg.regionFor.keyword(":").append[newLine]
pkg.append[newLine]

Get email body by python 3.4

I want get email body. My email is html and save in part. Use this code:
print('charset =', part.get_content_charset())
html = part.get_payload(decode=True)
print ('type =', type(html))
print('text =', html)
result is:
charset = utf-8
type = <class 'bytes'>
text = b'...<font face="DejaVu Sans Mono">\\u044d\\u0442\\u043e html<br>\n...
I want have normal text, but no \u044d\u0442\u043e.
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Your data is a byte array. You have to decode the bytes to a string:
text.decode('utf-8')