I am seeing a code in my project as
${'myproj.label' #i18n, format=[sighltyObj.field1], context='text'}
Intention is pass a variable into i18n text + encode the texts safely. Is this right to use display context along with i18n translations? When I tested with a field1 = "Hello%20World", it is NOT encoding the texts rather rendering as is.
How can I encode html strings while passing the arguments as variables into i18n?
HTL will not decode the text returned by format. I think the confusion comes from the documentation which states for the display context text the following:
Use this for simple HTML content - Encodes all HTML
(Source: HTL Specification Section 1.2.1 Display Context)
But this does not mean that this context decodes anything, it encodes HTML tags.
So if sighltyObj.field1 is Hello%20World it will not be rendered as Hello World but as Hello%20World as you already noticed.
The display context text will encode all HTML tags in the given text so that you can't "smuggle" them into a text (see code injection).
So for example:
${'<p>This is my text</p>' # context='text'}
will create the following HTML
<p>This is my text</p>
Note how the p tags were encoded:
<p> became <p> and </p> became </p>.
The getter for field1 in your sighltyObj will have to do the decoding so that Hello%20World becomes Hello World. There is already a answer on Stackoverflow that shows you how to do this: https://stackoverflow.com/a/6138183/190823
String result = java.net.URLDecoder.decode(url, "UTF-8");
Using Aurelia, I want to fill an <div> with contents of viewmodel property (lets call it htmlText) which contains html text, and I was using
<div>
${htmlText}
</div>
However, this encodes html so, instead of i.e. having paragraph or link, all tags are escaped so html can be seen as source.
Is there out of the box binder to do this?
You can accomplish this using the innerhtml binding like so:
<div innerhtml.bind="htmlText"></div>
Below is the sample code
<p>
I want this Text
<sup> not this </sup>
.(Need this too).
<sup> and not this </sup>
</p>
Using Selenium RC, selenium.getText("//...") bring us the all the text including which are in < sup >.
Is there any way to get the text from <p> without <sup> tags ?
Please let me know. Thanks
Your only option is to get the text of the three elements and manipulate the parts you don't want away. That, or resort to using getEval() to run some JavaScript that get's the <P> element's innerHTML property, then remove the parts inside the <SUP> elements yourself.
I am creating a sample ASP.NET MVC 3 site using Razor as view engine. The razor syntax starts with # character e.g. #RenderBody(). If I write #test on my cshtml page it gives me parse error
CS0103: The name 'test' does not exist in the current context
How do I escape '#' character?
## should do it.
Razor # escape char to symbols...
<img src="..." alt="Find me on twitter as #("#username")" />
or
<img src="..." alt="Find me on twitter as #("#")username" />
#Html.Raw("#") seems to me to be even more reliable than ##, since not in all cases ## will escape.
Therefore:
<meta name="twitter:site" content="#twitterSite">
would be:
<meta name="twitter:site" content="#Html.Raw("#")twitterSite">
use <text></text> or the easier way #:
Instead of HTML entity I prefer the use of #Html.Raw("#").
## is the escape character for # in Razor views as stated above.
Razor does however try to work out when an '#' is just an '#' and where it marks C# (or VB.Net) code. One of the main uses for this is to identify email addresses within a Razor view - it should not be necessary to escape the # character in an email address.
For the question about #RazorCodePart1 ## #RazorCodePart2, you need to the sequence:
#RazorCodePart1 #:## #RazorCodePart2
I know, it looks a bit odd, but it works and will get you the literal character '#' between the code blocks.
I just had the same problem. I declared a variable putting my text with the #.
#{
var twitterSite = "#MyTwitterSite";
}
...
<meta name="twitter:site" content="#twitterSite">
I know this question is old, but I tried all of the above and it didn't help me escape the character "#" in ASP.NET framework (MVC 5) inside a URL. Based on Terje Solem's answer though, the UTF-8 code %40 worked for me. this is the original URL I was trying to reach:
https://unpkg.com/#google/markerclustererplus#4.0.1/dist/markerclustererplus.min.js
this is what worked for me in my code:
https://unpkg.com/%40google/markerclustererplus#4.0.1/dist/markerclustererplus.min.js
this work for me
<meta name="author" content="Alan van Buuren #("#Alan_van_Buuren")">
Or yoy can use:
##Alan_van_Buuren
:D
You can use ## for this purpose.
Like var email = firstName + '\##' + domain;
I tried all the options above and none worked. This is what I did that worked :
#{
string str = #"[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,3}$";
}
<td>Email</td>
<td>
<input type="text" id="txtEmail" required name="email" pattern=#str />
</td>
I created a string varible and passed all the RegEx pattern code into it, then used the variable in the html, and Razor was cool with it.
just add a variable in CSHTML file
var myVariable = #"#";
and add it to your layout
<span class="my-class"><a href="#myVariale" target="_blank" >link text</a></span>
I couldn't get any of these to work inside my placeholder attribute, so I used xml special character.
<input type="text" placeholder="fex: firstname#lastname.com"/>
See more examples here.
https://www.dvteclipse.com/documentation/svlinter/How_to_use_special_characters_in_XML.3F.html
Actually # should be used with the Razor syntax Keywords or to the variable/model to bind a Value.
For Eg:
if test is assigned with value
i.e # { var test = "ABC" }
then you can get the value by settings as #test anywhere is cshtml page in html part.
otherwise, simple use as #Html.DisplayName("test")
I think in Razor view #Html.Raw() is the best solution for all version and always works for me. I have added an working example cdn URL to provide clear idea.
#Html.Raw("<script src=\"https://cdn.jsdelivr.net/npm/#popperjs/core#2.11.6/dist/umd/popper.min.js\"></script>")
Is it possible to make a Telerik RadEditor single-line entry only?
For example, in an ASP TextBox there is the Multiline attribute
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" />
Ah, just figured it out...
It's a bit weird, but there is an attribute for NewLineBr in the RadEditor.
<telerik:RadEditor NewLineBr="false">
Single line editing not possible with the RadEditor. It always uses an iframe element for the content area where the asp:textbox uses a textarea/input. Even if you make the height of the iframe be a single line, when the user presses Enter, they will get a new line. If you need a single line input from Telerik, then you can try using the RadInput control.