Server: Unix, Client: IE Edge
Part of my code:
%let P_debug_log = %str(<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>);
proc stream outfile=_webout quoting=both resetdelim='_do' ASIS;
BEGIN
%if "&_whattodo" ne "print" %then %do;
<script language='JavaScript' type='text/javascript'>
function subForm(f,v) {
if (v !== '') {
$('#'+ f).append('<INPUT TYPE="hidden" NAME="'+ v +'" VALUE="1">');
}
$('#'+f).submit();
}
$(document).ready(function() {
$('#footButtons').append($('.footButton')); /* move all elements with class=footButton to pageFooter */
$('#footMessage').append($('.footMsg'));
$('form.log').append("&P_debug_log.");
});
</script>
%end;
;;;;
Output:
The Problem is, that generated stream Output has linebreaks "somewhere" but not where expected (with Option ASIS it should be formatted like in my code).
This leads to unpredictable JavaScript Errors, e.g. when a linebreak is within a JavaScript string.
It seems as if there is an implicit LRECL 1024. This would be OK if linebreaks would be set as expected.
Any hints?
This is the originally formatted Output (Page Source):
<script language='JavaScript' type='text/javascript'> function subForm(f,v) { if (v !== '') { $('#'+ f).append('<INPUT TYPE="hidden" NAME="'+ v +'" VALUE="1">'); } $('#'+f).submit(); }
$(document).ready(function() { $('#footButtons').append($('.footButton')); $('#footMessage').append($('.footMsg')); $('form.log').append("
<INPUT TYPE=
'hidden
' NAME=
'_DEBUG
' VALUE=
'LOG
'
>"); }); </script>
Not sure if I have an answer, but it looks like the macro quoting is what is causing PROC STREAM to separate out the macro variable into multiple lines.
So if I run this simplified example:
%let P_debug_log = %str(<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>);
filename tst temp;
proc stream outfile=tst quoting=both resetdelim='_do' ASIS;
BEGIN
$('form.log').append("&P_debug_log.");
;;;;
Then it generates this file:
$('form.log').append("
<INPUT TYPE='hidden
' NAME='_DEBUG
' VALUE='LOG
'>");
If you remove the %STR() from around the value of the macro variable then it only inserts line breaks before and after the full macro variable reference and not also around the quotes in the macro variable.
$('form.log').append("
<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>
");
If you remove the quoting=both option then the line breaks will be outside the quotes, whether or not you use macro quoting.
$('form.log').append(
"<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>"
);
First of all, thank you all for your answers.
Robert Penridge was right.
Solution:
If you use PROC STREAM and want to include static code (as in my case: Javascript), then use &STREAMDELIM READFILE instead of %include.
Reason: if there are (valid!) inline comments "//" (comment until next linebreak,) in the included code, it will lead to unpredictable results....
thanks a lot,
dbdb
Simply remove the ASIS option you have added to proc stream.
I'm not sure if this is an undocumented feature but it doesn't appear in the documentation so I'm assuming so.
http://documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=n12zrkr08eiacmn17lcv4fmt79tb.htm&locale=en
Once you remove that the weird line breaks disappear.
Searching around, it appears the ASIS option is something to do with attempting to preserve column alignment.
Related
This is probably a simple question, but to which I havent found an answer yet.
How to escape the ' _ ' when creating an HtmlElement in razor?
To render a '-' in the final Html we put an ' _ ', but to render an '_' (underscore), How do we escape it? I tryed '#:', but it didn't work, and didn't find any other options...
Example:
#Html.CheckBox("Access_Groups", false, new
{
#class = "input-control checkbox",
#data_group = "I', looking for data-group",
#Description_pt = "<----- I'm looking for Description_pt"
})
#data_group will render as data-group as expected, but...
#Description_pt will render as Description-pt, and that is not what is expected (don't know how to escape the _ for this)
thank you
If you look at the signature of Html.Checkbox, we can see that it takes an object for the htmlAttributes. Further, looking at the syntax, its actually a key based collection of objects. A Dictionary<string,object> fits that bill and allows you to absolutely specify the name of the html attributes that you want to add (note each key is typed exactly how we want it to display).
#Html.CheckBox("Access_Groups", false, new Dictionary<string,object>
{{"class", "input-control checkbox"},
{"data-group", "I', looking for data-group"},
{"Description_pt", "SomeValue"}})
This renders the following HTML
<input Description_pt="SomeValue" class="input-control checkbox"
data-group="I', looking for data-group" id="Access_Groups"
name="Access_Groups" type="checkbox" value="true" />
Have you tried the HTML character code for underscore, i.e., _?
line breaks or pharagraph not working in textarea output? for example i am using enter for pharagraph in textarea but not working in output? How can i do that?
$("#submit-code").click(function() {
$("div.output").html($(".support-answer-textarea").val());
}).next().click(function () {
$(".support-answer-textarea").val($("div.output").html());
});
.support-answer-textarea{width:100%;min-height:300px;margin:0 0 50px 0;padding:20px 50px;border-top:1px solid #deddd9;border-bottom:1px solid #deddd9;border-left:none;border-right:none;box-sizing:border-box;letter-spacing:-1px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<textarea id="support-answer-textarea" class="support-answer-textarea" placeholder="Destek Konusunu Cevapla!"></textarea>
<button type="submit" id="submit-code" class="btn btn-success">Submit Your Code</button>
<div class="output"></div>
The best and easy way to fix line breaks on the output use these simple css:
.support-answer-textarea {
white-space: pre-wrap;
}
When you hit enter in a <textarea>, you're adding a new line character \n to the text which is considered a white space character in HTML. HTML generally converts the sequence of all white spaces to a single space. This means that if you enter a single or a dozen of whitespace characters (space, new line character or tab) in a row, the only effect in resulting HTML is just a single space.
Now the solution. You can substitute the new line character (\n) to <br> or <p> tag using replace() method.
$("#submit-code").click(function() {
$("div.output").html($(".support-answer-textarea").val().replace(/\n/g, "<br>"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<textarea id="support-answer-textarea" class="support-answer-textarea"></textarea>
<button type="submit" id="submit-code">Submit Your Code</button>
<div class="output"></div>
for me, I had a e.preventDefault() for only Enter keypress on a parent element, this prevents a new line from adding.
If you are capturing an input from a textarea, sending it via ajax (saving to database, e.g. mysql) and then want to display the result in a textarea (e.g. by echoing via php), use the following three steps in your JS:
#get value of textarea
var textarea_value = $('#id_of_your_textarea').val();
#replace line break with line break input
var textarea_with_break = textarea_value.replace(/(\r\n|\n|\r)/gm, '
');
#url encode the value so that you can send it via ajax
var textarea_encoded = encodeURIComponent(textarea_with_break);
#now send via ajax
You can also perform all of the above in one line. I did it in three with separate variables for easier readability.
Hope it helps.
Posting this here as it took me about an hour to figure this out, fumbling together the solutions from the answers below (see for more details):
The .val() of a textarea doesn't take new lines into account
New line in text area
URL Encode a string in jQuery for an AJAX request
Given that I have a string being displayed on the page in AngularDart.
... <strong>Notes: </strong> {{cmp.selectedStudent.notes}} ...
How can I make it display multi-line? In the string I have newline characters, I want them to be encoded as <br /> characters in the html output.
You can replace the '\n' in your string with <br/> and use something like the proposed my-bind-html directive shown in my answer here How to add a component programatically in Angular.Dart? (the code might be a bit outdated due to a lot of recent changes in Angular)
You could use ng-repeat and repeat over your notes lines but first you need to split them by '\n' so you get an array of lines.
List<String> _notesList = null;
List<String> get notesList {
if (_notesList==null) _notesList = notes.split("\n").toList(); return _notesList;
}
.
<span ng-repeat="note in cmp.selectedStudent.notesList">{{note}}<br /></span>
By default, angular doesn't interpret HTML balise to avoid some unpredictible behavior or others bad thing, but you can disable this verification with
ng-bind-html
link to the official doc : NgHtmlBind
So you can replace directly the '\n' character by the 'br' html node.
So you can do :
// ...
String getHtmlBrNote() {
return this.notes.replaceAll("\n", "<br />");
}
// ...
and after in angular
... <strong>Notes: </strong> <span ng-bind-html="cmp.selectedStudent.getHtmlBrNote()"></span> ...
And it will be ok
I am trying to do the following:
#foreach(var p in #Model.line_products){
<img class="small_img_#Model.line_products[i].short_name" src="/Content/images/#Model.line_products[i].image_name" />
}
Which isn't working, it renders the text just the way it is, not recognizing the '#'. I found this other post in Stackoverflow, which suggests adding parenthesis in the following way:
#foreach(var p in #Model.line_products){
<img class="small_img_(#Model.line_products[i].short_name)" src="/Content/images/#Model.line_products[i].image_name" />
}
Using this workaround, I get that my id is rendered as small_img_(MODEL ATTRIBUTE). Isn't there a workaround which doesn't require adding specific characters? (such as the parenthesis).
You have more errors than a simple undercore problem here. You cannot use #Model inside your if. You are already in a # block. Simply use #foreach(var p in Model.line_products).
Plus, the way you wrote the parenthesis, they will get rendered. What you want is
small_img_#(Model.line_products[i].short_name)
Put the parenthesis after the # instead of before:
class="small_img_#(Model.line_products[i].short_name)"
I sometimes put a couple of Guids in the id of an element and an underscore separator doesn't work.
There are two ways around this. First use the entity code _ instead and secondly just use a hyphen.
<input id="chk_#classLeader.ClassLeader_#ing.Ingredient.Guid" type="checkbox" class="chk_Done form-check">
<input id="chk-#classLeader.ClassLeader-#ing.Ingredient.Guid" type="checkbox" class="chk_Done form-check">
This is because I want to grab out the Guid's when the check box is clicked with some JQuery like this:
$(".chk_Done").click(function () {
var obj =[];
const itemId = ($(this).attr("id"));
const myArray = itemId.split("_");
var ClassLeaderGuid = myArray[1], IngredientGuid = myArray[2];
For example:
When typing παιχνιδια.com into Firefox, it is automatically converted to xn--kxadblxczv9d.com
Please suggest a tool for making such a conversion.
One of the easiest is this. Converts and checks for availability at the same time.
If you want to do it inside your browser, save the code in this answer as puny.js and the code below to puny.html, then load the file in your browser.
<html>
<title>Punyconverter</title>
<script type="text/javascript" src="puny.js"></script>
<style type="text/css">
input {width:300px;}
label {width:100px; display:inline-block;}
</style>
<script type="text/javascript">
onload = function( ) {
var ASCII = document.getElementById("ASCII");
var Unicode = document.getElementById("Unicode");
var Input = document.getElementById("Input");
Input.onkeyup=function(){
ASCII.value = punycode.ToASCII( this.value);
Unicode.value = punycode.ToUnicode( this.value);
}
};
</script>
</html>
<body>
<h1>Convert puny coded IDN</h1>
<div><label for="Input">Input</label><input id="Input" type="text"></div>
<div><label for="ASCII">ASCII</label><input id="ASCII" type="text" readonly="readonly"></div>
<div><label for="Unicode">Unicode</label><input id="Unicode" type="text" readonly="readonly"></div>
</body>
You can use any tool that supports "Libidn". A quick search showed SimpleDNS might be of help to you.
There are heaps of converters for IDN online, if that's enough for you, you can use one of them.
Internationalized domain name (i.e. domain names with non-ASCII characters) are encoded using the Punycode system.
You encode and decode IDNA with Python:
>>> print u'παιχνιδια'.encode('idna')
xn--mxaaitabzv9d
>>> print 'xn--mxaaitabzv9d'.decode('idna')
παιχνιδια
The standard modules in Perl also in Apache can do it with the URI module.
use URI;
#insert sitename in next:
$sitename = "..";
my $uri = URI->new( $sitename,'http');
if ($uri->scheme) { print $uri; }