what is the purpose of angle bracket percent in html - html

I just wanted to know what <% these exactly do? %> I've used these for exporting some html tables and data to excel, but i don't really know what it's function is.
any answers are appreciated.
so like when i use these in below coding, am i actually using asp?
<body>
<%
String exportToExcel = request.getParameter("exportToExcel");
if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) { //application/vnd.ms-excel
response.setContentType("application/vnd.ms-excel"); //application/vnd.opentextformatsofficedocument.spreadsheetml.sheet
response.setHeader("Content-Disposition", "inline; filename=" + "whatever.xls");
}
%>
i got it from http://www.quicklyjava.com/export-web-page-to-word

Answered over here: Name for Angle Bracket Percent Sign. Which then links to another answer.
In short, they are code render blocks which execute when the page is rendered. They are expressions as a part of the ASP.net framework, from what I can gather.
More information: here
EDIT: As others have commented, I found all this from a quick search.

Related

Razor, StringBuilder, HTML line break?

I have a problem that is just making me feel silly.... Given the following code in Razor:
#{
...
if (purchasedEvent.Address != null && purchasedEvent.Address != String.Empty){
addressBlock.AppendFormat("{0}<br />", purchasedEvent.Address);
}
...
}
#addressBlock.ToString()
The <br /> gets treated as literal text (that is to say I end up seeing something like 123 Cool Street<br />Anytown... rendered on the page. Changing the code (back) to addressBlock.AppendLine(purchasedEvent.Address) doesn't do any good either (renders 127 Cool Street Anytown.... What do I need to do to make the Razor engine respect that line break?
You need to use Html.Raw. To quote the docs: "Returns markup that is not HTML encoded."
So something like
#html.Raw(addressBlock.ToString())
The reason for it is that MVC is assuming that what you are giving it is the text as you want it to be seen and thus HTML encodes it. Raw allows you to tell it not to do that.

node.js: is there no way to put HTML into i18n-node JSON translation files?

The question says it all. If I put HTML directly into the (JSON-formatted) translation file, like this:
"test_html" : "click <a href='http://stackoverflow.com/'>here</a>",
I get this in my HTML:
click <a href='http://stackoverflow.com/'>here</a>
I also tried combining this in my translation file:
"test_html_placeholder" : "click %shere%s",
With this in my HTML:
<%= __('test_html_placeholder', '', '') %>
But got similar results.
The only thing I can get to work is this clumsiness:
"test_html_pre" : "click ",
"test_html_link" : "here",
"test_html_post" : ".",
with this:
<%= __('test_html_pre') %><%= __('test_html_link') %><%= __('test_html_post') %>
But it's so cumbersome as to be almost not worth doing, and moreover the word order in some languages would force me to put some empty strings in my translation files, which i18n-node doesn't seem to like as it spits out the key (attribute) name when it
encounters an empty string.
I also tried using "\" as an escape character in front of the symbols, but I got an invalid JSON error when I lifted sails (restarted the server).
Any ideas, workarounds? I'm using sails.js, it wasn't my decision but I'm stuck with it and it comes with i18n-node. It's kind of late in the day on this project to consider using another library, but not completely out of the question.
beside of any upcoming discussion whether to include (html-)code in language files or not:
try to use
<%- __('click') %>
instead of
<%= __('click') %>
in ejs (the sails default template engine) a '<%=' will escape any html tags while '<%-' puts output as is without touching it. I am pretty sure you'll find unescaped html in your .json files. i18n doesn't do any transformation other than JSON.stringify() but almost all template engines do escape strings by default to prevent xssi.
For those using pug/jade, you can use
!{ __('key_for_your_text') }
Another option for pug is using
p!= __('key_for_your_text')

Rails + HTML code; awkward results = wrong approach?

I have a Portfolio model that contains a comments field of type text, whose values are a set of paragraphs delimited by some combo of cr and nl characters. The objective is to extract the paragraphs into an array, wrap them in <p> tags, and rejoin them for output to the browser; so the focus in the code below is lines 6-8.
The problem I'm having is that the < and > characters are getting rendered as HTML entities < and >.
I'm new to Ruby and Rails, so my guess is that the reason this isn't working as intended is because I'm probably taking an incorrect approach--and I'd like to know how an experienced Ruby coder would address this sort of situation. How do you insert HTML tags into content before you send it to a view? Or is that always a violation of the MVC model--in which case, what's a correct way to solve this sort of problem?
Here's the code:
1. module ApplicationHelper
2.
3. def portfolio_featured
4. #portfolios = Portfolio.all
5. #portfolios.each do |p|
6. paras = p.comments.split(/\r?\n\r?\n/)
7. paras.collect! { |p| "<p>" + p + "</p>" }
8. p.comments = paras.join
9. end
10. end
11.
12. end
take a look at simple_format TextHelper.
It is probably what you are looking for.
You can use TextHelper#simple_format or something fancy like Bluecloth (Markdown), but if you want to cook it yourself, that's what you can write (the key is using safe_join):
def portfolio_featured
safe_join(Portfolio.all.map do |portfolio|
portfolio.comments.lines.map { |line| content_tag(:p, line.chomp) }
end)
end

Error in Mako: "expected %>", escaping %

I'm currently writing Javascript in a mako file, and on one line, I have to check whether two strings are equal. The string I'm checking against has "<%text" within it, so I used to get an error saying there's no tag named text. I escaped that by adding a second % to get "<%%text". But now, I'm getting the following error.
SyntaxException: Expected: %> in file file.mako
What is the problem?
"<%" and "%>" are reserved symbols in Mako. If they appear in your template, Mako will assume that you mean to escape a python code block. Here is an example of what I mean:
"""
<%
some_var = 'foo'
other_var = '{0} bar'.format(some_var)
%>
"""
Take a look at http://docs.makotemplates.org/en/latest/syntax.html#python-blocks for more details
Excuse the quotes, "<%" and "%>" are also reserved symbols in the Stack Overflow WYSIWYG editor.
If the Javascript variables you are comparing contain reserved symbols, you will have to find another way of comparing them. Perhaps you could use the unicode entity for the percent sign:
For example:
if ('<%' == '<\u0025') {
alert('success!');
}
I just had a broken string variable which broke the logic, and fail on the un-related <% ... %>
Example:
<%
variable = 'this won't work'
# ^^^
%>

Ruby on Rails Helper Method - HTML is displayed as plain text

I have a helper method for my Rails app that returns a string with HTML code for a Google Groups subscription form. Unfortunately, it comes out on the page like plain text. How can I force it to render as HTML?
Thanks in advance.
The result of your helper needs to be marked as "html_safe" in Rails 3. Otherwise, the tags will be escaped.
def my_helper
data = "<p>Hello!</p>"
data.html_safe
end
I suppose it was a problem with Rails html sanitize.
from rails changelog
You no longer need to call h(string)
to escape HTML output, it is on by
default in all view templates. If you
want the unescaped string, call
raw(string).
try it
One thing to watch out for is when joining multiple strings like this
def custom_check_box(checked)
'<span class="my-custom-checkbox '+( checked ? 'checked' : '')+'"></span>'.html_safe
end
In this case, only the last part is marked as html safe. Make sure you get the whole thing.
def custom_check_box(checked)
('<span class="my-custom-checkbox '+( checked ? 'checked' : '')+'"></span>').html_safe
end