Mixing razor code with HTML - html

Hi my mark up has snippets like below
<thead>
<tr class="">
<th data-field="firstname">First Name</th>
#{
foreach (MapDetail geMapDetailHead in Model.mapDetails)
{
string firstText, secText, thirdText;
if (geMapDetailHead.ResultTypeIDs.Equals("-9999"))
{
foreach (string rt in geMapDetailHead.ResultTypeIDs.Split(','))
{
firstText = #geMapDetailHead.Name;
string tab = geMapDetailHead.year;
int? month = geMapDetailHead.Month != 0 ? geMapDetailHead.Month : (geMapDetailHead.mapheader.Month != 0 ? geMapDetailHead.mapheader.Month : 0);
//switch (month.GetValueOrDefault())
//{
// default:
// tab += "";
// break;
// case 1:
// tab += " Jan";
// break;
// case 2:
// tab += " Feb";
// break;
// case 3:
// tab += " Mar";
// break;
// case 4:
// tab += " Apr";
// break;
// case 5:
// tab += " May";
// break;
// case 6:
// tab += " Jun";
// break;
// case 7:
// tab += " Jul";
// break;
// case 8:
// tab += " Aug";
// break;
// case 9:
// tab += " Sep";
// break;
// case 10:
// tab += " Oct";
// break;
// case 11:
// tab += " Nov";
// break;
// case 12:
// tab += " Dec";
// break;
//}
//secText = tab;
<th id=#geMapDetailHead.MapDetailID>#firstText #secText</th>
} #*end for loop*#
}
} #*end for loop*#
}
</tr>
</thead>
As soon as i un comment the switch statement it stops recognizing tag as markup. i have also tried putting
#:<th id=#geMapDetailHead.MapDetailID>#firstText #secText</th>
but did not work. How can i mix both the code and markup?

Well turned out that i had applied 1 extra # in the following line
firstText = #geMapDetailHead.Name;
I changed it to
firstText = geMapDetailHead.Name;
and BINGO!!
Cheers

Related

html to plaintext with NodeJS on server side

on the server-side, using Nodejs. I receive a text message containing HTML. I want a function that converts the html to plain text. And please don't tell me to add the tag <plaintext> or <pre>. (convert_to_html function doesn't exist in nodejs)
socket.on('echo', (text) => {
plaintext = convert_to_html(text);
socket.emit('echo', {
message: plaintext
});
});
ideal results:
input: <h1>haha i am big</h1>
plaintext(what i want plaintext to be): <h1 &60;haha i am big </h1 &60;
output: <h1>haha i am big</h1>
current result:
input: <h1>haha i am big</h1>
plaintext: <h1>haha i am big</h1>
output: haha i am big
You can use the insertAdjacementHTML method on the browser side, here you go an example
socket.on("response", function (msg) {
const messages = document.getElementById("messages");
messages.insertAdjacentHTML("beforebegin", msg);
window.scrollTo(0, document.body.scrollHeight);
});
still don't have a proper solution. while i wait for one, i will use reserved characters as a temporary solution.
https://devpractical.com/display-html-tags-as-plain-text/#:~:text=You%20can%20show%20HTML%20tags,the%20reader%20on%20the%20browser.
function parse_to_plain_text(html){
var result = "";
for (var i = 0; i < html.length; i++) {
var current_char = html[i];
if (current_char == ' '){
result += " "
}
else if (current_char == '<'){
result += "<"
}
else if (current_char == '>'){
result += ">"
}
else if (current_char == '&'){
result += "&"
}
else if (current_char == '"'){
result += """
}
else if (current_char == "'"){
result += "&apos;"
}
else{
result += current_char;
}
}
return result;
}

retrieving EntryID for Checkbox item in Google Sheets Form not working

I used the code from #contributorpw on this post get Entry ID which is used to pre-populate fields (Items) in a Google Form URL and added the extended list of form types from #SourceFli (in same post).
I get the error message: "Exception: The parameters (String) don't match the method signature for FormApp.CheckboxItem.createResponse". That checkbox has only 1 option: "yes".
The rest of all my form items are only TEXT items and work fine.
function getPreFillEntriesMap(){
var ssOrder = SpreadsheetApp.openById(ORDER_SPREADSHEET_ID);
var orderFormUrl = ssOrder.getFormUrl();
var orderForm = FormApp.openByUrl(orderFormUrl);
var form = orderForm;
// var form = FormApp.openById(id);
var items = form.getItems();
var newFormResponse = form.createResponse();
var itms = [];
for(var i = 0; i < items.length; i++){
var response = getDefaultItemResponse_(items[i]);
if(response){
newFormResponse.withItemResponse(response);
itms.push({
id: items[i].getId(),
entry: null,
title: items[i].getTitle(),
type: "" + items[i].getType()
});
}
}
var ens = newFormResponse.toPrefilledUrl().split("&entry.").map(function(s){
return s.split("=")[0];
});
ens.shift();
return Logger.log(itms.map(function(r, i){
r.entry = this[i];
return r;
}, ens));
}
function getDefaultItemResponse_(item){
switch(item.getType()){
case FormApp.ItemType.TEXT:
return item.asTextItem().createResponse("1");
break;
case FormApp.ItemType.MULTIPLE_CHOICE:
return item.asMultipleChoiceItem()
.createResponse(item.asMultipleChoiceItem().getChoices()[0].getValue());
break;
case FormApp.ItemType.CHECKBOX:
return item.asCheckboxItem()
.createResponse(item.asCheckboxItem().getChoices()[0].getValue());
break;
case FormApp.ItemType.DATETIME:
return item.asDateTimeItem()
.createResponse(new Date());
break;
case FormApp.ItemType.DATE:
return item.asDateItem()
.createResponse(new Date());
break;
case FormApp.ItemType.LIST:
return item.asListItem()
.createResponse(item.asListItem().getChoices()[0].getValue());
break;
case FormApp.ItemType.PARAGRAPH_TEXT:
return item.asParagraphTextItem()
.createResponse(item.asParagraphTextItem().createResponse("some paragraph"));
break;
case FormApp.ItemType.CHECKBOX_GRID:
return item.asCheckboxGridItem()
.createResponse(item.asCheckboxGridItem().createResponse([item.asGridItem().getColumns[0], item.asGridItem().getRows[0]]));
break;
case FormApp.ItemType.DURATION:
return item.asDurationItem()
.createResponse(item.asDurationItem().createResponse(2, 20, 20));
break;
case FormApp.ItemType.GRID:
return item.asGridItem()
.createResponse(item.asGridItem().createResponse([item.asGridItem().getColumns[0], item.asGridItem().getRows[0]]));
break;
case FormApp.ItemType.SCALE:
return item.asScaleItem()
.createResponse(item.asScaleItem().createResponse(1));
break;
case FormApp.ItemType.TIME:
return item.asTimeItem()
.createResponse(item.asTimeItem().createResponse(1, 1));
break;
default:
return undefined;
}
}
response of createResponse(responses) of Class CheckboxItem is String[]. In your script, the string is used. I thought that this might be the reason of your issue. So how about the following modification?
From:
return item.asCheckboxItem()
.createResponse(item.asCheckboxItem().getChoices()[0].getValue());
To:
return item.asCheckboxItem()
.createResponse([item.asCheckboxItem().getChoices()[0].getValue()]);
Reference:
createResponse(responses)

How can I properly write the following if statement with getLabel()

I'm getting the following error and would like to know how to rewrite this code properly.
ReferenceError: Function function getLabel() {/* */} can not be used as the left-hand side of assignment or as an operand of ++ or -- operator. (line 61, file "DLContactsToSheet")
var Phones = "";
for ( var g=0;g<contacts[i].getPhones().length;g++)
{
if (contacts[i].getPhones()[g].getLabel() = "MOBILE_PHONE") {
Phones += "C: "
} else if (contacts[i].getPhones()[g].getLabel() = "WORK_PHONE") {
Phones += "W: "
} else if (contacts[i].getPhones()[g].getLabel() = "HOME_PHONE") {
Phones += "H: "
} else {
Phones += "O: "
}
Phones += contacts[i].getPhones()[g].getPhoneNumber();
Phones += "\n";
}
try{ContactArray.push(Phones);}
catch(e){ContactArray.push("N/A")}
It would appear that the reference error is caused by an '=' rather than an '==' in your conditions.
Rewriting the conditions as if (phone.getLabel() == 'MOBILE_PHONE') { /* ... */ } etc should do the trick.
You need to hard code them, in order to fetch them.
Code
function fieldType() {
var contacts = ContactsApp.getContacts(), phones = [];
for(var i = 0, iLen = contacts.length; i < iLen; i++) {
var con = contacts[i], f = ContactsApp.Field;
var c = con.getPhones(f.MOBILE_PHONE), w = con.getPhones(f.HOME_PHONE), h = con.getPhones(f.WORK_PHONE);
phones = getNumber(phones, c, "C: ");
phones = getNumber(phones, w, "W: ");
phones = getNumber(phones, h, "H: ");
}
}
function getNumber(phones, type, prefix) {
var typeNumbers = [];
var pNumber = type.length > 0 ? type.map( function (d) { return prefix + d.getPhoneNumber() + "\n"; }) : null;
if(pNumber) {
typeNumbers.push(pNumber);
}
return phones.concat(typeNumbers);
}
Note
See method description for more info: getPhoneNumber()
You should probably store the value for each iteration in a variable before any conditional statements. A case-switch statement is probably also better suited for this.
for ( var g=0;g<contacts[i].getPhones().length;g++)
{
var phone_type = contacts[i].getPhones()[g].getLabel()
switch(phone_type) {
case "MOBILE_PHONE":
Phones += "C: "
break;
case "WORK_PHONE":
Phones += "W: "
break;
case "HOME_PHONE":
Phones += "H: "
break;
default:
Phones += "O: "
}
Phones += contacts[i].getPhones()[g].getPhoneNumber();
Phones += "\n";
}

Adobe AIR 3.2 Glitch

I just finished a successful build of my program last night. Then, I get up this morning, and after an update fro Adobe AIR 3.1 to AIR 3.2, I find THIS bug!
The same build under 3.1 works perfectly. However, as soon as 3.2 is installed, the following code after stopDrag fails silently. Mind you, it only fails in the packed and installed AIR application. It works perfectly when I test it inside of Adobe Flash Professional CS5.5
WHAT is going on? Here's the code I'm dealing with. Again, this works without error for Adobe AIR 3.1, but fails for 3.2. I cannot get to any other MouseEvent.MOUSE_UP events in my program at this point, due to my structure.
I omitted the irrelevant parts of the code. All the same, there is a lot, due to the fact that I don't know where the error occurs exactly. Instead of everything that is supposed to happen happening, stopDrag is the last line of code that fires in this block.
tile5.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler5);
function mouseUpHandler5(evt:MouseEvent):void
{
Mouse.cursor = "paw";
var obj = evt.target;
var target = obj.dropTarget;
obj.stopDrag();
if (target != null && target.parent == hsSlot1)
{
brdgcheck(5, 1);
}
}
function brdgcheck(tile:int, slot:int)
{
var ck_brdg_l:String = "osr.Langue.brdg_l" + String(slot);
var ck_brdg_t:String = "osr.Langue.brdg_t" + String(tile);
var ck_slotfilled:String = "Slot" + String(slot) + "Filled";
var ck_tile:String = "tile" + String(tile);
var ck_slot:String = "hsSlot" + String(slot);
var ck_txtTile:String;
switch(tile)
{
case 1:
ck_brdg_t = osr.Langue.brdg_t1;
ck_txtTile = tile1.txtTile1.text;
break;
case 2:
ck_brdg_t = osr.Langue.brdg_t2;
ck_txtTile = tile2.txtTile2.text;
break;
case 3:
ck_brdg_t = osr.Langue.brdg_t3;
ck_txtTile = tile3.txtTile3.text;
break;
case 4:
ck_brdg_t = osr.Langue.brdg_t4;
ck_txtTile = tile4.txtTile4.text;
break;
case 5:
ck_brdg_t = osr.Langue.brdg_t5;
ck_txtTile = tile5.txtTile5.text;
break;
}
switch(slot)
{
case 1:
ck_brdg_l = osr.Langue.brdg_l1;
break;
case 2:
ck_brdg_l = osr.Langue.brdg_l2;
break;
case 3:
ck_brdg_l = osr.Langue.brdg_l3;
break;
case 4:
ck_brdg_l = osr.Langue.brdg_l4;
break;
case 5:
ck_brdg_l = osr.Langue.brdg_l5;
break;
}
if (ck_brdg_l == ck_brdg_t)
{
osr.Sonus.PlaySound("concretehit");
this[ck_slotfilled].visible = true;
switch(slot)
{
case 1:
Slot1Filled.txtSlot1.text = ck_txtTile;
break;
case 2:
Slot2Filled.txtSlot2.text = ck_txtTile;
break;
case 3:
Slot3Filled.txtSlot3.text = ck_txtTile;
break;
case 4:
Slot4Filled.txtSlot4.text = ck_txtTile;
break;
case 5:
Slot5Filled.txtSlot5.text = ck_txtTile;
break;
}
this[ck_tile].visible = false;
this[ck_slot].visible = false;
if (hsSlot1.visible == false && hsSlot2.visible == false && hsSlot3.visible == false && hsSlot4.visible == false && hsSlot5.visible == false)
{
osr.Gradua.Score(true);
osr.Gradua.Evaluate("brdg");
btnReset.visible = false;
hsChar.visible = false;
if (osr.Gradua.Fetch("brdg", "arr_act_stcnt") < 4)
{
bga.gotoAndPlay("FINKEY");
win_key();
}
else
{
bga.gotoAndPlay("FINNON");
}
}
else
{
osr.Gradua.Score(true);
}
}
else
{
osr.Gradua.Score(false);
osr.Sonus.PlaySound("glassbreak");
switch(tile)
{
case 1:
tile1.x = 92.85;
tile1.y = 65.85;
break;
case 2:
tile2.x = 208.80;
tile2.y = 162.85;
break;
case 3:
tile3.x = 324.80;
tile3.y = 65.85;
break;
case 4:
tile4.x = 437.80;
tile4.y = 162.85;
break;
case 5:
tile5.x = 549.80;
tile5.y = 65.85;
break;
}
}
}
EDIT: I found a good workaround, to use "if (hsSlot1.hitTestPoint(mouseX,mouseY) && hsSlot1.visible == true)"
However, a solution to this problem would still be appreciated!

How to format content in html textarea as xml on the fly

I have a page that users are able to add xml markup into a text area input. I'd like after they enter it that it be color-coded and formatted as xml would look in an IDE such as Visual Studio. Anybody know of a script or tool that would allow for this within a client-side browser?
Take a look at CodeMirror, a syntax-highlighting editor in Javascript for browsers. This is an example for XML editing.
Short answer: you can't.
Not in an TEXTAREA, as the one here in SO.
The example in SO is very good, as it has a TEXTAREA where we type the text, and a DIV box below where you can see what you type formatted.
You could also go through the contentEditable = "true", but it's a real pain to do it properly...
A nice option would be this: vkBeautify
Here is an example:
(function() {
function createShiftArr(step) {
var space = ' ';
if ( isNaN(parseInt(step)) ) { // argument is string
space = step;
} else { // argument is integer
switch(step) {
case 1: space = ' '; break;
case 2: space = ' '; break;
case 3: space = ' '; break;
case 4: space = ' '; break;
case 5: space = ' '; break;
case 6: space = ' '; break;
case 7: space = ' '; break;
case 8: space = ' '; break;
case 9: space = ' '; break;
case 10: space = ' '; break;
case 11: space = ' '; break;
case 12: space = ' '; break;
}
}
var shift = ['\n']; // array of shifts
for(ix=0;ix<100;ix++){
shift.push(shift[ix]+space);
}
return shift;
}
function vkbeautify(){
this.step = ' '; // 4 spaces
this.shift = createShiftArr(this.step);
};
vkbeautify.prototype.xml = function(text,step) {
var ar = text.replace(/>\s{0,}</g,"><")
.replace(/</g,"~::~<")
.replace(/\s*xmlns\:/g,"~::~xmlns:")
.replace(/\s*xmlns\=/g,"~::~xmlns=")
.split('~::~'),
len = ar.length,
inComment = false,
deep = 0,
str = '',
ix = 0,
shift = step ? createShiftArr(step) : this.shift;
for(ix=0;ix<len;ix++) {
// start comment or <![CDATA[...]]> or <!DOCTYPE //
if(ar[ix].search(/<!/) > -1) {
str += shift[deep]+ar[ix];
inComment = true;
// end comment or <![CDATA[...]]> //
if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1 || ar[ix].search(/!DOCTYPE/) > -1 ) {
inComment = false;
}
} else
// end comment or <![CDATA[...]]> //
if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1) {
str += ar[ix];
inComment = false;
} else
// <elm></elm> //
if( /^<\w/.exec(ar[ix-1]) && /^<\/\w/.exec(ar[ix]) &&
/^<[\w:\-\.\,]+/.exec(ar[ix-1]) == /^<\/[\w:\-\.\,]+/.exec(ar[ix])[0].replace('/','')) {
str += ar[ix];
if(!inComment) deep--;
} else
// <elm> //
if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) == -1 && ar[ix].search(/\/>/) == -1 ) {
str = !inComment ? str += shift[deep++]+ar[ix] : str += ar[ix];
} else
// <elm>...</elm> //
if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) > -1) {
str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix];
} else
// </elm> //
if(ar[ix].search(/<\//) > -1) {
str = !inComment ? str += shift[--deep]+ar[ix] : str += ar[ix];
} else
// <elm/> //
if(ar[ix].search(/\/>/) > -1 ) {
str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix];
} else
// <? xml ... ?> //
if(ar[ix].search(/<\?/) > -1) {
str += shift[deep]+ar[ix];
} else
// xmlns //
if( ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) {
str += shift[deep]+ar[ix];
}
else {
str += ar[ix];
}
}
return (str[0] == '\n') ? str.slice(1) : str;
}
window.vkbeautify = new vkbeautify();
})();
var xmlData = '<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don\'t forget me this weekend!</body></note>';
xmlData = vkbeautify.xml(xmlData);
$('textarea').val(xmlData);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea cols="30" rows="10"></textarea>